Reputation: 113
There's a rule about the flight no(such as:CZ3102), which has 2 chars followed by 3-4 digits. And its Regular Expression should be: [A-Z]{2}[0-9]{3,4}.
Then how to write the lexer rule under ANTLR4?
One easy lexer rule is: [A-Z][A-Z][0-9][0-9][0-9][0-9]?
But that's not so elegant, and if the range is big, such as 1-255, it's not so easy the lexer rule.
Thanks
Upvotes: 2
Views: 849
Reputation: 170308
But that's not so elegant, and if the range is big, such as 1-255, it's not so easy the lexer rule.
Tokenize just numbers, and validate the numerical value inside parser listener or visitor.
Related links:
Upvotes: 1