1# 4e: parsing (combinators)
6Parsing composer: connects the `++edge` `vex` with the subsequent `++rule` `sab`
7as an optional suffix, using gate `raq` to compose or reject its
8result. If there is no suffix, or if the suffix fails to be composed
9with the current result, the current result is produced. Used to map a
10group of rules to a specified output.
29 ++ bend :: conditional comp
31 |* raq/_|*({a/* b/*} [~ u=[a b]])
33 |* {vex/edge sab/rule}
36 =+ yit=(sab q.u.q.vex)
37 =+ yur=(last p.vex p.yit)
40 =+ vux=(raq p.u.q.vex p.u.q.yit)
43 [p=yur q=[~ u=[p=u.vux q=q.u.q.yit]]]
49 > (;~((bend |=([a/char b/char] ?.(=(a b) ~ (some +(a))))) prn prn) [1 1] "qs")
50 [p=[p=1 q=3] q=[~ u=[p=~~q q=[p=[p=1 q=2] q="s"]]]]
51 > (;~((bend |=([a/char b/char] ?.(=(a b) ~ (some +(a))))) prn prn) [1 1] "qqq")
52 [p=[p=1 q=3] q=[~ u=[p=~~r q=[p=[p=1 q=3] q="q"]]]]
53 > (scan "aa" ;~((bend |=([a/char b/char] ?.(=(a b) ~ (some +(a))))) prn prn))
55 > (scan "ba" ;~((bend |=([a/char b/char] ?.(=(a b) ~ (some +(a))))) prn prn))
58 > `(unit @tas)`(scan "" ;~((bend) (easy ~) sym))
60 > `(unit @tas)`(scan "sep" ;~((bend) (easy ~) sym))
70Parsing composer: connects the `++edge` `vex` with a following `++rule` `sab`,
71combining the contents of `vex` with the result of `sab` using a binary
72gate `raq`. Used to fold over the results of several `++rules`.
77`raq` is a gate that accepts a cell of two nouns, `a` and `b`, and
78produces a cell of two nouns.
94 |* raq/_|*({a/* b/*} [a b]) :: arbitrary compose
96 |* {vex/edge sab/rule}
100 =+ yit=(sab q.u.q.vex)
101 =+ yur=(last p.vex p.yit)
104 [p=yur q=[~ u=[p=(raq p.u.q.vex p.u.q.yit) q=q.u.q.yit]]]
110 > (scan "123" ;~((comp |=([a/@u b/@u] (add a b))) dit dit dit))
112 > (scan "12" ;~((comp |=([a/@u b/@u] (add a b))) dit dit dit))
121Produces an `++edge` at the same text position (`++hair`) with a failing
137 ++ fail |=(tub/nail [p=p.tub q=~]) :: never parse
142 > (fail [[1 1] "abc"])
144 > (fail [[p=1.337 q=70] "Parse me, please?"])
145 [p=[p=1.337 q=70] q=~]
154Parsing composer: connects an `++edge` `vex` with a following `++rule` `sab` by
155parsing the `++rule` `bus` (the delimiting symbol) and throwing out the
179 |* {vex/edge sab/rule}
180 (plug vex ;~(pfix bus sab))
186 > (scan "200|mal|bon" ;~((glue bar) dem sym sym))
187 [q=200 7.102.829 7.237.474]
188 > `[@u @tas @tas]`(scan "200|mal|bon" ;~((glue bar) dem sym sym))
190 > (scan "200|;|bon" ;~((glue bar) dem sem sym))
191 [q=200 ~~~3b. 7.237.474]
192 > (scan "200.;.bon" ;~((glue dot) dem sem sym))
193 [q=200 ~~~3b. 7.237.474]
202Parsing composer: if an `++edge` `vex` reflects a success, fail. Otherwise,
203connect `vex` with the following `++rule`.
220 ++ less :: no first and second
221 |* {vex/edge sab/rule}
224 [p=(last p.vex p.roq) q=q.roq]
231 > (scan "sas-/lo" (star ;~(less lus bar prn)))
233 > (scan "sas-/l+o" (star ;~(less lus bar prn)))
236 > (scan "sas|-/lo" (star ;~(less lus bar prn)))
247Parsing composer: connects an `++edge` `vex` with two subsequent `++rule`s,
248ignoring the result of the first and producing the result of the second.
263 ++ pfix :: discard first rule
265 (comp |*({a/* b/*} b))
270 > `@t`(scan "%him" ;~(pfix cen sym))
272 > (scan "+++10" ;~(pfix (star lus) dem))
282Parsing composer: connects an `++edge` `vex` with a following `++rule` `sab`, producing
283a cell of both the results. See also: the monad applicator ;\~ for a
284more detailed explanation.
301 ++ plug :: first then second
303 |* {vex/edge sab/rule}
306 =+ yit=(sab q.u.q.vex)
307 =+ yur=(last p.vex p.yit)
310 [p=yur q=[~ u=[p=[p.u.q.vex p.u.q.yit] q=q.u.q.yit]]]
316 > (scan "1..20" ;~(plug dem dot dot dem))
318 > (scan "moke/~2014.1.1" ;~(plug sym fas nuck:so))
319 [1.701.539.693 ~~~2f. [% p=[p=~.da q=170.141.184.500.766.106.671.844.917.172.921.958.400]]]
320 > ;;(,[@tas @t ~ %da @da] (scan "moke/~2014.1.1" ;~(plug sym fas nuck:so)))
321 [%moke '/' ~ %da ~2014.1.1]
330Parsing composer: if `vex` reflects a failure, connect it with the
331following rule `sab`. See also: the monad applicator ;\~
348 ++ pose :: first or second
350 |* {vex/edge sab/rule}
353 [p=(last p.vex p.roq) q=q.roq]
361 > `@t`(scan "+" ;~(pose lus tar cen))
363 > `@t`(scan "*" ;~(pose lus tar cen))
365 > `@t`(scan "%" ;~(pose lus tar cen))
367 > `@t`(scan "-" ;~(pose lus tar cen))
378Parsing composer: connects `++edge`s `vex` with two subsequent `++rule`s returning the
379result of the first and discarding the result of the second.
384`a` is the result of parsing the first `++rule`.
386`b` is the result of of parsing the second `++rule`.
396 ++ sfix :: discard second rule
398 (comp |*({a/* b/*} a))
404 > `@t`(scan "him%" ;~(sfix sym cen))
406 > (scan "10+++" ;~(sfix dem (star lus)))
416Parsing composer: if an `++edge` `vex` reflects a failure, fail. Otherwise,
417connect `vex` with the following `++rule`.
434 ++ simu :: first and second
435 |* {vex/edge sab/rule}
445 > (scan "~zod" scat:vast)
447 > (scan "%zod" scat:vast)
448 [%dtzz p=%tas q=6.582.138]
449 > (scan "%zod" ;~(simu cen scat:vast))
450 [%dtzz p=%tas q=6.582.138]
451 > (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