2title = "4f: Parsing (Rule-Builders)"
10ordered `++list` as atom of a `++base`.
31 =|({p/@ q/@} |.((add p (mul wuc q))))
39 > (scan "123" (bass 10 (star dit)))
41 > (scan "123" (bass 8 (star dit)))
43 > `@ub`(scan "123" (bass 8 (star dit)))
53Ordered `++list` as atom of a `++base`.
74 =|({p/@ q/@} |.((add p (mul wuc q))))
82 > (scan "123" (boss 10 (star dit)))
85 > `@t`(scan "bam" (boss 256 (star alp)))
88 > `@ux`(scan "bam" (boss 256 (star alp)))
98Parser modifier. Accepts a `++rule` `sef` and produces a parser that
99produces a constant `cus`, assuming `sef` is successful.
103`cus` is a constant noun.
114 ++ cold :: replace w+ constant
122 [p=p.vex q=[~ u=[p=cus q=q.u.q.vex]]]
128 > ((cold %foo (just 'a')) [[1 1] "abc"])
129 [p=[p=1 q=2] q=[~ u=[p=%foo q=[p=[p=1 q=2] q="bc"]]]]
131 > ((cold %foo (just 'a')) [[1 1] "bc"])
141Parser modifier. Produces a parser that takes a (successful) result of a
142`++rule` `sef` and slams it through `poq`.
157 ++ cook :: apply gate
159 |* {poq/gate sef/rule}
165 [p=p.vex q=[~ u=[p=(poq p.u.q.vex) q=q.u.q.vex]]]
172 > ((cook ,@ud (just 'a')) [[1 1] "abc"])
173 [p=[p=1 q=2] q=[~ u=[p=97 q=[p=[p=1 q=2] q="bc"]]]]
175 > ((cook ,@tas (just 'a')) [[1 1] "abc"])
176 [p=[p=1 q=2] q=[~ u=[p=%a q=[p=[p=1 q=2] q="bc"]]]]
178 > ((cook |=(a=@ +(a)) (just 'a')) [[1 1] "abc"])
179 [p=[p=1 q=2] q=[~ u=[p=98 q=[p=[p=1 q=2] q="bc"]]]]
181 > ((cook |=(a=@ `@t`+(a)) (just 'a')) [[1 1] "abc"])
182 [p=[p=1 q=2] q=[~ u=[p='b' q=[p=[p=1 q=2] q="bc"]]]]
191Parser generator. Produces a parser that succeeds with given noun `huf`
192without consuming any text.
205 ++ easy :: always parse
211 [p=p.tub q=[~ u=[p=huf q=tub]]]
218 > ((easy %foo) [[1 1] "abc"])
219 [p=[p=1 q=1] q=[~ [p=%foo q=[p=[p=1 q=1] q="abc"]]]]
221 > ((easy %foo) [[1 1] "bc"])
222 [p=[p=1 q=1] q=[~ [p=%foo q=[p=[p=1 q=1] q="bc"]]]]
224 > ((easy 'a') [[1 1] "bc"])
225 [p=[p=1 q=1] q=[~ [p='a' q=[p=[p=1 q=1] q="bc"]]]]
234Parser modifier. Accepts a `++rule` `sef`, and produces a parser that succeeds only
235when the of `tub` is fully consumed using `sef`.
248 ++ full :: parse to end
252 ?~(q.vex vex ?:(=(~ q.q.u.q.vex) vex [p=p.vex q=~]))
259 > ((full (just 'a')) [[1 1] "ab"])
262 > ((full (jest 'ab')) [[1 1] "ab"])
263 [p=[p=1 q=3] q=[~ u=[p='ab' q=[p=[p=1 q=3] q=""]]]]
265 > ((full ;~(plug (just 'a') (just 'b'))) [[1 1] "ab"])
266 [p=[p=1 q=3] q=[~ u=[p=[~~a ~~b] q=[p=[p=1 q=3] q=""]]]]
275Parser modifier: prepend text to `++tape` before applying parser.
290 ++ funk :: add to tape first
291 |* {pre/tape sef/rule}
293 (sef p.tub (weld pre q.tub))
299 > ((funk "abc prefix-" (jest 'abc')) [[1 1] "to be parsed"])
300 [p=[p=1 q=4] q=[~ [p='abc' q=[p=[p=1 q=4] q=" prefix-to be parsed"]]]]
302 > ((funk "parse" (just 'a')) [[1 4] " me"])
312Parser modifier. Similar to `++cook` in that it produces a parser that takes a
313(successful) result of `sef` and slams it through `hez`. `hez` accepts a
314`++pint` `a` and a noun `b`, which is what the parser parsed.
329 ++ here :: place-based apply
331 |* {hez/_|=({a/pint b/*} [a b]) sef/rule}
337 [p=p.vex q=[~ u=[p=(hez [p.tub p.q.u.q.vex] p.u.q.vex) q=q.u.q.vex]]]
344 > (scan "abc" (star alf))
347 > (scan "abc" (here |*(^ +<) (star alf)))
348 [[[p=1 q=1] p=1 q=4] "abc"]
350 > (scan "abc" (star (here |*(^ +<) alf)))
351 ~[[[[p=1 q=1] p=1 q=2] ~~a] [[[p=1 q=2] p=1 q=3] ~~b] [[[p=1 q=3] p=1 q=4] ~~c]]
360Parser modifier: surround with pair of `++rule`s, the output of which is
365`fel` is a pair of `++rule`s.
377 |* {fel/{rule rule} hof/rule}
381 ;~(pfix -.fel ;~(sfix hof +.fel))
388 > (scan "-40-" (ifix [hep hep] dem))
391 > (scan "4my4" (ifix [dit dit] (star alf)))
401Match and consume a cord.
414 ++ jest :: match a cord
420 [p=p.tub q=[~ u=[p=fad q=tub]]]
421 ?: |(?=($~ q.tub) !=((end 3 1 daf) i.q.tub))
423 $(p.tub (lust i.q.tub p.tub), q.tub t.q.tub, daf (rsh 3 1 daf))
430 > ((jest 'abc') [[1 1] "abc"])
431 [p=[p=1 q=4] q=[~ [p='abc' q=[p=[p=1 q=4] q=""]]]]
433 > (scan "abc" (jest 'abc'))
436 > (scan "abc" (jest 'acb'))
441 > ((jest 'john doe') [[1 1] "john smith"])
444 > ((jest 'john doe') [[1 1] "john doe"])
445 [p=[p=1 q=9] q=[~ [p='john doe' q=[p=[p=1 q=9] q=""]]]]
454Match and consume a single character.
467 ++ just :: XX redundant, jest
468 ~/ %just :: match a char
484 > ((just 'a') [[1 1] "abc"])
485 [p=[p=1 q=2] q=[~ [p=~~a q=[p=[p=1 q=2] q="bc"]]]]
487 > (scan "abc" (just 'a'))
492 > (scan "a" (just 'a'))
495 > (scan "%" (just '%'))
505Used for recursive parsers, which would otherwise be infinite when
512`sef` is a gate that accepts a `++rule`
522 |* {gar/* sef/_|.(*rule)}
532 > |-(;~(plug prn ;~(pose $ (easy ~))))
536 > |-(;~(plug prn ;~(pose (knee *tape |.(^$)) (easy ~))))
538 [ c=c=tub=[p=[p=@ud q=@ud] q=""]
541 [ c=tub=[p=[p=@ud q=@ud] q=""]
542 b=<1.tnv [tub=[p=[p=@ud q=@ud] q=""] <1.ktu [daf=@tD <414.fvk 101.jzo 1.ypj %164>]>]>
543 a=<1.fvg [tub=[p=[p=@ud q=@ud] q=""] <1.khu [[les=@ mos=@] <414.fvk 101.jzo 1.ypj %164>]>]>
544 v=<414.fvk 101.jzo 1.ypj %164>
548 ... 450 lines omitted ...
551 > (scan "abcd" |-(;~(plug prn ;~(pose (knee *tape |.(^$)) (easy ~)))))
561Parser generator. Matches the next character if it is in a list of
566`bud` is a list of `++char`
575 ++ mask :: match char in set
583 ?. (lien bud |=(a/char =(i.q.tub a)))
592 > (scan "a" (mask "cba"))
595 > ((mask "abc") [[1 1] "abc"])
596 [p=[p=1 q=2] q=[~ [p=~~a q=[p=[p=1 q=2] q="bc"]]]]
598 > ((mask "abc") [[1 1] "bbc"])
599 [p=[p=1 q=2] q=[~ [p=~~b q=[p=[p=1 q=2] q="bc"]]]]
601 > ((mask "abc") [[1 1] "dbc"])
609Parse list with delimiter
611Parser modifier: Parse a list of matches using a delimiter `++rule`.
627 |* {bus/rule fel/rule}
628 ;~(pose (most bus fel) (easy ~))
635 > (scan "" (more ace dem))
638 > (scan "40 20" (more ace dem))
641 > (scan "40 20 60 1 5" (more ace dem))
642 [q=40 ~[q=20 q=60 q=1 q=5]]
649Parse list of at least one match
651Parser modifier: parse a `++list` of at least one match using a delimiter `++rule`.
667 |* {bus/rule fel/rule}
668 ;~(plug fel (star ;~(pfix bus fel)))
675 > (scan "40 20" (most ace dem))
678 > (scan "40 20 60 1 5" (most ace dem))
679 [q=40 ~[q=20 q=60 q=1 q=5]]
681 > (scan "" (most ace dem))
692Consume any character, producing it as a result.
705 ++ next :: consume a char
710 =+ zac=(lust i.q.tub p.tub)
711 [zac [~ i.q.tub [zac t.q.tub]]]
718 > (next [[1 1] "ebc"])
719 [p=[p=1 q=2] q=[~ [p=~~e q=[p=[p=1 q=2] q="bc"]]]]
721 > (next [[1 1] "john jumps jones"])
722 [p=[p=1 q=2] q=[~ [p=~~j q=[p=[p=1 q=2] q="ohn jumps jones"]]]]
729List of at least one match.
731Parser modifier: parse `++list` of at least one match.
744 ++ plus |*(fel/rule ;~(plug fel (star fel)))
750 > (scan ">>>>" (cook lent (plus gar)))
753 > (scan "- - " (plus ;~(pose ace hep)))
756 > `tape`(scan "- - " (plus ;~(pose ace hep)))
759 > `(pole ,@t)`(scan "- - " (plus ;~(pose ace hep)))
760 ['-' [' ' [' ' ['-' [' ' ~]]]]]
769Conditional `++cook`. Slams the result through a gate that produces
770a unit; if that unit is empty, fail.
783 ++ sear :: conditional cook
784 |* {pyq/$-(* (unit)) sef/rule}
789 =+ gey=(pyq p.u.q.vex)
792 [p=p.vex q=[~ u=[p=u.gey q=q.u.q.vex]]]
799 > ((sear |=(a/* ?@(a (some a) ~)) (just `a`)) [[1 1] "abc"])
800 [p=[p=1 q=2] q=[~ u=[p=97 q=[p=[p=1 q=2] q="bc"]]]]
802 > ((sear |=(* ~) (just 'a')) [[1 1] "abc"])
812Match characters (`++char`) within a range.
827 ++ shim :: match char in range
835 ?. ?&((gte i.q.tub les) (lte i.q.tub mos))
844 > ((shim 'a' 'z') [[1 1] "abc"])
845 [p=[p=1 q=2] q=[~ [p=~~a q=[p=[p=1 q=2] q="bc"]]]]
847 > ((shim 'a' 'Z') [[1 1] "abc"])
850 > ((shim 'a' 'Z') [[1 1] "Abc"])
851 [p=[p=1 q=2] q=[~ [p=~~~41. q=[p=[p=1 q=2] q="bc"]]]]
858Use gate to parse delimited list
860Parser modifier: By composing with a gate, parse a delimited `++list` of
877 |* raq/_|*({a/* b/*} [a b])
878 |* {bus/rule fel/rule}
879 ;~((comp raq) fel (stir +<+.raq raq ;~(pfix bus fel)))
886 > (scan "20+5+110" ((slug add) lus dem))
889 > `@t`(scan "a b c" ((slug |=(a/[@ @t] (cat 3 a))) ace alp))
899Add a label to an edge parsed by a rule.
914 ++ stag :: add a label
922 [p=p.vex q=[~ u=[p=[gob p.u.q.vex] q=q.u.q.vex]]]
929 > ((stag %foo (just 'a')) [[1 1] "abc"])
930 [p=[p=1 q=2] q=[~ u=[p=[%foo ~~a] q=[p=[p=1 q=2] q="bc"]]]]
932 > ((stag "xyz" (jest 'abc')) [[1 1] "abc"])
933 [p=[p=1 q=4] q=[~ u=[p=["xyz" 'abc'] q=[p=[p=1 q=4] q=""]]]]
935 > ((stag 10.000 (shim 0 100)) [[1 1] "abc"])
936 [p=[p=1 q=2] q=[~ u=[p=[10.000 ~~a] q=[p=[p=1 q=2] q="bc"]]]]
945Parser modifier: parse `++list` of matches.
954 ++ star :: 0 or more times
956 (stir `(list _(wonk *fel))`~ |*({a/* b/*} [a b]) fel)
962 > (scan "aaaaa" (just 'a'))
967 > (scan "aaaaa" (star (just 'a')))
970 > (scan "abcdef" (star (just 'a')))
975 > (scan "abcabc" (star (jest 'abc')))
978 > (scan "john smith" (star (shim 0 200)))
988Add faces `[p q]` to range-parser pairs in a list.
992`leh` is a list of range-parsers.
1000 |* leh/(list {?(@ {@ @}) rule})
1004 [i=[p=-.i.leh q=+.i.leh] t=$(leh t.leh)]
1011 > (stet (limo [[5 (just 'a')] [1 (jest 'abc')] [[1 1] (shim 0 200)]
1012 [[1 10] (cold %foo (just 'a'))]~]))
1014 [p=5 q=<1.lrk [tub=[p=[p=@ud q=@ud] q=""] <1.nqy [daf=@tD <394.imz 97.kdz 1.xlc %164>]>]>]
1015 [p=1 q=<1.lrk [tub=[p=[p=@ud q=@ud] q=""] <1.nqy [daf=@tD <394.imz 97.kdz 1.xlc %164>]>]>]
1016 [p=[1 1] q=<1.lrk [tub=[p=[p=@ud q=@ud] q=""] <1.nqy [daf=@tD <394.imz 97.kdz 1.xlc %164>]>]>]
1017 [p=[1 10] q=<1.lrk [tub=[p=[p=@ud q=@ud] q=""] <1.nqy [daf=@tD <394.imz 97.kdz 1.xlc %164>]>]>]
1019 > [[[1 1] (just 'a')] [[2 1] (shim 0 200)] ~]
1020 [ [[1 1] <1.tnv [tub=[p=[p=@ud q=@ud] q=""] <1.ktu [daf=@tD <414.fvk 101.jzo 1.ypj %164>]>]>]
1021 [[2 1] <1.fvg [tub=[p=[p=@ud q=@ud] q=""] <1.khu [[les=@ mos=@] <414.fvk 101.jzo 1.ypj %164>]>]>]
1024 > (stet (limo [[[1 1] (just 'a')] [[2 1] (shim 0 200)] ~]))
1026 [p=[1 1] q=<1.lrk [tub=[p=[p=@ud q=@ud] q=""] <1.nqy [daf=@tD <394.imz 97.kdz 1.xlc %164>]>]>]
1027 [p=[2 1] q=<1.lrk [tub=[p=[p=@ud q=@ud] q=""] <1.nqy [daf=@tD <394.imz 97.kdz 1.xlc %164>]>]>]
1038 ++ stew :: switch by first char
1040 |* leh/(list {p/?(@ {@ @}) q/rule}) :: char+range keys
1041 =+ ^= wor :: range complete lth
1042 |= {ort/?(@ {@ @}) wan/?(@ {@ @})}
1044 ?@(wan (lth ort wan) (lth ort -.wan))
1045 ?@(wan (lth +.ort wan) (lth +.ort -.wan))
1046 =+ ^= hel :: build parser map
1047 =+ hel=`(tree _?>(?=(^ leh) i.leh))`~
1055 ?: (wor p.i.leh p.n.yal)
1058 ?: (vor p.n.yal p.n.nuc)
1060 [n.nuc l.nuc [n.yal r.nuc r.yal]]
1063 ?: (vor p.n.yal p.n.nuc)
1065 [n.nuc [n.yal l.yal l.nuc] r.nuc]
1075 ?&((gte i.q.tub -.p.n.hel) (lte i.q.tub +.p.n.hel))
1076 :: (q.n.hel [(lust i.q.tub p.tub) t.q.tub])
1078 ?: (wor i.q.tub p.n.hel)
1084Parser generator. From an associative `++list` of characters or character
1085ranges to `++rule`s, construct a `++map`, and parse `++tape`s only
1086with `++rules` associated with a range that the `++tape`'s first character falls in.
1094Parse with `++rule` as many times as possible, and fold over results with a
1101`raq` is a gate that takes two nouns and produces a cell.
1114 |* {rud/* raq/_=>(~ |*({a/* b/*} [a b])) fel/rule}
1121 =+ wag=$(tub q.u.q.vex)
1123 [(last p.vex p.wag) [~ (raq p.u.q.vex p.u.q.wag) q.u.q.wag]]
1129 > (scan "abc" (stir *@ add prn))
1142Parse bounded number of times.
1146`[les=@ mos=@]` is a cell of atoms indicating the bounds.
1157 ++ stun :: parse several times
1158 |* {lig/{@ @} fel/rule}
1160 ^- (like (list _(wonk (fel))))
1169 -.lig ?:(=(0 -.lig) 0 (dec -.lig))
1170 +.lig ?:(=(0 +.lig) 0 (dec +.lig))
1175 [p.wag [~ [p.u.q.vex p.u.q.wag] q.u.q.wag]]
1181 > ((stun [5 10] prn) [1 1] "aquickbrownfoxran")
1182 [p=[p=1 q=11] q=[~ [p="aquickbrow" q=[p=[p=1 q=11] q="nfoxran"]]]]
1184 > ((stun [5 10] prn) [1 1] "aquickbro")
1185 [p=[p=1 q=10] q=[~ [p="aquickbro" q=[p=[p=1 q=10] q=""]]]]
1187 > ((stun [5 10] prn) [1 1] "aqui")
keysesc to close
- j k
- move down, up
- enter
- open
- esc
- back, or up a level
- 1 2 3 4
- readme, files, commits, refs
- /
- filter
- y
- copy the clone command
- c
- compare the chosen commit with another (or shift-click both)
- ?
- show or hide this list