6# 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.
34 ++ bend :: conditional comp
36 |* raq/_|*({a/* b/*} [~ u=[a b]])
38 |* {vex/edge sab/rule}
41 =+ yit=(sab q.u.q.vex)
42 =+ yur=(last p.vex p.yit)
45 =+ vux=(raq p.u.q.vex p.u.q.yit)
48 [p=yur q=[~ u=[p=u.vux q=q.u.q.yit]]]
54 > (;~((bend |=([a/char b/char] ?.(=(a b) ~ (some +(a))))) prn prn) [1 1] "qs")
55 [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"]]]]
58 > (scan "aa" ;~((bend |=([a/char b/char] ?.(=(a b) ~ (some +(a))))) prn prn))
60 > (scan "ba" ;~((bend |=([a/char b/char] ?.(=(a b) ~ (some +(a))))) prn prn))
63 > `(unit @tas)`(scan "" ;~((bend) (easy ~) sym))
65 > `(unit @tas)`(scan "sep" ;~((bend) (easy ~) sym))
75Parsing composer: connects the `++edge` `vex` with a following `++rule` `sab`,
76combining the contents of `vex` with the result of `sab` using a binary
77gate `raq`. Used to fold over the results of several `++rules`.
82`raq` is a gate that accepts a cell of two nouns, `a` and `b`, and
83produces a cell of two nouns.
99 |* raq/_|*({a/* b/*} [a b]) :: arbitrary compose
101 |* {vex/edge sab/rule}
105 =+ yit=(sab q.u.q.vex)
106 =+ yur=(last p.vex p.yit)
109 [p=yur q=[~ u=[p=(raq p.u.q.vex p.u.q.yit) q=q.u.q.yit]]]
115 > (scan "123" ;~((comp |=([a/@u b/@u] (add a b))) dit dit dit))
117 > (scan "12" ;~((comp |=([a/@u b/@u] (add a b))) dit dit dit))
126Produces an `++edge` at the same text position (`++hair`) with a failing
142 ++ fail |=(tub/nail [p=p.tub q=~]) :: never parse
147 > (fail [[1 1] "abc"])
149 > (fail [[p=1.337 q=70] "Parse me, please?"])
150 [p=[p=1.337 q=70] q=~]
159Parsing composer: connects an `++edge` `vex` with a following `++rule` `sab` by
160parsing the `++rule` `bus` (the delimiting symbol) and throwing out the
184 |* {vex/edge sab/rule}
185 (plug vex ;~(pfix bus sab))
191 > (scan "200|mal|bon" ;~((glue bar) dem sym sym))
192 [q=200 7.102.829 7.237.474]
193 > `[@u @tas @tas]`(scan "200|mal|bon" ;~((glue bar) dem sym sym))
195 > (scan "200|;|bon" ;~((glue bar) dem sem sym))
196 [q=200 ~~~3b. 7.237.474]
197 > (scan "200.;.bon" ;~((glue dot) dem sem sym))
198 [q=200 ~~~3b. 7.237.474]
207Parsing composer: if an `++edge` `vex` reflects a success, fail. Otherwise,
208connect `vex` with the following `++rule`.
225 ++ less :: no first and second
226 |* {vex/edge sab/rule}
229 [p=(last p.vex p.roq) q=q.roq]
236 > (scan "sas-/lo" (star ;~(less lus bar prn)))
238 > (scan "sas-/l+o" (star ;~(less lus bar prn)))
241 > (scan "sas|-/lo" (star ;~(less lus bar prn)))
252Parsing composer: connects an `++edge` `vex` with two subsequent `++rule`s,
253ignoring the result of the first and producing the result of the second.
268 ++ pfix :: discard first rule
270 (comp |*({a/* b/*} b))
275 > `@t`(scan "%him" ;~(pfix cen sym))
277 > (scan "+++10" ;~(pfix (star lus) dem))
287Parsing composer: connects an `++edge` `vex` with a following `++rule` `sab`, producing
288a cell of both the results. See also: the monad applicator ;\~ for a
289more detailed explanation.
306 ++ plug :: first then second
308 |* {vex/edge sab/rule}
311 =+ yit=(sab q.u.q.vex)
312 =+ yur=(last p.vex p.yit)
315 [p=yur q=[~ u=[p=[p.u.q.vex p.u.q.yit] q=q.u.q.yit]]]
321 > (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]]]
325 > ;;(,[@tas @t ~ %da @da] (scan "moke/~2014.1.1" ;~(plug sym fas nuck:so)))
326 [%moke '/' ~ %da ~2014.1.1]
335Parsing composer: if `vex` reflects a failure, connect it with the
336following rule `sab`. See also: the monad applicator ;\~
353 ++ pose :: first or second
355 |* {vex/edge sab/rule}
358 [p=(last p.vex p.roq) q=q.roq]
366 > `@t`(scan "+" ;~(pose lus tar cen))
368 > `@t`(scan "*" ;~(pose lus tar cen))
370 > `@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.
389`a` is the result of parsing the first `++rule`.
391`b` is the result of of parsing the second `++rule`.
401 ++ sfix :: discard second rule
403 (comp |*({a/* b/*} a))
409 > `@t`(scan "him%" ;~(sfix sym cen))
411 > (scan "10+++" ;~(sfix dem (star lus)))
421Parsing composer: if an `++edge` `vex` reflects a failure, fail. Otherwise,
422connect `vex` with the following `++rule`.
439 ++ simu :: first and second
440 |* {vex/edge sab/rule}
450 > (scan "~zod" scat:vast)
452 > (scan "%zod" scat:vast)
453 [%dtzz p=%tas q=6.582.138]
454 > (scan "%zod" ;~(simu cen scat:vast))
455 [%dtzz p=%tas q=6.582.138]
456 > (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