EBNF Semantic Action
EBNF

Prev:EBNF Action
Next:EBNF Variable


Semantic actions allow providing a quotation that gets run on the AST of a matched rule that returns success or failure. The result of the parse is decided by the result of the semantic action. The stack effect for the quotation is ( ast -- ? ). A semantic action follows the rule it applies to and is delimited by '?[' and ']?'.

Examples
USING: prettyprint peg.ebnf math math.parser ; "1" EBNF[[ rule=[0-9] ?[ digit> odd? ]? ]] .
49

USING: prettyprint peg.ebnf math math.parser ; "2" EBNF[[ rule=[0-9] ?[ digit> odd? ]? ]] .
Peg parsing error at character position 0. Expected Got '2'