urbit/lib/tree.hoon

66 lines
1.5 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
|%
2015-08-12 00:31:16 +03:00
++ extract
|= a=marl ^- tape
?~ a ~
%- weld :_ $(a t.a)
?. ?=(_:/(**) i.a)
$(a c.i.a)
v.i.a.g.i.a
::
++ getall
|= tag=(list mane)
|= ele=manx ^- marl
?: (lien tag |=(a=mane =(a n.g.ele)))
~[ele]
(zing (turn c.ele ..$))
2015-08-04 02:49:34 +03:00
++ baff |*([a=(unit) b=(trap)] ?^(a a *b))
++ find-in-tree
|* [paz=fist:jo fun=$+(* (unit))]
|= jon=json
=+ a=`(list json)`~[jon]
2015-08-05 00:45:29 +03:00
|^ (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
::
2015-08-12 00:31:16 +03:00
++ map-to-json
|* [a=$+(* cord) b=$+(* json)]
|* c=(map) ^- json
~! c
(jobe (turn (~(tap by c)) |*([k=* v=*] [(a k) (b v)])))
::
2015-08-04 02:49:34 +03:00
++ json-front
|= a=json ^- json
=- (fall `(unit json)`- ~)
%. 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))
--
--
2015-09-02 01:20:17 +03:00
=*(tree . .)