urbit/tree/json.hook
2015-08-05 16:48:34 -07:00

72 lines
1.7 KiB
Plaintext

::
:::: /hook/json/tree
::
/? 314
/+ tree
/= gas /$ fuel
/= dat /^ tree-include
/: /===/tree-gen /%
/tree-include/
::
/= kid /^ (map span tree-include)
/: /===/tree-gen /% 2 /_
/tree-include/
!:
::::
::
|%
++ schema (dict ,[term $|(mark schema)])
++ dict |*(a=_,* $&([a (dict a)] a))
++ query
$% [%kids p=(list query)]
[%name %t]
[%path %t]
[%snip %r]
[%head %r]
[%body %r]
[%meta %j]
==
++ to-queries
|= a=schema ^- (list query)
?@(-.a [(to-query a) ~] [(to-query -.a) $(a +.a)])
::
++ to-query
|= a=[term $|(mark schema)]
~| invalid-query/a
?+ -.a ;;(query a)
%kids [%kids (to-queries ?@(+.a !! +.a))]
==
++ from-type :: XX holding out for noun odors
|= a=$%([%t p=cord] [%r p=json] [%j p=json])
?- -.a
%t [%s p.a]
%r p.a
%j p.a
==
++ from-queries
|= [bem=beam quy=(list query)]
=< (jobe (turn quy .))
|= a=query
:- -.a
?- -.a
%name (from-type +.a ?^(s.bem i.s.bem q.bem))
%path (from-type +.a (crip (spud (flop s.bem))))
%head (from-type +.a head.dat)
%snip (from-type +.a snip.dat)
%meta (from-type +.a meta.dat)
%body (from-type +.a body.dat)
%kids ?< (~(has by (mo p.a)) %kids) :: XX recursion?
=< a/(turn (~(tap by kid)) .)
|= [dir=span dak=tree-include]
^^$(quy [name/%t p.a], s.bem [dir s.bem], dat dak, kid ~)
== :: XX array
--
!:
::::
::
^- json
=+ ^= schem
=+ seh=(fall (~(get by qix.gas) 'q') 'body.r')
~|(bad-noun/seh ;;(schema (rash seh read-schem)))
(from-queries bem.gas(s but.gas) (to-queries schem))