question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

antlr4 4.9.2 parser calls error handler for same "foobar^4" input although nothing changed in grammar.g4

See original GitHub issue

Hello,

i was thinking about posting this in discussions but since it only occurs with the latest 4.9.2 version maybe here is the correct place.

in our codebase we have the following grammar.g4 (excerpt):

PhraseLiteral
    :   '"' StringCharacters? '"'
    |   TermCharacters
    ;

fragment
StringCharacters
    :   StringCharacter+
    ;

fragment
TermCharacters
    : ~["\\ \t\r\u000C\n()^*] ~["\\ \t\r\u000C\n()^]*
    ;

we generate the needed files with:

antlr4 -Dlanguage=JavaScript /path/to/SearchGrammar2.g4

and later we use it the following (also only excerpt):

const errorHandler = new SyntaxProcessorErrorHandler();
const chars = new antlr4.InputStream(input); // input is foobar^4
const lexer = new SearchGrammar2Lexer(chars);
const tokens = new antlr4.CommonTokenStream(lexer);
const parser = new SearchGrammar2Parser(tokens);
parser.addErrorListener(errorHandler);

with version 4.9.1 we dont get an error but now with 4.9.2 we get the following error:

extraneous input '^' expecting {'^', DEC_NUMBER, PhraseLiteral}

we get the error when using the following input:

foobar^4 // maybe caret handling has been changed in 4.9.2 ?

we haven’t changed anything except updating to 4.9.2 and use JavaScript, do you have any idea what changes in 4.9.2 could cause this?

edit: another side note, which may be helpful: the generated files hasnt changed at all using 4.9.2 - the only difference is that after installing the 4.9.2 npm package we get this error, if we use the 4.9.1 npm package there is no such error

Issue Analytics

  • State:open
  • Created 2 years ago
  • Comments:13 (7 by maintainers)

github_iconTop GitHub Comments

2reactions
kaby76commented, Apr 30, 2021

@duc-talentwunder Excellent! I can reproduce the problem. Sorry for the strange reference to a similar problem. I was thinking out loud that what you are seeing is due to the same bug in the code. I will debug the JS runtime with your grammar over the weekend to verify that it is. Thanks.

1reaction
lisa-twcommented, Apr 29, 2021

Hi there. I am working with Duc and tried our grammar with Java target. I followed the instructions here and used the jars of versions 4.9.1 and 4.9.2. With both versions, the input foobar^4 does not throw an error.

Also tried it with the plugin and no error is thrown.

If I input something like ^4, an error is thrown (as expected).

It seems like this might be an issue with the npm package - or is there anything else we should do to test our grammar file?

Screenshot 2021-04-29 at 17 28 21
Read more comments on GitHub >

github_iconTop Results From Across the Web

antlr4 4.9.2 parser calls error handler for same "foobar^4" input ...
antlr4 4.9.2 parser calls error handler for same "foobar^4" input although nothing changed in grammar.g4.
Read more >
JavaScript target for grammars-v4/java/java with input HSDB.java ...
antlr4 4.9.2 parser calls error handler for same "foobar^4" input although nothing changed in grammar.g4 #3150. Open. Fix for Issue 2156 antlr/grammars-v4# ...
Read more >
Handling errors in ANTLR4 - java - Stack Overflow
This solution worked for me with one caveat - we're trying to parse using SLL and then falling back to LL, and it...
Read more >
ANTLR4 grammar syntax support - Visual Studio Marketplace
Extension for Visual Studio Code - Language support for ANTLR4 grammar files. ... Syntax coloring for ANTLR grammars (.g and .g4 files).
Read more >
Parser (ANTLR 4 Runtime 4.11.1 API) - javadoc.io
The error handling strategy for the parser. ... The same as compileParseTreePattern(String, int) but specify a Lexer rather than trying to deduce it...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found