Just add EOF to the end of your start rule.
How to define an "everything else" parser rule to catch illegal extra
-
16-07-2023 - |
Question
So I have my parser up and running. It works great. Now I find that, it parses only the "legal" part of the file and totally ignores the illegal extra.
Here is an example:
grammar myrule;
myrule: a_rule+;
a_rule: Open_Brace Lower_Case_Char+ Close_Brace;
Open_Brace: '{';
Lower_Case_Char: 'a'..'z';
Close_Brace: '}';
when I feed it with "{ abc }", it parses great as expected.
But when I feed with "{ abc } extra extra", it happily ends without reporting the illegal part, "extra extra".
How to catch the illegal part?
I am using ANTLR v3.4.
Solution
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow