move to a new state after cosuming tokens in antlr

2019-07-30 08:40发布

问题:

i have following grammar

root
    : sql_statements EOF | EOF
   ;

sql_statements
    :( sql_statement )+
   ;

sql_statement
    : ddl_statement semicolon
   ;

ddl_statement
    : alter_statement
   ;

This is a initial snapshot of my grammar i have following test case

aleter table user;alter table group_user;

first statement has error hence i am getting error for both statements under sql_statements rule

Failed to parse at line 1:1 due to mismatched input 'aleter' expecting ALTER

Now i want to use Defaulterrorhandler functionality to skip first statement till semicolon. Then it should start from second statement starting with rule sql_statements.

Question :
How to tell which rule to start after consuming error tokens ?
Thanks in advance.