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

ANTLR matches incomplete rule #4696

Open
diyan-gochev-at-ft-dot-com opened this issue Sep 15, 2024 · 3 comments
Open

ANTLR matches incomplete rule #4696

diyan-gochev-at-ft-dot-com opened this issue Sep 15, 2024 · 3 comments

Comments

@diyan-gochev-at-ft-dot-com

I am using ANTLR 4.13.2

functionsReturningNumerics
    : 'LENGTH' '(' stringPrimary ')'

........

passing just 'LENGTH' without parentheses, ANTLR matches the expression.
Is it an expected behaviour or it's bug?

@diyan-gochev-at-ft-dot-com diyan-gochev-at-ft-dot-com changed the title ANTLR matches ANTLR matches incomplete rule Sep 15, 2024
@kaby76
Copy link
Contributor

kaby76 commented Sep 15, 2024

It could be as designed. But, we need to actually see a minimum reproducible example (grammar and input). Check whether your start rule is a proper EOF-terminated rule. It should be.

@diyan-gochev-at-ft-dot-com
Copy link
Author

diyan-gochev-at-ft-dot-com commented Sep 18, 2024

@kaby76 Thank you for your feedback.
The case is very simple, I have 2 rules:

pathExpression
    : IDENTIFICATION_VARIABLE ('.' IDENTIFICATION_VARIABLE)*
    ;

AND

functionsReturningNumerics
    : 'LENGTH' '(' stringPrimary ')'
    | 'LOCATE' '(' ....

with options:

options { caseInsensitive = true; }

The string to parse (the subject) is the string:

 id,name,type,palletType,length,width,height

(does not contain parentheses at all).

I expect functionsReturningNumerics rule to fail to match because of the missing (but required parentheses) and continue trying to match the other rules, and eventually match "pathExpression", but instead, ANTLR logs

line 1:30 mismatched input ',' expecting '(' 

and even though the parentheses are missing, the parser successfully matches functionsReturningNumerics.
Here is the log, showing that "functionsReturningNumerics" rule succeeds:

2024-09-18T04:38:46.974+03:00  INFO 62114 --- [nio-8080-exec-2] c.etradesoft.aql.parser.AQLListenerImpl  : visitTerminal(,)
2024-09-18T04:38:46.974+03:00  INFO 62114 --- [nio-8080-exec-2] c.etradesoft.aql.parser.AQLListenerImpl  : visitTerminal(length)
2024-09-18T04:38:46.974+03:00  INFO 62114 --- [nio-8080-exec-2] c.etradesoft.aql.parser.AQLListenerImpl  : exitFunctionsReturningNumerics(length)
2024-09-18T04:38:46.974+03:00  INFO 62114 --- [nio-8080-exec-2] c.etradesoft.aql.parser.AQLListenerImpl  : exitArithmeticPrimary(length)
2024-09-18T04:38:46.974+03:00  INFO 62114 --- [nio-8080-exec-2] c.etradesoft.aql.parser.AQLListenerImpl  : exitArithmeticFactor(length)
2024-09-18T04:38:46.974+03:00  INFO 62114 --- [nio-8080-exec-2] c.etradesoft.aql.parser.AQLListenerImpl  : exitArithmeticTerm(length)
2024-09-18T04:38:46.974+03:00  INFO 62114 --- [nio-8080-exec-2] c.etradesoft.aql.parser.AQLListenerImpl  : exitSimpleArithmeticExpression(length)
2024-09-18T04:38:46.974+03:00  INFO 62114 --- [nio-8080-exec-2] c.etradesoft.aql.parser.AQLListenerImpl  : exitArithmeticExpression(length)
2024-09-18T04:38:46.974+03:00  INFO 62114 --- [nio-8080-exec-2] c.etradesoft.aql.parser.AQLListenerImpl  : exitExpression(length)
2024-09-18T04:38:46.974+03:00  INFO 62114 --- [nio-8080-exec-2] c.etradesoft.aql.parser.AQLListenerImpl  : exitSelectExpressionWithAlias(length)
2024-09-18T04:38:46.974+03:00  INFO 62114 --- [nio-8080-exec-2] c.etradesoft.aql.parser.AQLListenerImpl  : visitTerminal(,)

The problem is that functionsReturningNumerics rule succeeds without the required parentheses.

@diyan-gochev-at-ft-dot-com
Copy link
Author

diyan-gochev-at-ft-dot-com commented Sep 18, 2024

The comment has been updated, the logs provided.
Looks like a bug.

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

No branches or pull requests

2 participants