2title = "4e: Parsing (Combinators)"
10Parsing composer: connects the `++edge` `vex` with the subsequent `++rule` `sab`
11as an optional suffix, using gate `raq` to compose or reject its
12result. If there is no suffix, or if the suffix fails to be composed
13with the current result, the current result is produced. Used to map a
14group of rules to a specified output.
31 ++ bend :: conditional comp
33 |* raq/_|*({a/* b/*} [~ u=[a b]])
35 |* {vex/edge sab/rule}
38 =+ yit=(sab q.u.q.vex)
39 =+ yur=(last p.vex p.yit)
42 =+ vux=(raq p.u.q.vex p.u.q.yit)
45 [p=yur q=[~ u=[p=u.vux q=q.u.q.yit]]]
52 > (;~((bend |=([a/char b/char] ?.(=(a b) ~ (some +(a))))) prn prn) [1 1] "qs")
53 [p=[p=1 q=3] q=[~ u=[p=~~q q=[p=[p=1 q=2] q="s"]]]]
55 > (;~((bend |=([a/char b/char] ?.(=(a b) ~ (some +(a))))) prn prn) [1 1] "qqq")
56 [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))
61 > (scan "ba" ;~((bend |=([a/char b/char] ?.(=(a b) ~ (some +(a))))) prn prn))
65 > `(unit @tas)`(scan "" ;~((bend) (easy ~) sym))
68 > `(unit @tas)`(scan "sep" ;~((bend) (easy ~) sym))
78Parsing composer: connects the `++edge` `vex` with a following `++rule` `sab`,
79combining the contents of `vex` with the result of `sab` using a binary
80gate `raq`. Used to fold over the results of several `++rules`.
84`raq` is a gate that accepts a cell of two nouns, `a` and `b`, and
85produces a cell of two nouns.
100 |* raq/_|*({a/* b/*} [a b]) :: arbitrary compose
102 |* {vex/edge sab/rule}
106 =+ yit=(sab q.u.q.vex)
107 =+ yur=(last p.vex p.yit)
110 [p=yur q=[~ u=[p=(raq p.u.q.vex p.u.q.yit) q=q.u.q.yit]]]
117 > (scan "123" ;~((comp |=([a/@u b/@u] (add a b))) dit dit dit))
119 > (scan "12" ;~((comp |=([a/@u b/@u] (add a b))) dit dit dit))
129Produces an `++edge` at the same text position (`++hair`) with a failing
143 ++ fail |=(tub/nail [p=p.tub q=~]) :: never parse
149 > (fail [[1 1] "abc"])
152 > (fail [[p=1.337 q=70] "Parse me, please?"])
153 [p=[p=1.337 q=70] q=~]
162Parsing composer: connects an `++edge` `vex` with a following `++rule` `sab` by
163parsing 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]
211Parsing composer: if an `++edge` `vex` reflects a success, fail. Otherwise,
212connect `vex` with the following `++rule`.
227 ++ less :: no first and second
228 |* {vex/edge sab/rule}
231 [p=(last p.vex p.roq) q=q.roq]
239 > (scan "sas-/lo" (star ;~(less lus bar prn)))
242 > (scan "sas-/l+o" (star ;~(less lus bar prn)))
246 > (scan "sas|-/lo" (star ;~(less lus bar prn)))
257Parsing composer: connects an `++edge` `vex` with two subsequent `++rule`s,
258ignoring the result of the first and producing the result of the second.
271 ++ pfix :: discard first rule
273 (comp |*({a/* b/*} b))
279 > `@t`(scan "%him" ;~(pfix cen sym))
282 > (scan "+++10" ;~(pfix (star lus) dem))
292Parsing composer: connects an `++edge` `vex` with a following `++rule` `sab`, producing
293a cell of both the results. See also: the monad applicator ;\~ for a
294more detailed explanation.
309 ++ plug :: first then second
311 |* {vex/edge sab/rule}
314 =+ yit=(sab q.u.q.vex)
315 =+ yur=(last p.vex p.yit)
318 [p=yur q=[~ u=[p=[p.u.q.vex p.u.q.yit] q=q.u.q.yit]]]
325 > (scan "1..20" ;~(plug dem dot dot dem))
328 > (scan "moke/~2014.1.1" ;~(plug sym fas nuck:so))
329 [1.701.539.693 ~~~2f. [% p=[p=~.da q=170.141.184.500.766.106.671.844.917.172.921.958.400]]]
331 > ;;(,[@tas @t ~ %da @da] (scan "moke/~2014.1.1" ;~(plug sym fas nuck:so)))
332 [%moke '/' ~ %da ~2014.1.1]
341Parsing composer: if `vex` reflects a failure, connect it with the
342following rule `sab`. See also: the monad applicator ;\~
357 ++ pose :: first or second
359 |* {vex/edge sab/rule}
362 [p=(last p.vex p.roq) q=q.roq]
370 > `@t`(scan "+" ;~(pose lus tar cen))
373 > `@t`(scan "*" ;~(pose lus tar cen))
376 > `@t`(scan "%" ;~(pose lus tar cen))
379 > `@t`(scan "-" ;~(pose lus tar cen))
390Parsing composer: connects `++edge`s `vex` with two subsequent `++rule`s returning the
391result of the first and discarding the result of the second.
395`a` is the result of parsing the first `++rule`.
397`b` is the result of of parsing the second `++rule`.
406 ++ sfix :: discard second rule
408 (comp |*({a/* b/*} a))
414 > `@t`(scan "him%" ;~(sfix sym cen))
417 > (scan "10+++" ;~(sfix dem (star lus)))
427Parsing composer: if an `++edge` `vex` reflects a failure, fail. Otherwise,
428connect `vex` with the following `++rule`.
443 ++ simu :: first and second
444 |* {vex/edge sab/rule}
455 > (scan "~zod" scat:vast)
458 > (scan "%zod" scat:vast)
459 [%dtzz p=%tas q=6.582.138]
461 > (scan "%zod" ;~(simu cen scat:vast))
462 [%dtzz p=%tas q=6.582.138]
464 > (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