Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Grammar rule matching even though it shouldn't #340

Open
tobbi opened this issue Oct 24, 2019 · 1 comment
Open

Grammar rule matching even though it shouldn't #340

tobbi opened this issue Oct 24, 2019 · 1 comment
Labels

Comments

@tobbi
Copy link

tobbi commented Oct 24, 2019

I have specified the following grammar:
https://pastebin.com/mzwv0czc

I'm testing it out with the following C# code:

var stream = new AntlrInputStream(plausiregel);
var lexer = new plausiregelGrammarLexer(stream);
var tokens = new CommonTokenStream(lexer);
var parser = new plausiregelGrammarParser(tokens);
var ctx = parser.plausiregel();
var eof = ctx.Eof();

The input is as follows:
G:238859 == G:238859 > 100

Because I specified a mandatory EOF token after the formel rule, the plausiregel formula should be null because the input string does not match due to trailing garbage after the formel rule. However, only the EOF token is null.

Am I incorrect with my assessment?

@sharwell
Copy link
Member

sharwell commented Oct 24, 2019

Parser rules do not always return null if an error occurred (it attempts to recover from errors). There should be a property of ctx you can check to see if an error occurred. There are other options as well:

  • You can register an error listener and use that to verify that no errors were reported, while still allowing recovery
  • You can use BailErrorListener to throw an exception if an error occurs

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants