2title = "4f: Parsing (Rule-Builders)"
10ordered `list` as atom of a `base`.
31 =|([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)))
52Ordered `list` as atom of a `base`.
73 =|([p=@ q=@] |.((add p (mul wuc q))))
80> (scan "123" (boss 10 (star dit)))
83> `@t`(scan "bam" (boss 256 (star alp)))
86> `@ux`(scan "bam" (boss 256 (star alp)))
96Parser modifier. Accepts a `rule` `sef` and produces a parser that produces a
97constant `cus`, assuming `sef` is successful.
101`cus` is a constant noun.
120 [p=p.vex q=[~ u=[p=cus q=q.u.q.vex]]]
126> ((cold %foo (just 'a')) [[1 1] "abc"])
127[p=[p=1 q=2] q=[~ u=[p=%foo q=[p=[p=1 q=2] q="bc"]]]]
129> ((cold %foo (just 'a')) [[1 1] "bc"])
139Parser modifier. Produces a parser that takes a (successful) result of a
140`rule` `sef` and slams it through `poq`.
157 |* [poq=gate sef=rule]
163 [p=p.vex q=[~ u=[p=(poq p.u.q.vex) q=q.u.q.vex]]]
169> ((cook ,@ud (just 'a')) [[1 1] "abc"])
170[p=[p=1 q=2] q=[~ u=[p=97 q=[p=[p=1 q=2] q="bc"]]]]
172> ((cook ,@tas (just 'a')) [[1 1] "abc"])
173[p=[p=1 q=2] q=[~ u=[p=%a q=[p=[p=1 q=2] q="bc"]]]]
175> ((cook |=(a=@ +(a)) (just 'a')) [[1 1] "abc"])
176[p=[p=1 q=2] q=[~ u=[p=98 q=[p=[p=1 q=2] q="bc"]]]]
178> ((cook |=(a=@ `@t`+(a)) (just 'a')) [[1 1] "abc"])
179[p=[p=1 q=2] q=[~ u=[p='b' q=[p=[p=1 q=2] q="bc"]]]]
188Parser generator. Produces a parser that succeeds with given noun `huf`
189without consuming any text.
208 [p=p.tub q=[~ u=[p=huf q=tub]]]
214> ((easy %foo) [[1 1] "abc"])
215[p=[p=1 q=1] q=[~ [p=%foo q=[p=[p=1 q=1] q="abc"]]]]
217> ((easy %foo) [[1 1] "bc"])
218[p=[p=1 q=1] q=[~ [p=%foo q=[p=[p=1 q=1] q="bc"]]]]
220> ((easy 'a') [[1 1] "bc"])
221[p=[p=1 q=1] q=[~ [p='a' q=[p=[p=1 q=1] q="bc"]]]]
230If string `sic` is parsed: `%.y`. If string `non` is parsed: `%.n`. Otherwise, fail.
247 ;~(pose (cold %& (jest sic)) (cold %| (jest non)))
253> (rash 'foo' (fuss 'foo' 'bar'))
256> (rash 'bar' (fuss 'foo' 'bar'))
259> (rash 'baz' (fuss 'foo' 'bar'))
270Parser modifier. Accepts a `rule` `sef`, and produces a parser that succeeds
271only when the `tape` of `tub` is fully consumed using `sef`.
288 ?~(q.vex vex ?:(=(~ q.q.u.q.vex) vex [p=p.vex q=~]))
294> ((full (just 'a')) [[1 1] "ab"])
297> ((full (jest 'ab')) [[1 1] "ab"])
298[p=[p=1 q=3] q=[~ u=[p='ab' q=[p=[p=1 q=3] q=""]]]]
300> ((full ;~(plug (just 'a') (just 'b'))) [[1 1] "ab"])
301[p=[p=1 q=3] q=[~ u=[p=['a' 'b'] q=[p=[p=1 q=3] q=""]]]]
310Parser modifier: prepend text to `tape` before applying parser.
326 |* [pre=tape sef=rule]
328 (sef p.tub (weld pre q.tub))
334> ((funk "abc prefix-" (jest 'abc')) [[1 1] "to be parsed"])
335[p=[p=1 q=4] q=[~ [p='abc' q=[p=[p=1 q=4] q=" prefix-to be parsed"]]]]
337> ((funk "parse" (just 'a')) [[1 4] " me"])
347Parser modifier. Similar to `++cook` in that it produces a parser that takes a
348(successful) result of `sef` and slams it through `hez`. `hez` accepts a
349`pint` `a` and a noun `b`, which is what the parser parsed.
366 =+ [hez=|=([a=pint b=*] [a b]) sef=*rule]
374 [p=p.vex q=[~ u=[p=(hez [p.tub p.q.u.q.vex] p.u.q.vex) q=q.u.q.vex]]]
381> (scan "abc" (star alf))
384> (scan "abc" (here |*(^ +<) (star alf)))
385[[[p=1 q=1] p=1 q=4] "abc"]
387> (scan "abc" (star (here |*(^ +<) alf)))
388~[[[[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]]
395Apply `rule` to indented block starting at current column number, omitting the
411 =+ [har tap]=[p q]:+<
412 =+ lev=(fil 3 (dec q.har) ' ')
414 =+ =- roq=((star ;~(pose prn ;~(sfix eol (jest lev)) -)) har tap)
415 ;~(simu ;~(plug eol eol) eol)
417 =+ vex=(sef har(q 1) p.u.q.roq)
418 =+ fur=p.vex(q (add (dec q.har) q.p.vex))
422 &4.vex(q.p (add (dec q.har) q.p.&4.vex))
425 ?. =(10 -.res) [-.res $(res +.res)]
426 (welp [`@t`10 (trip lev)] $(res +.res))
432> `tape`(scan " foo\0a bar" ;~(pfix ace ace ace (inde (star ;~(pose prn (just '\0a'))))))
438Note the amount of indentation whitespace to be stripped from the beginning of
439each line is determined by the value of `q` (the column) in the `hair` when
440`++inde` is first called. This means something like the `pfix` expression in the
441example above is necessary to set the level of indentation. Additionally, the
442`rule` given to `++inde` must consume the whole line including the line ending.
450Parser modifier: surround with pair of `rule`s, the output of which is
455`fel` is a pair of `rule`s.
467 |* [fel=[rule rule] hof=rule]
471 ;~(pfix -.fel ;~(sfix hof +.fel))
477> (scan "-40-" (ifix [hep hep] dem))
480> (scan "4my4" (ifix [dit dit] (star alf)))
490Match and consume a cord.
509 [p=p.tub q=[~ u=[p=fad q=tub]]]
510 ?: |(?=(~ q.tub) !=((end 3 daf) i.q.tub))
512 $(p.tub (lust i.q.tub p.tub), q.tub t.q.tub, daf (rsh 3 daf))
518> ((jest 'abc') [[1 1] "abc"])
519[p=[p=1 q=4] q=[~ [p='abc' q=[p=[p=1 q=4] q=""]]]]
521> (scan "abc" (jest 'abc'))
524> (scan "abc" (jest 'acb'))
529> ((jest 'john doe') [[1 1] "john smith"])
532> ((jest 'john doe') [[1 1] "john doe"])
533[p=[p=1 q=9] q=[~ [p='john doe' q=[p=[p=1 q=9] q=""]]]]
542Match and consume a single character.
571> ((just 'a') [[1 1] "abc"])
572[p=[p=1 q=2] q=[~ [p='a' q=[p=[p=1 q=2] q="bc"]]]]
574> (scan "abc" (just 'a'))
579> (scan "a" (just 'a'))
582> (scan "%" (just '%'))
592Used for recursive parsers, which would otherwise be infinite when
599`sef` is a gate that accepts a `rule`
609 =| [gar=* sef=_|.(*rule)]
620> |-(;~(plug prn ;~(pose $ (easy ~))))
624> |-(;~(plug prn ;~(pose (knee *tape |.(^$)) (easy ~))))
626 [ c=c=tub=[p=[p=@ud q=@ud] q=""]
629 [ c=tub=[p=[p=@ud q=@ud] q=""]
630 b=<1.tnv [tub=[p=[p=@ud q=@ud] q=""] <1.ktu [daf=@tD <414.fvk 101.jzo 1.ypj %164>]>]>
631 a=<1.fvg [tub=[p=[p=@ud q=@ud] q=""] <1.khu [[les=@ mos=@] <414.fvk 101.jzo 1.ypj %164>]>]>
632 v=<414.fvk 101.jzo 1.ypj %164>
636 ... 450 lines omitted ...
640> (scan "abcd" |-(;~(plug prn ;~(pose (knee *tape |.(^$)) (easy ~)))))
650Parser generator. Matches the next character if it is in a list of characters.
654`bud` is a list of `char`
671 ?. (lien bud |=(a=char =(i.q.tub a)))
679> (scan "a" (mask "cba"))
682> ((mask "abc") [[1 1] "abc"])
683[p=[p=1 q=2] q=[~ [p='a' q=[p=[p=1 q=2] q="bc"]]]]
685> ((mask "abc") [[1 1] "bbc"])
686[p=[p=1 q=2] q=[~ [p='b' q=[p=[p=1 q=2] q="bc"]]]]
688> ((mask "abc") [[1 1] "dbc"])
696Parse list with delimiter
698Parser modifier: Parse a list of matches using a delimiter `rule`.
714 |* [bus=rule fel=rule]
715 ;~(pose (most bus fel) (easy ~))
721> (scan "" (more ace dem))
724> (scan "40 20" (more ace dem))
727> (scan "40 20 60 1 5" (more ace dem))
728[40 [i=20 t=~[60 1 5]]]
735Parse list of at least one match
737Parser modifier: parse a `list` of at least one match using a delimiter `rule`.
753 |* [bus=rule fel=rule]
754 ;~(plug fel (star ;~(pfix bus fel)))
760> (scan "40 20" (most ace dem))
763> (scan "40 20 60 1 5" (most ace dem))
764[40 [i=20 t=~[60 1 5]]]
766> (scan "" (most ace dem))
777Consume any character, producing it as a result.
795 =+ zac=(lust i.q.tub p.tub)
796 [zac [~ i.q.tub [zac t.q.tub]]]
802> (next [[1 1] "ebc"])
803[p=[p=1 q=2] q=[~ [p='e' q=[p=[p=1 q=2] q="bc"]]]]
805> (next [[1 1] "john jumps jones"])
806[p=[p=1 q=2] q=[~ [p='j' q=[p=[p=1 q=2] q="ohn jumps jones"]]]]
815Given `a`, a list of `@tas`, match any one in the list and produce it. Note the
816list should not be a `list` type, but just a null-terminated cell like `~[%foo %bar %baz]`. The type produced will be a union of the items in the given list,
817so you can use a `?-` expression on the output.
821`a` is a `(pole @tas)`.
834 (cold -.a (jest -.a))
842> (scan "foo" (perk ~[%foo %bar]))
845> (scan "bar" (perk ~[%foo %bar]))
848> (scan "baz" (perk ~[%foo %bar]))
857List of at least one match.
859Parser modifier: parse `list` of at least one match.
872++ plus |*(fel=rule ;~(plug fel (star fel))) ::
878> (scan ">>>>" (cook lent (plus gar)))
881> (scan "- - " (plus ;~(pose ace hep)))
882['-' [i=' ' t=~[' ' '-' ' ']]]
884> `tape`(scan "- - " (plus ;~(pose ace hep)))
887> `(pole ,@t)`(scan "- - " (plus ;~(pose ace hep)))
888['-' [' ' [' ' ['-' [' ' ~]]]]]
897Either successfully apply `rule` `a` and produce a `unit` of the result, or produce `~`.
910++ punt |*([a=rule] ;~(pose (stag ~ a) (easy ~)))
916> ((punt (jest 'foo')) 1^1 "foo")
917[p=[p=1 q=4] q=[~ u=[p=[~ 'foo'] q=[p=[p=1 q=4] q=~]]]]
919> ((punt (jest 'foo')) 1^1 "bar")
920[p=[p=1 q=1] q=[~ [p=~ q=[p=[p=1 q=1] q="bar"]]]]
929Conditional `cook`. Slams the result through a gate that produces
930a unit; if that unit is empty, fail.
934`pyq` is a gate that produces a `unit`.
946 |* [pyq=$-(* (unit)) sef=rule]
951 =+ gey=(pyq p.u.q.vex)
954 [p=p.vex q=[~ u=[p=u.gey q=q.u.q.vex]]]
960> ((sear |=(a=* ?@(a (some a) ~)) (just 'a')) [[1 1] "abc"])
961[p=[p=1 q=2] q=[~ u=[p=97 q=[p=[p=1 q=2] q="bc"]]]]
963> ((sear |=(* ~) (just 'a')) [[1 1] "abc"])
973Match characters (`char`) within a range.
996 ?. ?&((gte i.q.tub les) (lte i.q.tub mos))
1004> `tape`(rash 'abc' (plus (shim 'a' 'z')))
1007> `tape`(rash 'ABC' (plus (shim 'a' 'z')))
1016Use gate to parse delimited list
1018Parser modifier: By composing with a gate, parse a delimited `list` of
1023`raq` is a binary gate.
1037 |* raq=_=>(~ |*([a=* b=*] [a b]))
1038 |* [bus=rule fel=rule]
1039 ;~((comp raq) fel (stir +<+.raq raq ;~(pfix bus fel)))
1045> (scan "20+5+110" ((slug add) lus dem))
1048> `@t`(scan "a b c" ((slug |=(a=[@t @t] (cat 3 a))) ace alp))
1058Add a label to an `edge` parsed by a `rule`.
1081 [p=p.vex q=[~ u=[p=[gob p.u.q.vex] q=q.u.q.vex]]]
1087> (rash 'abc' (stag %foo (jest 'abc')))
1097Parser modifier: parse `list` of matches.
1112 (stir `(list _(wonk *fel))`~ |*([a=* b=*] [a b]) fel)
1118> (scan "aaaaa" (just 'a'))
1123> (scan "aaaaa" (star (just 'a')))
1126> (scan "abcdef" (star (just 'a')))
1131> (scan "abcabc" (star (jest 'abc')))
1134> (scan "john smith" (star (shim 0 200)))
1144Add faces `[p q]` to range-parser pairs in a list. Typically used in combination
1145with [`++stew`](#stew).
1149`leh` is a list of range-parsers.
1153A `(list [p=?(@ [@ @]) q=rule])`.
1159 |* leh=(list [?(@ [@ @]) rule])
1163 [i=[p=-.i.leh q=+.i.leh] t=$(leh t.leh)]
1173 [['a' 'z'] (cook |=(a=@ (sub a 32)) alp)]
1174 [['A' 'Z'] (cook |=(a=@ (add a 32)) alp)]
1177> `tape`(rash 'fooBARbaz' (star rule))
1187Parser generator. From an associative `list` of characters or character
1188ranges to `rule`s, construct a `map`, and parse `tape`s only
1189with `rule`s associated with a range that the `tape`'s first character falls in.
1193`leh` is a `(list [p=?(@ [@ @]) q=rule])`, where `p` is a `char` or `char` range.
1202++ stew :: switch by first char
1204 |* leh=(list [p=?(@ [@ @]) q=rule]) :: char+range keys
1205 =+ ^= wor :: range complete lth
1206 |= [ort=?(@ [@ @]) wan=?(@ [@ @])]
1208 ?@(wan (lth ort wan) (lth ort -.wan))
1209 ?@(wan (lth +.ort wan) (lth +.ort -.wan))
1210 =+ ^= hel :: build parser map
1211 =+ hel=`(tree _?>(?=(^ leh) i.leh))`~
1219 ?: (wor p.i.leh p.n.yal)
1222 ?: (mor p.n.yal p.n.nuc)
1224 [n.nuc l.nuc [n.yal r.nuc r.yal]]
1227 ?: (mor p.n.yal p.n.nuc)
1229 [n.nuc [n.yal l.yal l.nuc] r.nuc]
1239 ?&((gte i.q.tub -.p.n.hel) (lte i.q.tub +.p.n.hel))
1240 :: (q.n.hel [(lust i.q.tub p.tub) t.q.tub])
1242 ?: (wor i.q.tub p.n.hel)
1254 [['a' 'z'] (cook |=(a=@ (sub a 32)) alp)]
1255 [['A' 'Z'] (cook |=(a=@ (add a 32)) alp)]
1258> `tape`(rash 'fooBARbaz' (star rule))
1268Parse with `rule` as many times as possible, and fold over results with a
1275`raq` is a gate that takes two nouns and produces a cell.
1288 |* [rud=* raq=_=>(~ |*([a=* b=*] [a b])) fel=rule]
1293 :: lef: successful interim parse results (per .fel)
1294 :: wag: initial accumulator (.rud in .tub at farthest success)
1297 =| lef=(list _(fel tub))
1298 |- ^- [_lef (pair hair [~ u=(pair _rud nail)])]
1303 $(lef [vex lef], tub q.u.q.vex)
1305 :: fold .lef into .wag, combining results with .raq
1308 |= _[vex=(fel tub) wag=wag] :: q.vex is always (some)
1310 :- (last p.vex p.wag)
1311 [~ (raq p.u.+.q.vex p.u.q.wag) q.u.q.wag]
1317> (scan "abc" (stir *@ add prn))
1330Parse bounded number of times.
1334`lig` is a cell of atoms (`[@ @]`) indicating the bounds.
1347 |* [lig=[@ @] fel=rule]
1349 ^- (like (list _(wonk (fel))))
1358 -.lig ?:(=(0 -.lig) 0 (dec -.lig))
1359 +.lig ?:(=(0 +.lig) 0 (dec +.lig))
1364 [p.wag [~ [p.u.q.vex p.u.q.wag] q.u.q.wag]]
1370> ((stun [5 10] prn) [1 1] "aquickbrownfoxran")
1371[p=[p=1 q=11] q=[~ [p="aquickbrow" q=[p=[p=1 q=11] q="nfoxran"]]]]
1373> ((stun [5 10] prn) [1 1] "aquickbro")
1374[p=[p=1 q=10] q=[~ [p="aquickbro" q=[p=[p=1 q=10] q=""]]]]
1376> ((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