Lexer Rules
A lexer grammar is composed of lexer rules, optionally broken into multiple modes, as we saw in âIssuing Context-Sensitive Tokens with Lexical Modesâ. Lexical modes allow us to split a single lexer grammar into multiple sublexers. The lexer can return only those tokens matched by rules from the current mode.
Lexer rules specify token definitions and more or less follow the syntax of parser rules except that lexer rules cannot have arguments, return values, or local variables. Lexer rule names must begin with an uppercase letter, which distinguishes them from parser rule names.
â | â/** Optional document comment */â |
â | TokenName â:â alternative1 â|â â...â â|â alternativeN â;â |
You can also define rules ...
Get The Definitive ANTLR 4 Reference, 2nd Edition now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.