shrub/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
2015-12-20 23:50:45 +03:00
|= a/marl ^- tape
2015-08-12 00:31:16 +03:00
?~ a ~
%- weld :_ $(a t.a)
2015-12-15 01:21:10 +03:00
?. ?=(_:/(**) i.a)
2015-08-12 00:31:16 +03:00
$(a c.i.a)
v.i.a.g.i.a
::
++ getall
2015-12-20 23:50:45 +03:00
|= tag/(list mane)
|= ele/manx ^- marl
?: (lien tag |=(a/mane =(a n.g.ele)))
2015-08-12 00:31:16 +03:00
~[ele]
(zing (turn c.ele ..$))
::
2015-12-20 23:50:45 +03:00
++ baff |*({a/(unit) b/(trap)} ?^(a a *b))
2015-08-04 02:49:34 +03:00
++ find-in-tree
2015-12-20 23:50:45 +03:00
|* {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)
2015-12-20 23:50:45 +03:00
|* {b/(list json) c/*} ^+ *fun
2015-08-05 00:45:29 +03:00
(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
2015-12-20 23:50:45 +03:00
|* {a/$+(* cord) b/$+(* json)}
|* c/(map) ^- json
2015-08-12 00:31:16 +03:00
~! c
2015-12-20 23:50:45 +03:00
(jobe (turn (~(tap by c)) |*({k/* v/*} [(a k) (b v)])))
2015-08-12 00:31:16 +03:00
::
2015-08-04 02:49:34 +03:00
++ json-front
2015-12-20 23:50:45 +03:00
|= a/json ^- json
2015-08-04 02:49:34 +03:00
=- (fall `(unit json)`- ~)
%. a
2015-12-21 00:16:39 +03:00
%+ find-in-tree (ot c+(ar some) gn+so ga+(om so) ~):jo
2015-12-20 23:50:45 +03:00
|= {nom/span atr/(map span cord)} ^- (unit json)
2015-08-04 02:49:34 +03:00
?. (~(has by atr) 'urb:front') ~
?> ?=($meta nom)
2015-08-04 02:49:34 +03:00
(biff (~(get by atr) %value) poja)
::
++ read-schem
=< (cook to-noun (cook to-tree apex))
|%
2015-12-14 10:58:14 +03:00
++ noun $@(term [noun noun]) :: shadow
2015-12-20 23:50:45 +03:00
++ 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-12-20 23:50:45 +03:00
++ to-noun |=(a/data ?@(a a [l.a $(a r.a)]))
2015-08-04 02:49:34 +03:00
++ to-tree
2015-12-20 23:50:45 +03:00
|= {acc/data a/(list {p/@u q/term})}
2015-08-04 02:49:34 +03:00
%+ roll a =< .(acc ^acc)
2015-12-20 23:50:45 +03:00
|= {{n/@u v/term} acc/data}
2015-08-04 02:49:34 +03:00
?@ 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))
--
--