2title = "4e: Parsing (Combinators)"
11Parsing composer: connects the `++edge` `vex` with the subsequent `++rule` `sab`
12as an optional suffix, using gate `raq` to compose or reject its
13result. If there is no suffix, or if the suffix fails to be composed
14with the current result, the current result is produced. Used to map a
15group of rules to a specified output.
32 ++ bend :: conditional comp
34 |* raq/_|*({a/* b/*} [~ u=[a b]])
36 |* {vex/edge sab/rule}
39 =+ yit=(sab q.u.q.vex)
40 =+ yur=(last p.vex p.yit)
43 =+ vux=(raq p.u.q.vex p.u.q.yit)
46 [p=yur q=[~ u=[p=u.vux q=q.u.q.yit]]]
53 > (;~((bend |=([a/char b/char] ?.(=(a b) ~ (some +(a))))) prn prn) [1 1] "qs")
54 [p=[p=1 q=3] q=[~ u=[p=~~q q=[p=[p=1 q=2] q="s"]]]]
56 > (;~((bend |=([a/char b/char] ?.(=(a b) ~ (some +(a))))) prn prn) [1 1] "qqq")
57 [p=[p=1 q=3] q=[~ u=[p=~~r q=[p=[p=1 q=3] q="q"]]]]
59 > (scan "aa" ;~((bend |=([a/char b/char] ?.(=(a b) ~ (some +(a))))) prn prn))
62 > (scan "ba" ;~((bend |=([a/char b/char] ?.(=(a b) ~ (some +(a))))) prn prn))
66 > `(unit @tas)`(scan "" ;~((bend) (easy ~) sym))
69 > `(unit @tas)`(scan "sep" ;~((bend) (easy ~) sym))
79Parsing composer: connects the `++edge` `vex` with a following `++rule` `sab`,
80combining the contents of `vex` with the result of `sab` using a binary
81gate `raq`. Used to fold over the results of several `++rules`.
85`raq` is a gate that accepts a cell of two nouns, `a` and `b`, and
86produces a cell of two nouns.
101 |* raq/_|*({a/* b/*} [a b]) :: arbitrary compose
103 |* {vex/edge sab/rule}
107 =+ yit=(sab q.u.q.vex)
108 =+ yur=(last p.vex p.yit)
111 [p=yur q=[~ u=[p=(raq p.u.q.vex p.u.q.yit) q=q.u.q.yit]]]
118 > (scan "123" ;~((comp |=([a/@u b/@u] (add a b))) dit dit dit))
120 > (scan "12" ;~((comp |=([a/@u b/@u] (add a b))) dit dit dit))
131Produces an `++edge` at the same text position (`++hair`) with a failing
145 ++ fail |=(tub/nail [p=p.tub q=~]) :: never parse
151 > (fail [[1 1] "abc"])
154 > (fail [[p=1.337 q=70] "Parse me, please?"])
155 [p=[p=1.337 q=70] q=~]
164Parsing composer: connects an `++edge` `vex` with a following `++rule` `sab` by
165parsing the `++rule` `bus` (the delimiting symbol) and throwing out the
185 |* {vex/edge sab/rule}
186 (plug vex ;~(pfix bus sab))
193 > (scan "200|mal|bon" ;~((glue bar) dem sym sym))
194 [q=200 7.102.829 7.237.474]
196 > `[@u @tas @tas]`(scan "200|mal|bon" ;~((glue bar) dem sym sym))
199 > (scan "200|;|bon" ;~((glue bar) dem sem sym))
200 [q=200 ~~~3b. 7.237.474]
202 > (scan "200.;.bon" ;~((glue dot) dem sem sym))
203 [q=200 ~~~3b. 7.237.474]
212Parsing composer: if an `++edge` `vex` reflects a success, fail. Otherwise,
213connect `vex` with the following `++rule`.
226 ++ less :: no first and second
227 |* {vex/edge sab/rule}
230 [p=(last p.vex p.roq) q=q.roq]
238 > (scan "sas-/lo" (star ;~(less lus bar prn)))
241 > (scan "sas-/l+o" (star ;~(less lus bar prn)))
245 > (scan "sas|-/lo" (star ;~(less lus bar prn)))
256Parsing composer: connects an `++edge` `vex` with two subsequent `++rule`s,
257ignoring the result of the first and producing the result of the second.
268 ++ pfix :: discard first rule
270 (comp |*({a/* b/*} b))
276 > `@t`(scan "%him" ;~(pfix cen sym))
279 > (scan "+++10" ;~(pfix (star lus) dem))
289Parsing composer: connects an `++edge` `vex` with a following `++rule` `sab`, producing
290a cell of both the results. See also: the monad applicator ;\~ for a
291more detailed explanation.
304 ++ plug :: first then second
306 |* {vex/edge sab/rule}
309 =+ yit=(sab q.u.q.vex)
310 =+ yur=(last p.vex p.yit)
313 [p=yur q=[~ u=[p=[p.u.q.vex p.u.q.yit] q=q.u.q.yit]]]
320 > (scan "1..20" ;~(plug dem dot dot dem))
323 > (scan "moke/~2014.1.1" ;~(plug sym fas nuck:so))
324 [1.701.539.693 ~~~2f. [% p=[p=~.da q=170.141.184.500.766.106.671.844.917.172.921.958.400]]]
326 > ;;(,[@tas @t ~ %da @da] (scan "moke/~2014.1.1" ;~(plug sym fas nuck:so)))
327 [%moke '/' ~ %da ~2014.1.1]
336Parsing composer: if `vex` reflects a failure, connect it with the
337following rule `sab`. See also: the monad applicator ;\~
350 ++ pose :: first or second
352 |* {vex/edge sab/rule}
355 [p=(last p.vex p.roq) q=q.roq]
363 > `@t`(scan "+" ;~(pose lus tar cen))
366 > `@t`(scan "*" ;~(pose lus tar cen))
369 > `@t`(scan "%" ;~(pose lus tar cen))
372 > `@t`(scan "-" ;~(pose lus tar cen))
383Parsing composer: connects `++edge`s `vex` with two subsequent `++rule`s returning the
384result of the first and discarding the result of the second.
388`a` is the result of parsing the first `++rule`.
390`b` is the result of of parsing the second `++rule`.
397 ++ sfix :: discard second rule
399 (comp |*({a/* b/*} a))
405 > `@t`(scan "him%" ;~(sfix sym cen))
408 > (scan "10+++" ;~(sfix dem (star lus)))
418Parsing composer: if an `++edge` `vex` reflects a failure, fail. Otherwise,
419connect `vex` with the following `++rule`.
432 ++ simu :: first and second
433 |* {vex/edge sab/rule}
444 > (scan "~zod" scat:vast)
447 > (scan "%zod" scat:vast)
448 [%dtzz p=%tas q=6.582.138]
450 > (scan "%zod" ;~(simu cen scat:vast))
451 [%dtzz p=%tas q=6.582.138]
453 > (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