4
votes

I'm a n00b to ANTLR and going big by trying to get an ASN.1 parser running in ANTLR4. I am presently at the stage where I'm passing in an input file to grun and seeing errors like "line 1:12029 no viable alternative at input ..."

I'm trying to relate this back to some problem with my rules but locating the offending input by character count is a challenge. Is it normal for an ANTLR parser to see the input as a single line, or am I failing to recognize EOLs because of a rule problem (I'm on an OSX system)? If it is normal to see the input as one long line, can someone recommend a tool for locating a given character position in a file?

1

1 Answers

3
votes

Does your code use only \r line endings? ANTLR 4 increments the line count and resets the char position only when a \n character is consumed. If you need to handle plain \r line endings, you'll need to override LexerATNSimulator.consume to perform this check.

Checking for the complete set of line endings is much more expensive than checking for \n alone, so since \r line endings are rare the default implementation uses \n for maximum performance.