ANTLR Lexer rules in v4 Implicit lexer rules


Example

When tokens like '{' are used in a parser rule, an implicit lexer rule will be created for them unless an explicit rule exists.

In other words, if you have a lexer rule:

OPEN_BRACE: '{';

Then both of these parser rules are equivalent:

parserRule: '{';
parserRule: OPEN_BRACE;

But if the OPEN_BRACE lexer rule is not defined, an implicit anonymous rule will be created. In that case, the implicit rule will be defined as if it were defined before the other rules: it will have a higher priority than other rules.