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

intellij-plugin-v4 does not generate parse tree upon error recovery correctly #597

Open
hengxin opened this issue Nov 29, 2022 · 1 comment
Labels

Comments

@hengxin
Copy link

hengxin commented Nov 29, 2022

I am reading "Section 9.3: Automatic Error Recovery Strategy" of the book "The Definitive ANTLR 4 Reference" and trying the following grammar Class on the input class T { { int i; } }.

grammar Class;

prog : classDef+ ;

classDef : 'class' ID '{' member+ '}' ;

member
    :   'int' ID ';'
    |   'int' f=ID '(' ID ')' '{' stat '}'
    ;

stat:   expr ';'
    |   ID '=' expr ';'
    ;

expr:   INT 
    |   ID '(' INT ')'
    ;

INT :  [0-9]+ ;
ID  :  [a-zA-Z]+ ;
WS  :  [ \t\r\n]+ -> skip ;

The intellij-plugin-v4 (1.19.3-3) generates the following parse tree in which the extraneous { is recognized in member.
image

However, the book shows the following parse tree in which the extraneous { is recognized outside member.
image

According to the description of the error recovery strategy in the book, I am expecting the second parse tree.

@bjansen
Copy link
Collaborator

bjansen commented Mar 29, 2023

You're right, TestRig shows the same output as the book:

image

It might be caused by a different behavior between the interpreter run by the plugin and the actual generated parser. @parrt wdyt?

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