on d452c09 help sign in
64 lines 1.6 kB history raw
1### `++bend`
3Conditional composer
5Parsing composer: connects the `++edge` `vex` with the subsequent `++rule` `sab`
6as an optional suffix, using gate `raq` to compose or reject its
7result. If there is no suffix, or if the suffix fails to be composed
8with the current result, the current result is produced. Used to map a
9group of rules to a specified output.
11Accepts
12-------
14`raq` is a gate.
16`sab` is a rule.
18`vex` is an edge.
20Produces
21--------
23A `++rule`.
25Source
26------
28 ++ bend :: conditional comp
29 ~/ %bend
30 |* raq/_|*({a/* b/*} [~ u=[a b]])
31 ~/ %fun
32 |* {vex/edge sab/rule}
33 ?~ q.vex
34 vex
35 =+ yit=(sab q.u.q.vex)
36 =+ yur=(last p.vex p.yit)
37 ?~ q.yit
38 [p=yur q=q.vex]
39 =+ vux=(raq p.u.q.vex p.u.q.yit)
40 ?~ vux
41 [p=yur q=q.vex]
42 [p=yur q=[~ u=[p=u.vux q=q.u.q.yit]]]
43 ::
45Examples
46--------
48 ~zod/try=> (;~((bend |=([a/char b/char] ?.(=(a b) ~ (some +(a))))) prn prn) [1 1] "qs")
49 [p=[p=1 q=3] q=[~ u=[p=~~q q=[p=[p=1 q=2] q="s"]]]]
50 ~zod/try=> (;~((bend |=([a/char b/char] ?.(=(a b) ~ (some +(a))))) prn prn) [1 1] "qqq")
51 [p=[p=1 q=3] q=[~ u=[p=~~r q=[p=[p=1 q=3] q="q"]]]]
52 ~zod/try=> (scan "aa" ;~((bend |=([a/char b/char] ?.(=(a b) ~ (some +(a))))) prn prn))
53 ~~b
54 ~zod/try=> (scan "ba" ;~((bend |=([a/char b/char] ?.(=(a b) ~ (some +(a))))) prn prn))
55 ! {1 3}
56 ! exit
57 ~zod/try=> `(unit @tas)`(scan "" ;~((bend) (easy ~) sym))
58 ~
59 ~zod/try=> `(unit @tas)`(scan "sep" ;~((bend) (easy ~) sym))
60 [~ %sep]
64***