The bpeg Grammar¶
The bpeg grammar is modelled after Python’s own parser grammar as per PEP 617.
It provides indentation based rules, a PEG-like expression grammar,
and efficient literal declarations.
See Terminal Expressions for defining special and literal terminals.
Top-level rules¶
comment: '#' :: NEW_LINE
A line comment, discarding the entire line starting at the
#symbol.
define: name ':' NEW_LINE INDENT rule+
A named collection of ordered rules. If more than one rule matches, the uppermost matching rule is preferred.
rule: '|' e [ '{' action '}' ] NEW_LINE
A rule to match any input matching the expression
e. The optionalactiondefines how to translate the matched input.
Compound Expressions¶
sequence: e1 e2
Ordered sequence of clauses, matching
e1followed bye2.“return” expression
choice: e1 | e2
Ordered choice, matching either
e1ore2. If both match,e1is preferred.
group: ( e )
Match
e. Useful to enforce precedence.expr (‘,’ expr)*
option: [ e ]
Match
eor nothing. Always succeeds, may be zero width.[ “async” ] “def”
not: !e
Match if
edoes not match. Matches with zero width.! NEW_LINE
repeat: e+
Match
eonce or several times.‘:’ statement+
any: e*
Match
ezero or several times. Equivalent to[ e+ ].