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.
34 =+ 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]]]
55> (;~((bend |=([a=char b=char] ?.(=(a b) ~ (some +(a))))) prn prn) [1 1] "qs")
56[p=[p=1 q=3] q=[~ u=[p=113 q=[p=[p=1 q=2] q="s"]]]]
58> (;~((bend |=([a=char b=char] ?.(=(a b) ~ (some +(a))))) prn prn) [1 1] "qqq")
59[p=[p=1 q=3] q=[~ u=[p=114 q=[p=[p=1 q=3] q="q"]]]]
61> `@t`(scan "aa" ;~((bend |=([a=char b=char] ?.(=(a b) ~ (some +(a))))) prn prn))
64> (scan "ba" ;~((bend |=([a=char b=char] ?.(=(a b) ~ (some +(a))))) prn prn))
68> `(unit @tas)`(scan "" ;~((bend) (easy ~) sym))
71> `(unit @tas)`(scan "sep" ;~((bend) (easy ~) sym))
81Parsing composer: connects the `edge` `vex` with a following `rule` `sab`,
82combining the contents of `vex` with the result of `sab` using a binary
83gate `raq`. Used to fold over the results of several `rule`s.
87`raq` is a gate that accepts a cell of two nouns, `a` and `b`, and
88produces a cell of two nouns.
103 =+ raq=|*([a=* b=*] [a b])
107 |* [vex=edge sab=rule]
111 =+ yit=(sab q.u.q.vex)
112 =+ yur=(last p.vex p.yit)
115 [p=yur q=[~ u=[p=(raq p.u.q.vex p.u.q.yit) q=q.u.q.yit]]]
122> (scan "123" ;~((comp |=([a=@ud b=@ud] (add a b))) dit dit dit))
125> (scan "12" ;~((comp |=([a=@ud b=@ud] (add a b))) dit dit dit))
136Produces an `edge` at the same text position (`hair`) with a failing
150++ fail |=(tub=nail [p=p.tub q=~])
156> (fail [[1 1] "abc"])
159> (fail [[p=1.337 q=70] "Parse me, please?"])
160[p=[p=1.337 q=70] q=~]
169Parsing composer: connects an `edge` `vex` with a following `rule` `sab` by
170parsing the `rule` `bus` (the delimiting symbol) and throwing out the
192 |* [vex=edge sab=rule]
193 (plug vex ;~(pfix bus sab))
199> `[@ud @tas @tas]`(scan "200|mal|bon" ;~((glue bar) dem sym sym))
202> `[@ud @t @tas]`(scan "200|;|bon" ;~((glue bar) dem mic sym))
212Parsing composer: if an `edge` `vex` reflects a success, fail. Otherwise,
213connect `vex` with the following `rule`.
229 |* [vex=edge sab=rule]
232 [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.
275 |* sam=[vex=edge sab=rule]
277 (comp |*([a=* b=*] b))
283> `@t`(scan "%him" ;~(pfix cen sym))
286> (scan "+++10" ;~(pfix (star lus) dem))
296Parsing composer: connects an `edge` `vex` with a following `rule` `sab`,
297producing a cell of both the results. See also: the monad applicator `;~` for a
298more detailed explanation.
315 |* [vex=edge sab=rule]
318 =+ yit=(sab q.u.q.vex)
319 =+ yur=(last p.vex p.yit)
322 [p=yur q=[~ u=[p=[p.u.q.vex p.u.q.yit] q=q.u.q.yit]]]
328> (scan "1..20" ;~(plug dem dot dot dem))
338Parsing composer: if `vex` reflects a failure, connect it with the
339following rule `sab`. See also: the monad applicator `;~`
356 |* [vex=edge sab=rule]
359 [p=(last p.vex p.roq) q=q.roq]
366> `@t`(scan "+" ;~(pose lus tar cen))
369> `@t`(scan "*" ;~(pose lus tar cen))
372> `@t`(scan "%" ;~(pose lus tar cen))
375> `@t`(scan "-" ;~(pose lus tar cen))
386Parsing composer: connects `edge` `vex` with two subsequent `rule`s returning the
387result of the first and discarding the result of the second.
404 |* sam=[vex=edge sab=rule]
406 (comp |*([a=* b=*] a))
412> `@t`(scan "him%" ;~(sfix sym cen))
415> (scan "10+++" ;~(sfix dem (star lus)))
425Parsing composer: if an `edge` `vex` reflects a failure, fail. Otherwise,
426connect `vex` with the following `rule`.
442 |* [vex=edge sab=rule]
452> (scan "~zod" scat:vast)
455> (scan "%zod" scat:vast)
456[%dtzz p=%tas q=6.582.138]
458> (scan "%zod" ;~(simu cen scat:vast))
459[%dtzz p=%tas q=6.582.138]
461> (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