urbit/lib/tree.hoon

44 lines
1.1 KiB
Plaintext
Raw Normal View History

2015-08-04 02:49:34 +03:00
/- tree-include
2015-08-05 00:45:29 +03:00
!:
2015-08-04 02:49:34 +03:00
|%
++ baff |*([a=(unit) b=(trap)] ?^(a a *b))
++ find-in-tree
|* [paz=fist:jo fun=$+(* (unit))]
2015-08-05 00:45:29 +03:00
|= a=(list json)
|^ (try)
++ try
|. ^+ *fun
?~ a ~
%+ biff (paz i.a)
|* [b=(list json) c=*] ^+ *fun
(baff (baff (fun c) try(a b)) try(a t.a))
--
2015-08-04 02:49:34 +03:00
::
++ json-front
|= a=json ^- json
=- (fall `(unit json)`- ~)
2015-08-05 00:45:29 +03:00
%+ biff ((ar some):jo a)
2015-08-04 02:49:34 +03:00
%+ find-in-tree (ot c/(ar some) gn/so ga/(om so) ~):jo
|= [nom=span atr=(map span cord)] ^- (unit json)
?. (~(has by atr) 'urb:front') ~
?> ?=(%meta nom)
(biff (~(get by atr) %value) poja)
::
++ read-schem
=< (cook to-noun (cook to-tree apex))
|%
2015-08-05 00:45:29 +03:00
++ noun $|(term [noun noun]) :: shadow
++ data $|(term [n=@ l=noun r=data])
2015-08-04 02:49:34 +03:00
++ apex ;~(plug sym (star ;~(plug delim sym)))
++ delim ;~(pose (cold 0 dot) (cook lent (plus cab)))
2015-08-05 00:45:29 +03:00
++ to-noun |=(a=data ?@(a a [l.a $(a r.a)]))
2015-08-04 02:49:34 +03:00
++ to-tree
|= [acc=data a=(list ,[p=@u q=term])]
%+ roll a =< .(acc ^acc)
|= [[n=@u v=term] acc=data]
?@ acc [n acc v]
2015-08-05 00:45:29 +03:00
?: (gth n n.acc) [n (to-noun acc) v]
2015-08-04 02:49:34 +03:00
acc(r $(acc r.acc))
--
--