3 title/'4f: Parsing (Rule-Builders)'
9# 4f: parsing (rule builders)
14ordered `++list` as atom of a `++base`.
35 =|({p/@ q/@} |.((add p (mul wuc q))))
43 > (scan "123" (bass 10 (star dit)))
45 > (scan "123" (bass 8 (star dit)))
47 > `@ub`(scan "123" (bass 8 (star dit)))
58Ordered `++list` as atom of a `++base`.
79 =|({p/@ q/@} |.((add p (mul wuc q))))
87 > (scan "123" (boss 10 (star dit)))
90 > `@t`(scan "bam" (boss 256 (star alp)))
93 > `@ux`(scan "bam" (boss 256 (star alp)))
102Parser modifier. Accepts a `++rule` `sef` and produces a parser that
103produces a constant `cus`, assuming `sef` is successful.
107`cus` is a constant noun.
118 ++ cold :: replace w+ constant
126 [p=p.vex q=[~ u=[p=cus q=q.u.q.vex]]]
132 > ((cold %foo (just 'a')) [[1 1] "abc"])
133 [p=[p=1 q=2] q=[~ u=[p=%foo q=[p=[p=1 q=2] q="bc"]]]]
135 > ((cold %foo (just 'a')) [[1 1] "bc"])
145Parser modifier. Produces a parser that takes a (successful) result of a
146`++rule` `sef` and slams it through `poq`.
161 ++ cook :: apply gate
163 |* {poq/gate sef/rule}
169 [p=p.vex q=[~ u=[p=(poq p.u.q.vex) q=q.u.q.vex]]]
176 > ((cook ,@ud (just 'a')) [[1 1] "abc"])
177 [p=[p=1 q=2] q=[~ u=[p=97 q=[p=[p=1 q=2] q="bc"]]]]
179 > ((cook ,@tas (just 'a')) [[1 1] "abc"])
180 [p=[p=1 q=2] q=[~ u=[p=%a q=[p=[p=1 q=2] q="bc"]]]]
182 > ((cook |=(a=@ +(a)) (just 'a')) [[1 1] "abc"])
183 [p=[p=1 q=2] q=[~ u=[p=98 q=[p=[p=1 q=2] q="bc"]]]]
185 > ((cook |=(a=@ `@t`+(a)) (just 'a')) [[1 1] "abc"])
186 [p=[p=1 q=2] q=[~ u=[p='b' q=[p=[p=1 q=2] q="bc"]]]]
195Parser generator. Produces a parser that succeeds with given noun `huf`
196without consuming any text.
209 ++ easy :: always parse
215 [p=p.tub q=[~ u=[p=huf q=tub]]]
222 > ((easy %foo) [[1 1] "abc"])
223 [p=[p=1 q=1] q=[~ [p=%foo q=[p=[p=1 q=1] q="abc"]]]]
225 > ((easy %foo) [[1 1] "bc"])
226 [p=[p=1 q=1] q=[~ [p=%foo q=[p=[p=1 q=1] q="bc"]]]]
228 > ((easy 'a') [[1 1] "bc"])
229 [p=[p=1 q=1] q=[~ [p='a' q=[p=[p=1 q=1] q="bc"]]]]
238Parser modifier. Accepts a `++rule` `sef`, and produces a parser that succeeds only
239when the of `tub` is fully consumed using `sef`.
252 ++ full :: parse to end
256 ?~(q.vex vex ?:(=(~ q.q.u.q.vex) vex [p=p.vex q=~]))
263 > ((full (just 'a')) [[1 1] "ab"])
266 > ((full (jest 'ab')) [[1 1] "ab"])
267 [p=[p=1 q=3] q=[~ u=[p='ab' q=[p=[p=1 q=3] q=""]]]]
269 > ((full ;~(plug (just 'a') (just 'b'))) [[1 1] "ab"])
270 [p=[p=1 q=3] q=[~ u=[p=[~~a ~~b] q=[p=[p=1 q=3] q=""]]]]
279Parser modifier: prepend text to `++tape` before applying parser.
294 ++ funk :: add to tape first
295 |* {pre/tape sef/rule}
297 (sef p.tub (weld pre q.tub))
303 > ((funk "abc prefix-" (jest 'abc')) [[1 1] "to be parsed"])
304 [p=[p=1 q=4] q=[~ [p='abc' q=[p=[p=1 q=4] q=" prefix-to be parsed"]]]]
306 > ((funk "parse" (just 'a')) [[1 4] " me"])
316Parser modifier. Similar to `++cook` in that it produces a parser that takes a
317(successful) result of `sef` and slams it through `hez`. `hez` accepts a
318`++pint` `a` and a noun `b`, which is what the parser parsed.
333 ++ here :: place-based apply
335 |* {hez/_|=({a/pint b/*} [a b]) sef/rule}
341 [p=p.vex q=[~ u=[p=(hez [p.tub p.q.u.q.vex] p.u.q.vex) q=q.u.q.vex]]]
348 > (scan "abc" (star alf))
351 > (scan "abc" (here |*(^ +<) (star alf)))
352 [[[p=1 q=1] p=1 q=4] "abc"]
354 > (scan "abc" (star (here |*(^ +<) alf)))
355 ~[[[[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]]
364Parser modifier: surround with pair of `++rule`s, the output of which is
369`fel` is a pair of `++rule`s.
381 |* {fel/{rule rule} hof/rule}
385 ;~(pfix -.fel ;~(sfix hof +.fel))
392 > (scan "-40-" (ifix [hep hep] dem))
395 > (scan "4my4" (ifix [dit dit] (star alf)))
405Match and consume a cord.
418 ++ jest :: match a cord
424 [p=p.tub q=[~ u=[p=fad q=tub]]]
425 ?: |(?=($~ q.tub) !=((end 3 1 daf) i.q.tub))
427 $(p.tub (lust i.q.tub p.tub), q.tub t.q.tub, daf (rsh 3 1 daf))
434 > ((jest 'abc') [[1 1] "abc"])
435 [p=[p=1 q=4] q=[~ [p='abc' q=[p=[p=1 q=4] q=""]]]]
437 > (scan "abc" (jest 'abc'))
440 > (scan "abc" (jest 'acb'))
445 > ((jest 'john doe') [[1 1] "john smith"])
448 > ((jest 'john doe') [[1 1] "john doe"])
449 [p=[p=1 q=9] q=[~ [p='john doe' q=[p=[p=1 q=9] q=""]]]]
458Match and consume a single character.
471 ++ just :: XX redundant, jest
472 ~/ %just :: match a char
488 > ((just 'a') [[1 1] "abc"])
489 [p=[p=1 q=2] q=[~ [p=~~a q=[p=[p=1 q=2] q="bc"]]]]
491 > (scan "abc" (just 'a'))
496 > (scan "a" (just 'a'))
499 > (scan "%" (just '%'))
509Used for recursive parsers, which would otherwise be infinite when
516`sef` is a gate that accepts a `++rule`
526 |* {gar/* sef/_|.(*rule)}
536 > |-(;~(plug prn ;~(pose $ (easy ~))))
540 > |-(;~(plug prn ;~(pose (knee *tape |.(^$)) (easy ~))))
542 [ c=c=tub=[p=[p=@ud q=@ud] q=""]
545 [ c=tub=[p=[p=@ud q=@ud] q=""]
546 b=<1.tnv [tub=[p=[p=@ud q=@ud] q=""] <1.ktu [daf=@tD <414.fvk 101.jzo 1.ypj %164>]>]>
547 a=<1.fvg [tub=[p=[p=@ud q=@ud] q=""] <1.khu [[les=@ mos=@] <414.fvk 101.jzo 1.ypj %164>]>]>
548 v=<414.fvk 101.jzo 1.ypj %164>
552 ... 450 lines omitted ...
555 > (scan "abcd" |-(;~(plug prn ;~(pose (knee *tape |.(^$)) (easy ~)))))
565Parser generator. Matches the next character if it is in a list of
570`bud` is a list of `++char`
579 ++ mask :: match char in set
587 ?. (lien bud |=(a/char =(i.q.tub a)))
596 > (scan "a" (mask "cba"))
599 > ((mask "abc") [[1 1] "abc"])
600 [p=[p=1 q=2] q=[~ [p=~~a q=[p=[p=1 q=2] q="bc"]]]]
602 > ((mask "abc") [[1 1] "bbc"])
603 [p=[p=1 q=2] q=[~ [p=~~b q=[p=[p=1 q=2] q="bc"]]]]
605 > ((mask "abc") [[1 1] "dbc"])
612Parse list with delimiter
614Parser modifier: Parse a list of matches using a delimiter `++rule`.
630 |* {bus/rule fel/rule}
631 ;~(pose (most bus fel) (easy ~))
638 > (scan "" (more ace dem))
641 > (scan "40 20" (more ace dem))
644 > (scan "40 20 60 1 5" (more ace dem))
645 [q=40 ~[q=20 q=60 q=1 q=5]]
652Parse list of at least one match
654Parser modifier: parse a `++list` of at least one match using a delimiter `++rule`.
670 |* {bus/rule fel/rule}
671 ;~(plug fel (star ;~(pfix bus fel)))
678 > (scan "40 20" (most ace dem))
681 > (scan "40 20 60 1 5" (most ace dem))
682 [q=40 ~[q=20 q=60 q=1 q=5]]
684 > (scan "" (most ace dem))
695Consume any character, producing it as a result.
708 ++ next :: consume a char
713 =+ zac=(lust i.q.tub p.tub)
714 [zac [~ i.q.tub [zac t.q.tub]]]
721 > (next [[1 1] "ebc"])
722 [p=[p=1 q=2] q=[~ [p=~~e q=[p=[p=1 q=2] q="bc"]]]]
724 > (next [[1 1] "john jumps jones"])
725 [p=[p=1 q=2] q=[~ [p=~~j q=[p=[p=1 q=2] q="ohn jumps jones"]]]]
733List of at least one match.
735Parser modifier: parse `++list` of at least one match.
748 ++ plus |*(fel/rule ;~(plug fel (star fel)))
754 > (scan ">>>>" (cook lent (plus gar)))
757 > (scan "- - " (plus ;~(pose ace hep)))
760 > `tape`(scan "- - " (plus ;~(pose ace hep)))
763 > `(pole ,@t)`(scan "- - " (plus ;~(pose ace hep)))
764 ['-' [' ' [' ' ['-' [' ' ~]]]]]
773Conditional `++cook`. Slams the result through a gate that produces
774a unit; if that unit is empty, fail.
787 ++ sear :: conditional cook
788 |* {pyq/$-(* (unit)) sef/rule}
793 =+ gey=(pyq p.u.q.vex)
796 [p=p.vex q=[~ u=[p=u.gey q=q.u.q.vex]]]
803 > ((sear |=(a/* ?@(a (some a) ~)) (just `a`)) [[1 1] "abc"])
804 [p=[p=1 q=2] q=[~ u=[p=97 q=[p=[p=1 q=2] q="bc"]]]]
806 > ((sear |=(* ~) (just 'a')) [[1 1] "abc"])
816Match characters (`++char`) within a range.
831 ++ shim :: match char in range
839 ?. ?&((gte i.q.tub les) (lte i.q.tub mos))
848 > ((shim 'a' 'z') [[1 1] "abc"])
849 [p=[p=1 q=2] q=[~ [p=~~a q=[p=[p=1 q=2] q="bc"]]]]
851 > ((shim 'a' 'Z') [[1 1] "abc"])
854 > ((shim 'a' 'Z') [[1 1] "Abc"])
855 [p=[p=1 q=2] q=[~ [p=~~~41. q=[p=[p=1 q=2] q="bc"]]]]
862Use gate to parse delimited list
864Parser modifier: By composing with a gate, parse a delimited `++list` of
881 |* raq/_|*({a/* b/*} [a b])
882 |* {bus/rule fel/rule}
883 ;~((comp raq) fel (stir +<+.raq raq ;~(pfix bus fel)))
890 > (scan "20+5+110" ((slug add) lus dem))
893 > `@t`(scan "a b c" ((slug |=(a/[@ @t] (cat 3 a))) ace alp))
903Add a label to an edge parsed by a rule.
918 ++ stag :: add a label
926 [p=p.vex q=[~ u=[p=[gob p.u.q.vex] q=q.u.q.vex]]]
933 > ((stag %foo (just 'a')) [[1 1] "abc"])
934 [p=[p=1 q=2] q=[~ u=[p=[%foo ~~a] q=[p=[p=1 q=2] q="bc"]]]]
936 > ((stag "xyz" (jest 'abc')) [[1 1] "abc"])
937 [p=[p=1 q=4] q=[~ u=[p=["xyz" 'abc'] q=[p=[p=1 q=4] q=""]]]]
939 > ((stag 10.000 (shim 0 100)) [[1 1] "abc"])
940 [p=[p=1 q=2] q=[~ u=[p=[10.000 ~~a] q=[p=[p=1 q=2] q="bc"]]]]
949Parser modifier: parse `++list` of matches.
958 ++ star :: 0 or more times
960 (stir `(list _(wonk *fel))`~ |*({a/* b/*} [a b]) fel)
966 > (scan "aaaaa" (just 'a'))
971 > (scan "aaaaa" (star (just 'a')))
974 > (scan "abcdef" (star (just 'a')))
979 > (scan "abcabc" (star (jest 'abc')))
982 > (scan "john smith" (star (shim 0 200)))
992Add faces `[p q]` to range-parser pairs in a list.
996`leh` is a list of range-parsers.
1006 |* leh/(list {?(@ {@ @}) rule})
1010 [i=[p=-.i.leh q=+.i.leh] t=$(leh t.leh)]
1017 > (stet (limo [[5 (just 'a')] [1 (jest 'abc')] [[1 1] (shim 0 200)]
1018 [[1 10] (cold %foo (just 'a'))]~]))
1020 [p=5 q=<1.lrk [tub=[p=[p=@ud q=@ud] q=""] <1.nqy [daf=@tD <394.imz 97.kdz 1.xlc %164>]>]>]
1021 [p=1 q=<1.lrk [tub=[p=[p=@ud q=@ud] q=""] <1.nqy [daf=@tD <394.imz 97.kdz 1.xlc %164>]>]>]
1022 [p=[1 1] q=<1.lrk [tub=[p=[p=@ud q=@ud] q=""] <1.nqy [daf=@tD <394.imz 97.kdz 1.xlc %164>]>]>]
1023 [p=[1 10] q=<1.lrk [tub=[p=[p=@ud q=@ud] q=""] <1.nqy [daf=@tD <394.imz 97.kdz 1.xlc %164>]>]>]
1025 > [[[1 1] (just 'a')] [[2 1] (shim 0 200)] ~]
1026 [ [[1 1] <1.tnv [tub=[p=[p=@ud q=@ud] q=""] <1.ktu [daf=@tD <414.fvk 101.jzo 1.ypj %164>]>]>]
1027 [[2 1] <1.fvg [tub=[p=[p=@ud q=@ud] q=""] <1.khu [[les=@ mos=@] <414.fvk 101.jzo 1.ypj %164>]>]>]
1030 > (stet (limo [[[1 1] (just 'a')] [[2 1] (shim 0 200)] ~]))
1032 [p=[1 1] q=<1.lrk [tub=[p=[p=@ud q=@ud] q=""] <1.nqy [daf=@tD <394.imz 97.kdz 1.xlc %164>]>]>]
1033 [p=[2 1] q=<1.lrk [tub=[p=[p=@ud q=@ud] q=""] <1.nqy [daf=@tD <394.imz 97.kdz 1.xlc %164>]>]>]
1044 ++ stew :: switch by first char
1046 |* leh/(list {p/?(@ {@ @}) q/rule}) :: char+range keys
1047 =+ ^= wor :: range complete lth
1048 |= {ort/?(@ {@ @}) wan/?(@ {@ @})}
1050 ?@(wan (lth ort wan) (lth ort -.wan))
1051 ?@(wan (lth +.ort wan) (lth +.ort -.wan))
1052 =+ ^= hel :: build parser map
1053 =+ hel=`(tree _?>(?=(^ leh) i.leh))`~
1061 ?: (wor p.i.leh p.n.yal)
1064 ?: (vor p.n.yal p.n.nuc)
1066 [n.nuc l.nuc [n.yal r.nuc r.yal]]
1069 ?: (vor p.n.yal p.n.nuc)
1071 [n.nuc [n.yal l.yal l.nuc] r.nuc]
1081 ?&((gte i.q.tub -.p.n.hel) (lte i.q.tub +.p.n.hel))
1082 :: (q.n.hel [(lust i.q.tub p.tub) t.q.tub])
1084 ?: (wor i.q.tub p.n.hel)
1091Parser generator. From an associative `++list` of characters or character
1092ranges to `++rule`s, construct a `++map`, and parse `++tape`s only
1093with `++rules` associated with a range that the `++tape`'s first character falls in.
1102Parse with `++rule` as many times as possible, and fold over results with a
1109`raq` is a gate that takes two nouns and produces a cell.
1120 ++ stun :: parse several times
1121 |* {lig/{@ @} fel/rule}
1123 ^- (like (list _(wonk (fel))))
1132 -.lig ?:(=(0 -.lig) 0 (dec -.lig))
1133 +.lig ?:(=(0 +.lig) 0 (dec +.lig))
1138 [p.wag [~ [p.u.q.vex p.u.q.wag] q.u.q.wag]]
1144 > (scan "abc" (stir *@ add prn))
1157Parse bounded number of times.
1161`[les=@ mos=@]` is a cell of atoms indicating the bounds.
1172 ++ stun :: parse several times
1173 |* {lig/{@ @} fel/rule}
1175 ^- (like (list _(wonk (fel))))
1184 -.lig ?:(=(0 -.lig) 0 (dec -.lig))
1185 +.lig ?:(=(0 +.lig) 0 (dec +.lig))
1190 [p.wag [~ [p.u.q.vex p.u.q.wag] q.u.q.wag]]
1196 > ((stun [5 10] prn) [1 1] "aquickbrownfoxran")
1197 [p=[p=1 q=11] q=[~ [p="aquickbrow" q=[p=[p=1 q=11] q="nfoxran"]]]]
1199 > ((stun [5 10] prn) [1 1] "aquickbro")
1200 [p=[p=1 q=10] q=[~ [p="aquickbro" q=[p=[p=1 q=10] q=""]]]]
1202 > ((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