3 title/'4e: Parsing (Combinators)'
8# 4e: parsing (combinators)
14Parsing composer: connects the `++edge` `vex` with the subsequent `++rule` `sab`
15as an optional suffix, using gate `raq` to compose or reject its
16result. If there is no suffix, or if the suffix fails to be composed
17with the current result, the current result is produced. Used to map a
18group of rules to a specified output.
35 ++ bend :: conditional comp
37 |* raq/_|*({a/* b/*} [~ u=[a b]])
39 |* {vex/edge sab/rule}
42 =+ yit=(sab q.u.q.vex)
43 =+ yur=(last p.vex p.yit)
46 =+ vux=(raq p.u.q.vex p.u.q.yit)
49 [p=yur q=[~ u=[p=u.vux q=q.u.q.yit]]]
56 > (;~((bend |=([a/char b/char] ?.(=(a b) ~ (some +(a))))) prn prn) [1 1] "qs")
57 [p=[p=1 q=3] q=[~ u=[p=~~q q=[p=[p=1 q=2] q="s"]]]]
59 > (;~((bend |=([a/char b/char] ?.(=(a b) ~ (some +(a))))) prn prn) [1 1] "qqq")
60 [p=[p=1 q=3] q=[~ u=[p=~~r q=[p=[p=1 q=3] q="q"]]]]
62 > (scan "aa" ;~((bend |=([a/char b/char] ?.(=(a b) ~ (some +(a))))) prn prn))
65 > (scan "ba" ;~((bend |=([a/char b/char] ?.(=(a b) ~ (some +(a))))) prn prn))
69 > `(unit @tas)`(scan "" ;~((bend) (easy ~) sym))
72 > `(unit @tas)`(scan "sep" ;~((bend) (easy ~) sym))
82Parsing composer: connects the `++edge` `vex` with a following `++rule` `sab`,
83combining the contents of `vex` with the result of `sab` using a binary
84gate `raq`. Used to fold over the results of several `++rules`.
88`raq` is a gate that accepts a cell of two nouns, `a` and `b`, and
89produces a cell of two nouns.
104 |* raq/_|*({a/* b/*} [a b]) :: arbitrary compose
106 |* {vex/edge sab/rule}
110 =+ yit=(sab q.u.q.vex)
111 =+ yur=(last p.vex p.yit)
114 [p=yur q=[~ u=[p=(raq p.u.q.vex p.u.q.yit) q=q.u.q.yit]]]
121 > (scan "123" ;~((comp |=([a/@u b/@u] (add a b))) dit dit dit))
123 > (scan "12" ;~((comp |=([a/@u b/@u] (add a b))) dit dit dit))
133Produces an `++edge` at the same text position (`++hair`) with a failing
147 ++ fail |=(tub/nail [p=p.tub q=~]) :: never parse
153 > (fail [[1 1] "abc"])
156 > (fail [[p=1.337 q=70] "Parse me, please?"])
157 [p=[p=1.337 q=70] q=~]
166Parsing composer: connects an `++edge` `vex` with a following `++rule` `sab` by
167parsing the `++rule` `bus` (the delimiting symbol) and throwing out the
189 |* {vex/edge sab/rule}
190 (plug vex ;~(pfix bus sab))
197 > (scan "200|mal|bon" ;~((glue bar) dem sym sym))
198 [q=200 7.102.829 7.237.474]
200 > `[@u @tas @tas]`(scan "200|mal|bon" ;~((glue bar) dem sym sym))
203 > (scan "200|;|bon" ;~((glue bar) dem sem sym))
204 [q=200 ~~~3b. 7.237.474]
206 > (scan "200.;.bon" ;~((glue dot) dem sem sym))
207 [q=200 ~~~3b. 7.237.474]
215Parsing composer: if an `++edge` `vex` reflects a success, fail. Otherwise,
216connect `vex` with the following `++rule`.
231 ++ less :: no first and second
232 |* {vex/edge sab/rule}
235 [p=(last p.vex p.roq) q=q.roq]
243 > (scan "sas-/lo" (star ;~(less lus bar prn)))
246 > (scan "sas-/l+o" (star ;~(less lus bar prn)))
250 > (scan "sas|-/lo" (star ;~(less lus bar prn)))
261Parsing composer: connects an `++edge` `vex` with two subsequent `++rule`s,
262ignoring the result of the first and producing the result of the second.
275 ++ pfix :: discard first rule
277 (comp |*({a/* b/*} b))
283 > `@t`(scan "%him" ;~(pfix cen sym))
286 > (scan "+++10" ;~(pfix (star lus) dem))
296Parsing composer: connects an `++edge` `vex` with a following `++rule` `sab`, producing
297a cell of both the results. See also: the monad applicator ;\~ for a
298more detailed explanation.
313 ++ plug :: first then second
315 |* {vex/edge sab/rule}
318 =+ yit=(sab q.u.q.vex)
319 =+ yur=(last p.vex p.yit)
322 [p=yur q=[~ u=[p=[p.u.q.vex p.u.q.yit] q=q.u.q.yit]]]
329 > (scan "1..20" ;~(plug dem dot dot dem))
332 > (scan "moke/~2014.1.1" ;~(plug sym fas nuck:so))
333 [1.701.539.693 ~~~2f. [% p=[p=~.da q=170.141.184.500.766.106.671.844.917.172.921.958.400]]]
335 > ;;(,[@tas @t ~ %da @da] (scan "moke/~2014.1.1" ;~(plug sym fas nuck:so)))
336 [%moke '/' ~ %da ~2014.1.1]
345Parsing composer: if `vex` reflects a failure, connect it with the
346following rule `sab`. See also: the monad applicator ;\~
361 ++ pose :: first or second
363 |* {vex/edge sab/rule}
366 [p=(last p.vex p.roq) q=q.roq]
374 > `@t`(scan "+" ;~(pose lus tar cen))
377 > `@t`(scan "*" ;~(pose lus tar cen))
380 > `@t`(scan "%" ;~(pose lus tar cen))
383 > `@t`(scan "-" ;~(pose lus tar cen))
394Parsing composer: connects `++edge`s `vex` with two subsequent `++rule`s returning the
395result of the first and discarding the result of the second.
399`a` is the result of parsing the first `++rule`.
401`b` is the result of of parsing the second `++rule`.
410 ++ sfix :: discard second rule
412 (comp |*({a/* b/*} a))
418 > `@t`(scan "him%" ;~(sfix sym cen))
421 > (scan "10+++" ;~(sfix dem (star lus)))
431Parsing composer: if an `++edge` `vex` reflects a failure, fail. Otherwise,
432connect `vex` with the following `++rule`.
447 ++ simu :: first and second
448 |* {vex/edge sab/rule}
459 > (scan "~zod" scat:vast)
462 > (scan "%zod" scat:vast)
463 [%dtzz p=%tas q=6.582.138]
465 > (scan "%zod" ;~(simu cen scat:vast))
466 [%dtzz p=%tas q=6.582.138]
468 > (scan "~zod" ;~(simu cen scat:vast))
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