This page lists common rule expression in order to describe the structure of the parsed document.
A rule expression is a pattern expression that produces a boolean and are therefore predicate.
To see how this expressions are translated into code, see the grammar to code page
They are written in Basic PEG / BNF syntax
Note that EBNF quantifier like (…)?, (…)* and (…)+ are greedy
rule ::= part1 part2 part3
rule ::= part1 part2 part3
Ordered choice (also known as alternative) is expressed with the or logical matcher (ie |)
rule : (x|y|z)
/* example */
returnType : (type | 'void') ;
Rule := ( part1 | part2 | part3 );
Rule := ( part1 | part2 | part3 );
With the * quantifier (ie Match an alternative within subrule zero or more times. )
( part ) *
( part ) *
word : letter letter*
(part1 | part 2 | part 3)*
rule := letter (letter)*
With the + quantifier (ie Match an alternative within subrule zero or more times )
( oneormore )+
( oneormore )+
annotations : (annotation)+ ;
Match part1 or nothing. This is the ? greedy quantifier (ie o or 1)
part1?
part1?
(part1)?
rule_B ::= [ optional_token ] and_another_one?
<opt-whitespace> ::= " " <opt-whitespace> | ""
Here’s another antlr rule with an empty alternative that makes the entire rule optional:
superClass
: 'extends' ID
| // empty means other alternative(s) are optional
;
rule_C := &required
rule_C := &required
rule_C ::= !forbidden
rule_recover ::= !(';' | id '=')
rule_D ::= { can_use_braces + (and_parens) * }
rule_D ::= { can_use_braces + (and_parens) * }
With the + quantifier
letter+
letter+