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.

Was it helpful?

Solution

Just add EOF to the end of your start rule.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top