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))
130Produces an `++edge` at the same text position (`++hair`) with a failing
144 ++ fail |=(tub/nail [p=p.tub q=~]) :: never parse
150 > (fail [[1 1] "abc"])
153 > (fail [[p=1.337 q=70] "Parse me, please?"])
154 [p=[p=1.337 q=70] q=~]
163Parsing composer: connects an `++edge` `vex` with a following `++rule` `sab` by
164parsing the `++rule` `bus` (the delimiting symbol) and throwing out the
186 |* {vex/edge sab/rule}
187 (plug vex ;~(pfix bus sab))
194 > (scan "200|mal|bon" ;~((glue bar) dem sym sym))
195 [q=200 7.102.829 7.237.474]
197 > `[@u @tas @tas]`(scan "200|mal|bon" ;~((glue bar) dem sym sym))
200 > (scan "200|;|bon" ;~((glue bar) dem sem sym))
201 [q=200 ~~~3b. 7.237.474]
203 > (scan "200.;.bon" ;~((glue dot) dem sem sym))
204 [q=200 ~~~3b. 7.237.474]
212Parsing composer: if an `++edge` `vex` reflects a success, fail. Otherwise,
213connect `vex` with the following `++rule`.
228 ++ less :: no first and second
229 |* {vex/edge sab/rule}
232 [p=(last p.vex p.roq) q=q.roq]
240 > (scan "sas-/lo" (star ;~(less lus bar prn)))
243 > (scan "sas-/l+o" (star ;~(less lus bar prn)))
247 > (scan "sas|-/lo" (star ;~(less lus bar prn)))
258Parsing composer: connects an `++edge` `vex` with two subsequent `++rule`s,
259ignoring the result of the first and producing the result of the second.
272 ++ pfix :: discard first rule
274 (comp |*({a/* b/*} b))
280 > `@t`(scan "%him" ;~(pfix cen sym))
283 > (scan "+++10" ;~(pfix (star lus) dem))
293Parsing composer: connects an `++edge` `vex` with a following `++rule` `sab`, producing
294a cell of both the results. See also: the monad applicator ;\~ for a
295more detailed explanation.
310 ++ plug :: first then second
312 |* {vex/edge sab/rule}
315 =+ yit=(sab q.u.q.vex)
316 =+ yur=(last p.vex p.yit)
319 [p=yur q=[~ u=[p=[p.u.q.vex p.u.q.yit] q=q.u.q.yit]]]
326 > (scan "1..20" ;~(plug dem dot dot dem))
329 > (scan "moke/~2014.1.1" ;~(plug sym fas nuck:so))
330 [1.701.539.693 ~~~2f. [% p=[p=~.da q=170.141.184.500.766.106.671.844.917.172.921.958.400]]]
332 > ;;(,[@tas @t ~ %da @da] (scan "moke/~2014.1.1" ;~(plug sym fas nuck:so)))
333 [%moke '/' ~ %da ~2014.1.1]
342Parsing composer: if `vex` reflects a failure, connect it with the
343following rule `sab`. See also: the monad applicator ;\~
358 ++ pose :: first or second
360 |* {vex/edge sab/rule}
363 [p=(last p.vex p.roq) q=q.roq]
371 > `@t`(scan "+" ;~(pose lus tar cen))
374 > `@t`(scan "*" ;~(pose lus tar cen))
377 > `@t`(scan "%" ;~(pose lus tar cen))
380 > `@t`(scan "-" ;~(pose lus tar cen))
391Parsing composer: connects `++edge`s `vex` with two subsequent `++rule`s returning the
392result of the first and discarding the result of the second.
396`a` is the result of parsing the first `++rule`.
398`b` is the result of of parsing the second `++rule`.
407 ++ sfix :: discard second rule
409 (comp |*({a/* b/*} a))
415 > `@t`(scan "him%" ;~(sfix sym cen))
418 > (scan "10+++" ;~(sfix dem (star lus)))
428Parsing composer: if an `++edge` `vex` reflects a failure, fail. Otherwise,
429connect `vex` with the following `++rule`.
444 ++ simu :: first and second
445 |* {vex/edge sab/rule}
456 > (scan "~zod" scat:vast)
459 > (scan "%zod" scat:vast)
460 [%dtzz p=%tas q=6.582.138]
462 > (scan "%zod" ;~(simu cen scat:vast))
463 [%dtzz p=%tas q=6.582.138]
465 > (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