4e: Parsing (Combinators)
+bend
+bendConditional composer.
Parsing composer: connects the $edge .vex with the subsequent $rule .sab as an optional suffix, using gate .raq to compose or reject its result. If there is no suffix, or if the suffix fails to be composed with the current result, the current result is produced. Used to map a group of $rules to a specified output.
Accepts
.raq is a gate.
.sab is a rule.
.vex is an edge.
Produces
A $rule.
Source
++ bend
~/ %bend
=+ raq=|*([a=* b=*] [~ u=[a b]])
|@
++ $
~/ %fun
|* [vex=edge sab=rule]
?~ q.vex
vex
=+ yit=(sab q.u.q.vex)
=+ yur=(last p.vex p.yit)
?~ q.yit
[p=yur q=q.vex]
=+ vux=(raq p.u.q.vex p.u.q.yit)
?~ vux
[p=yur q=q.vex]
[p=yur q=[~ u=[p=u.vux q=q.u.q.yit]]]
--Examples
+comp
+compArbitrary compose.
Parsing composer: connects the $edge .vex with a following $rule .sab, combining the contents of .vex with the result of .sab using a binary gate .raq. Used to fold over the results of several $rules.
Accepts
.raq is a gate that accepts a cell of two $nouns, .a and .b, and produces a cell of two $nouns.
.vex is an edge.
.sab is a rule.
Produces
A $rule.
Source
Examples
+fail
+failNever parse.
Produces an $edge at the same text position ($hair) with a failing result (q=~).
Accepts
.tub is a $nail.
Produces
An $edge.
Source
Examples
+glue
+glueSkip delimiter.
Parsing composer: connects an $edge .vex with a following $rule .sab by parsing the $rule .bus (the delimiting symbol) and throwing out the result.
Accepts
.bus is a $rule.
.vex is an $edge.
.sab is a $rule.
Produces
A $rule.
Source
Examples
+less
+lessParse unless.
Parsing composer: if an $edge .vex reflects a success, fail. Otherwise, connect .vex with the following $rule.
Accepts
.vex is an $edge.
.sab is a $rule.
Produces
An $edge.
Source
Examples
+pfix
+pfixDiscard first rule.
Parsing composer: connects an $edge .vex with two subsequent $rules, ignoring the result of the first and producing the result of the second.
Accepts
.vex is an $edge.
.sab is a $rule.
Produces
An $edge.
Source
Examples
+plug
+plugParse to tuple.
Parsing composer: connects an $edge .vex with a following $rule .sab, producing a cell of both the results. See also: the monad applicator ;~ for a more detailed explanation.
Accepts
.vex is an $edge.
.sab is a $rule.
Produces
An $edge.
Source
Examples
+pose
+poseParse options.
Parsing composer: if .vex reflects a failure, connect it with the following $rule .sab. See also: the monad applicator ;~
Accepts
.vex is an $edge.
.sab is a $rule.
Produces
An $edge.
Source
Examples
+sfix
+sfixDiscard second rule.
Parsing composer: connects $edge .vex with two subsequent $rules returning the result of the first and discarding the result of the second.
Accepts
.vex is an $edge.
.sab is a $rule.
Produces
An $edge.
Source
Examples
+simu
+simuFirst and second.
Parsing composer: if an $edge .vex reflects a failure, fail. Otherwise, connect .vex with the following $rule.
Accepts
.vex is an $edge.
.sab is a $rule.
Produces
An $edge.
Source
Examples
Last updated