ANTLR how to detect garbage data at the end of input

When using grammars written in ANTLR, the parser correctly recognizes data from the input stream, but if I have garbage text at the end of the input (which should not be parsed by the grammar), the parser does not complain.

I assume this behavior is fine (I mean the parser did its job and parsed everything I said it should parse), but is there any trick to detect when there are any data left at the input after the parser has completed the work?

Thanks.

+4
source share
1 answer

As Scott has already answered the ANTLR mailing list:

Hello,

When using grammars written in ANTLR, the parser correctly recognizes data from the input stream, but if I have garbage text at the end of the input (garbage text should not be analyzed by the grammar), the parser does not complain.

I assume this is all right (I mean the parser did its job and parsed no matter what I said, it should parse), but is there any trick to detect when any data left on after the parser has completed its work?

Thanks Gaby.

Add an EOF token at the end of your launch rule

- Scott

+4
source

Source: https://habr.com/ru/post/1299551/


All Articles