Debugging ANTLR4 Grammar

I am n00b for ANTLR and am doing great trying to get an ASN.1 parser working in ANTLR4. I am now at the stage where I am transferring the input file to be in time and seeing errors such as "line 1: 12029 there is no viable alternative when entering ..."

I'm trying to connect this with some kind of problem with my rules, but finding offensive input by number of characters is a problem. Is it normal for the ANTLR analyzer to see the input as a single line, or can I not recognize the EOL due to a problem with the rule (I am on the OSX system)? If it’s normal to see the input as a single long line, can someone recommend a tool for determining the given position of a character in a file?

+4
source share
1 answer

Does your code only use line endings \r ? ANTLR 4 increases the number of lines and resets the char position only when using the \n character. If you need to handle simple \r strings, you need to override LexerATNSimulator.consume to perform this check.

Checking the complete set of lines is much more expensive than checking only on \n , since line endings \r are rare, \n used for the default implementation.

+3
source

All Articles