on bfaa358 help sign in
58 lines 1.7 kB history raw
1### `++stew`
3Switch by first
5 ++ stew :: switch by first char
6 ~/ %stew
7 |* leh/(list {p/?(@ {@ @}) q/rule}) :: char+range keys
8 =+ ^= wor :: range complete lth
9 |= {ort/?(@ {@ @}) wan/?(@ {@ @})}
10 ?@ ort
11 ?@(wan (lth ort wan) (lth ort -.wan))
12 ?@(wan (lth +.ort wan) (lth +.ort -.wan))
13 =+ ^= hel :: build parser map
14 =+ hel=`(tree _?>(?=(^ leh) i.leh))`~
15 |- ^+ hel
16 ?~ leh
17 ~
18 =+ yal=$(leh t.leh)
19 |- ^+ hel
20 ?~ yal
21 [i.leh ~ ~]
22 ?: (wor p.i.leh p.n.yal)
23 =+ nuc=$(yal l.yal)
24 ?> ?=(^ nuc)
25 ?: (vor p.n.yal p.n.nuc)
26 [n.yal nuc r.yal]
27 [n.nuc l.nuc [n.yal r.nuc r.yal]]
28 =+ nuc=$(yal r.yal)
29 ?> ?=(^ nuc)
30 ?: (vor p.n.yal p.n.nuc)
31 [n.yal l.yal nuc]
32 [n.nuc [n.yal l.yal l.nuc] r.nuc]
33 ~% %fun ..^$ ~
34 |= tub/nail
35 ?~ q.tub
36 (fail tub)
37 |-
38 ?~ hel
39 (fail tub)
40 ?: ?@ p.n.hel
41 =(p.n.hel i.q.tub)
42 ?&((gte i.q.tub -.p.n.hel) (lte i.q.tub +.p.n.hel))
43 :: (q.n.hel [(lust i.q.tub p.tub) t.q.tub])
44 (q.n.hel tub)
45 ?: (wor i.q.tub p.n.hel)
46 $(hel l.hel)
47 $(hel r.hel)
48 ::
52Parser generator. From an associative `++list` of characters or character
53ranges to `++rule`s, construct a `++map`, and parse `++tape`s only
54with `++rules` associated with a range that the `++tape`'s first character falls in.
58***