2title = "4f: Parsing (Rule-Builders)"
9ordered `++list` as atom of a `++base`.
30 =|({p/@ q/@} |.((add p (mul wuc q))))
38 > (scan "123" (bass 10 (star dit)))
40 > (scan "123" (bass 8 (star dit)))
42 > `@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)))
97Parser modifier. Accepts a `++rule` `sef` and produces a parser that
98produces a constant `cus`, assuming `sef` is successful.
102`cus` is a constant noun.
113 ++ cold :: replace w+ constant
121 [p=p.vex q=[~ u=[p=cus q=q.u.q.vex]]]
127 > ((cold %foo (just 'a')) [[1 1] "abc"])
128 [p=[p=1 q=2] q=[~ u=[p=%foo q=[p=[p=1 q=2] q="bc"]]]]
130 > ((cold %foo (just 'a')) [[1 1] "bc"])
140Parser modifier. Produces a parser that takes a (successful) result of a
141`++rule` `sef` and slams it through `poq`.
156 ++ cook :: apply gate
158 |* {poq/gate sef/rule}
164 [p=p.vex q=[~ u=[p=(poq p.u.q.vex) q=q.u.q.vex]]]
171 > ((cook ,@ud (just 'a')) [[1 1] "abc"])
172 [p=[p=1 q=2] q=[~ u=[p=97 q=[p=[p=1 q=2] q="bc"]]]]
174 > ((cook ,@tas (just 'a')) [[1 1] "abc"])
175 [p=[p=1 q=2] q=[~ u=[p=%a q=[p=[p=1 q=2] q="bc"]]]]
177 > ((cook |=(a=@ +(a)) (just 'a')) [[1 1] "abc"])
178 [p=[p=1 q=2] q=[~ u=[p=98 q=[p=[p=1 q=2] q="bc"]]]]
180 > ((cook |=(a=@ `@t`+(a)) (just 'a')) [[1 1] "abc"])
181 [p=[p=1 q=2] q=[~ u=[p='b' q=[p=[p=1 q=2] q="bc"]]]]
190Parser generator. Produces a parser that succeeds with given noun `huf`
191without consuming any text.
204 ++ easy :: always parse
210 [p=p.tub q=[~ u=[p=huf q=tub]]]
217 > ((easy %foo) [[1 1] "abc"])
218 [p=[p=1 q=1] q=[~ [p=%foo q=[p=[p=1 q=1] q="abc"]]]]
220 > ((easy %foo) [[1 1] "bc"])
221 [p=[p=1 q=1] q=[~ [p=%foo q=[p=[p=1 q=1] q="bc"]]]]
223 > ((easy 'a') [[1 1] "bc"])
224 [p=[p=1 q=1] q=[~ [p='a' q=[p=[p=1 q=1] q="bc"]]]]
233Parser modifier. Accepts a `++rule` `sef`, and produces a parser that succeeds only
234when the of `tub` is fully consumed using `sef`.
247 ++ full :: parse to end
251 ?~(q.vex vex ?:(=(~ q.q.u.q.vex) vex [p=p.vex q=~]))
258 > ((full (just 'a')) [[1 1] "ab"])
261 > ((full (jest 'ab')) [[1 1] "ab"])
262 [p=[p=1 q=3] q=[~ u=[p='ab' q=[p=[p=1 q=3] q=""]]]]
264 > ((full ;~(plug (just 'a') (just 'b'))) [[1 1] "ab"])
265 [p=[p=1 q=3] q=[~ u=[p=[~~a ~~b] q=[p=[p=1 q=3] q=""]]]]
274Parser modifier: prepend text to `++tape` before applying parser.
289 ++ funk :: add to tape first
290 |* {pre/tape sef/rule}
292 (sef p.tub (weld pre q.tub))
298 > ((funk "abc prefix-" (jest 'abc')) [[1 1] "to be parsed"])
299 [p=[p=1 q=4] q=[~ [p='abc' q=[p=[p=1 q=4] q=" prefix-to be parsed"]]]]
301 > ((funk "parse" (just 'a')) [[1 4] " me"])
311Parser modifier. Similar to `++cook` in that it produces a parser that takes a
312(successful) result of `sef` and slams it through `hez`. `hez` accepts a
313`++pint` `a` and a noun `b`, which is what the parser parsed.
328 ++ here :: place-based apply
330 |* {hez/_|=({a/pint b/*} [a b]) sef/rule}
336 [p=p.vex q=[~ u=[p=(hez [p.tub p.q.u.q.vex] p.u.q.vex) q=q.u.q.vex]]]
343 > (scan "abc" (star alf))
346 > (scan "abc" (here |*(^ +<) (star alf)))
347 [[[p=1 q=1] p=1 q=4] "abc"]
349 > (scan "abc" (star (here |*(^ +<) alf)))
350 ~[[[[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]]
359Parser modifier: surround with pair of `++rule`s, the output of which is
364`fel` is a pair of `++rule`s.
376 |* {fel/{rule rule} hof/rule}
380 ;~(pfix -.fel ;~(sfix hof +.fel))
387 > (scan "-40-" (ifix [hep hep] dem))
390 > (scan "4my4" (ifix [dit dit] (star alf)))
400Match and consume a cord.
413 ++ jest :: match a cord
419 [p=p.tub q=[~ u=[p=fad q=tub]]]
420 ?: |(?=($~ q.tub) !=((end 3 1 daf) i.q.tub))
422 $(p.tub (lust i.q.tub p.tub), q.tub t.q.tub, daf (rsh 3 1 daf))
429 > ((jest 'abc') [[1 1] "abc"])
430 [p=[p=1 q=4] q=[~ [p='abc' q=[p=[p=1 q=4] q=""]]]]
432 > (scan "abc" (jest 'abc'))
435 > (scan "abc" (jest 'acb'))
440 > ((jest 'john doe') [[1 1] "john smith"])
443 > ((jest 'john doe') [[1 1] "john doe"])
444 [p=[p=1 q=9] q=[~ [p='john doe' q=[p=[p=1 q=9] q=""]]]]
453Match and consume a single character.
466 ++ just :: XX redundant, jest
467 ~/ %just :: match a char
483 > ((just 'a') [[1 1] "abc"])
484 [p=[p=1 q=2] q=[~ [p=~~a q=[p=[p=1 q=2] q="bc"]]]]
486 > (scan "abc" (just 'a'))
491 > (scan "a" (just 'a'))
494 > (scan "%" (just '%'))
504Used for recursive parsers, which would otherwise be infinite when
511`sef` is a gate that accepts a `++rule`
521 |* {gar/* sef/_|.(*rule)}
531 > |-(;~(plug prn ;~(pose $ (easy ~))))
535 > |-(;~(plug prn ;~(pose (knee *tape |.(^$)) (easy ~))))
537 [ c=c=tub=[p=[p=@ud q=@ud] q=""]
540 [ c=tub=[p=[p=@ud q=@ud] q=""]
541 b=<1.tnv [tub=[p=[p=@ud q=@ud] q=""] <1.ktu [daf=@tD <414.fvk 101.jzo 1.ypj %164>]>]>
542 a=<1.fvg [tub=[p=[p=@ud q=@ud] q=""] <1.khu [[les=@ mos=@] <414.fvk 101.jzo 1.ypj %164>]>]>
543 v=<414.fvk 101.jzo 1.ypj %164>
547 ... 450 lines omitted ...
550 > (scan "abcd" |-(;~(plug prn ;~(pose (knee *tape |.(^$)) (easy ~)))))
560Parser generator. Matches the next character if it is in a list of
565`bud` is a list of `++char`
574 ++ mask :: match char in set
582 ?. (lien bud |=(a/char =(i.q.tub a)))
591 > (scan "a" (mask "cba"))
594 > ((mask "abc") [[1 1] "abc"])
595 [p=[p=1 q=2] q=[~ [p=~~a q=[p=[p=1 q=2] q="bc"]]]]
597 > ((mask "abc") [[1 1] "bbc"])
598 [p=[p=1 q=2] q=[~ [p=~~b q=[p=[p=1 q=2] q="bc"]]]]
600 > ((mask "abc") [[1 1] "dbc"])
607Parse list with delimiter
609Parser modifier: Parse a list of matches using a delimiter `++rule`.
625 |* {bus/rule fel/rule}
626 ;~(pose (most bus fel) (easy ~))
633 > (scan "" (more ace dem))
636 > (scan "40 20" (more ace dem))
639 > (scan "40 20 60 1 5" (more ace dem))
640 [q=40 ~[q=20 q=60 q=1 q=5]]
647Parse list of at least one match
649Parser modifier: parse a `++list` of at least one match using a delimiter `++rule`.
665 |* {bus/rule fel/rule}
666 ;~(plug fel (star ;~(pfix bus fel)))
673 > (scan "40 20" (most ace dem))
676 > (scan "40 20 60 1 5" (most ace dem))
677 [q=40 ~[q=20 q=60 q=1 q=5]]
679 > (scan "" (most ace dem))
690Consume any character, producing it as a result.
703 ++ next :: consume a char
708 =+ zac=(lust i.q.tub p.tub)
709 [zac [~ i.q.tub [zac t.q.tub]]]
716 > (next [[1 1] "ebc"])
717 [p=[p=1 q=2] q=[~ [p=~~e q=[p=[p=1 q=2] q="bc"]]]]
719 > (next [[1 1] "john jumps jones"])
720 [p=[p=1 q=2] q=[~ [p=~~j q=[p=[p=1 q=2] q="ohn jumps jones"]]]]
728List of at least one match.
730Parser modifier: parse `++list` of at least one match.
743 ++ plus |*(fel/rule ;~(plug fel (star fel)))
749 > (scan ">>>>" (cook lent (plus gar)))
752 > (scan "- - " (plus ;~(pose ace hep)))
755 > `tape`(scan "- - " (plus ;~(pose ace hep)))
758 > `(pole ,@t)`(scan "- - " (plus ;~(pose ace hep)))
759 ['-' [' ' [' ' ['-' [' ' ~]]]]]
768Conditional `++cook`. Slams the result through a gate that produces
769a unit; if that unit is empty, fail.
782 ++ sear :: conditional cook
783 |* {pyq/$-(* (unit)) sef/rule}
788 =+ gey=(pyq p.u.q.vex)
791 [p=p.vex q=[~ u=[p=u.gey q=q.u.q.vex]]]
798 > ((sear |=(a/* ?@(a (some a) ~)) (just `a`)) [[1 1] "abc"])
799 [p=[p=1 q=2] q=[~ u=[p=97 q=[p=[p=1 q=2] q="bc"]]]]
801 > ((sear |=(* ~) (just 'a')) [[1 1] "abc"])
811Match characters (`++char`) within a range.
826 ++ shim :: match char in range
834 ?. ?&((gte i.q.tub les) (lte i.q.tub mos))
843 > ((shim 'a' 'z') [[1 1] "abc"])
844 [p=[p=1 q=2] q=[~ [p=~~a q=[p=[p=1 q=2] q="bc"]]]]
846 > ((shim 'a' 'Z') [[1 1] "abc"])
849 > ((shim 'a' 'Z') [[1 1] "Abc"])
850 [p=[p=1 q=2] q=[~ [p=~~~41. q=[p=[p=1 q=2] q="bc"]]]]
857Use gate to parse delimited list
859Parser modifier: By composing with a gate, parse a delimited `++list` of
876 |* raq/_|*({a/* b/*} [a b])
877 |* {bus/rule fel/rule}
878 ;~((comp raq) fel (stir +<+.raq raq ;~(pfix bus fel)))
885 > (scan "20+5+110" ((slug add) lus dem))
888 > `@t`(scan "a b c" ((slug |=(a/[@ @t] (cat 3 a))) ace alp))
898Add a label to an edge parsed by a rule.
913 ++ stag :: add a label
921 [p=p.vex q=[~ u=[p=[gob p.u.q.vex] q=q.u.q.vex]]]
928 > ((stag %foo (just 'a')) [[1 1] "abc"])
929 [p=[p=1 q=2] q=[~ u=[p=[%foo ~~a] q=[p=[p=1 q=2] q="bc"]]]]
931 > ((stag "xyz" (jest 'abc')) [[1 1] "abc"])
932 [p=[p=1 q=4] q=[~ u=[p=["xyz" 'abc'] q=[p=[p=1 q=4] q=""]]]]
934 > ((stag 10.000 (shim 0 100)) [[1 1] "abc"])
935 [p=[p=1 q=2] q=[~ u=[p=[10.000 ~~a] q=[p=[p=1 q=2] q="bc"]]]]
944Parser modifier: parse `++list` of matches.
953 ++ star :: 0 or more times
955 (stir `(list _(wonk *fel))`~ |*({a/* b/*} [a b]) fel)
961 > (scan "aaaaa" (just 'a'))
966 > (scan "aaaaa" (star (just 'a')))
969 > (scan "abcdef" (star (just 'a')))
974 > (scan "abcabc" (star (jest 'abc')))
977 > (scan "john smith" (star (shim 0 200)))
987Add faces `[p q]` to range-parser pairs in a list.
991`leh` is a list of range-parsers.
1001 |* leh/(list {?(@ {@ @}) rule})
1005 [i=[p=-.i.leh q=+.i.leh] t=$(leh t.leh)]
1012 > (stet (limo [[5 (just 'a')] [1 (jest 'abc')] [[1 1] (shim 0 200)]
1013 [[1 10] (cold %foo (just 'a'))]~]))
1015 [p=5 q=<1.lrk [tub=[p=[p=@ud q=@ud] q=""] <1.nqy [daf=@tD <394.imz 97.kdz 1.xlc %164>]>]>]
1016 [p=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 1] q=<1.lrk [tub=[p=[p=@ud q=@ud] q=""] <1.nqy [daf=@tD <394.imz 97.kdz 1.xlc %164>]>]>]
1018 [p=[1 10] q=<1.lrk [tub=[p=[p=@ud q=@ud] q=""] <1.nqy [daf=@tD <394.imz 97.kdz 1.xlc %164>]>]>]
1020 > [[[1 1] (just 'a')] [[2 1] (shim 0 200)] ~]
1021 [ [[1 1] <1.tnv [tub=[p=[p=@ud q=@ud] q=""] <1.ktu [daf=@tD <414.fvk 101.jzo 1.ypj %164>]>]>]
1022 [[2 1] <1.fvg [tub=[p=[p=@ud q=@ud] q=""] <1.khu [[les=@ mos=@] <414.fvk 101.jzo 1.ypj %164>]>]>]
1025 > (stet (limo [[[1 1] (just 'a')] [[2 1] (shim 0 200)] ~]))
1027 [p=[1 1] q=<1.lrk [tub=[p=[p=@ud q=@ud] q=""] <1.nqy [daf=@tD <394.imz 97.kdz 1.xlc %164>]>]>]
1028 [p=[2 1] q=<1.lrk [tub=[p=[p=@ud q=@ud] q=""] <1.nqy [daf=@tD <394.imz 97.kdz 1.xlc %164>]>]>]
1039 ++ stew :: switch by first char
1041 |* leh/(list {p/?(@ {@ @}) q/rule}) :: char+range keys
1042 =+ ^= wor :: range complete lth
1043 |= {ort/?(@ {@ @}) wan/?(@ {@ @})}
1045 ?@(wan (lth ort wan) (lth ort -.wan))
1046 ?@(wan (lth +.ort wan) (lth +.ort -.wan))
1047 =+ ^= hel :: build parser map
1048 =+ hel=`(tree _?>(?=(^ leh) i.leh))`~
1056 ?: (wor p.i.leh p.n.yal)
1059 ?: (vor p.n.yal p.n.nuc)
1061 [n.nuc l.nuc [n.yal r.nuc r.yal]]
1064 ?: (vor p.n.yal p.n.nuc)
1066 [n.nuc [n.yal l.yal l.nuc] r.nuc]
1076 ?&((gte i.q.tub -.p.n.hel) (lte i.q.tub +.p.n.hel))
1077 :: (q.n.hel [(lust i.q.tub p.tub) t.q.tub])
1079 ?: (wor i.q.tub p.n.hel)
1086Parser generator. From an associative `++list` of characters or character
1087ranges to `++rule`s, construct a `++map`, and parse `++tape`s only
1088with `++rules` associated with a range that the `++tape`'s first character falls in.
1097Parse with `++rule` as many times as possible, and fold over results with a
1104`raq` is a gate that takes two nouns and produces a cell.
1117 |* {rud/* raq/_=>(~ |*({a/* b/*} [a b])) fel/rule}
1124 =+ wag=$(tub q.u.q.vex)
1126 [(last p.vex p.wag) [~ (raq p.u.q.vex p.u.q.wag) q.u.q.wag]]
1132 > (scan "abc" (stir *@ add prn))
1145Parse bounded number of times.
1149`[les=@ mos=@]` is a cell of atoms indicating the bounds.
1160 ++ stun :: parse several times
1161 |* {lig/{@ @} fel/rule}
1163 ^- (like (list _(wonk (fel))))
1172 -.lig ?:(=(0 -.lig) 0 (dec -.lig))
1173 +.lig ?:(=(0 +.lig) 0 (dec +.lig))
1178 [p.wag [~ [p.u.q.vex p.u.q.wag] q.u.q.wag]]
1184 > ((stun [5 10] prn) [1 1] "aquickbrownfoxran")
1185 [p=[p=1 q=11] q=[~ [p="aquickbrow" q=[p=[p=1 q=11] q="nfoxran"]]]]
1187 > ((stun [5 10] prn) [1 1] "aquickbro")
1188 [p=[p=1 q=10] q=[~ [p="aquickbro" q=[p=[p=1 q=10] q=""]]]]
1190 > ((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