Antlr4 如何让组件在缺少令牌时停止

Antrl4 how to make the component stop at missing token

我有一个 java 项目,使用我自己的语法,为它制作一个编译器:

page p1
{
        //some code

}
Controller c1 controls p1
{
       //some code
}

page p2
{
       //some code
}

现在,如果我删除右花括号,它会给我一个错误,并继续识别并将第二页的右花括号识别为第一页,这会导致我以后出现很多问题 我的解析器:

component :   page  controller*;
page : PAGE PAGE_ID PAGE_OPEN page_body PAGE_CLOSE;
controller : CONTROLLER  CONTROLLER_ID CNTRLS  CONTROLLER_ID CONTROLLER_OPEN controller_body CONTROLLER_CLOSE ;

词法分析器:

mode Page;
PAGE_WS : WS ->skip;
PAGE_ID : ID;
PAGE_SPACE : WS -> skip;
PAGE_OPEN: OPEN_BRACKETS ->pushMode(PageBody);

mode PageBody;
PAGE_BODY_SPACE : WS -> skip;
PAGE_SC: SEMICOLON;
EQ : EQUALS;
...
PAGE_CLOSE: CLOSE_BRACKETS -> popMode,popMode;

错误看起来像:

line 7:0 token recognition error at: 'C'
line 7:1 token recognition error at: 'o'
line 7:2 token recognition error at: 'n'
line 7:3 token recognition error at: 't'
line 7:4 token recognition error at: 'r'
line 7:5 token recognition error at: 'o'
line 7:6 token recognition error at: 'l'
line 7:7 token recognition error at: 'l'
line 7:8 token recognition error at: 'e'
line 7:9 token recognition error at: 'r'
line 7:11 token recognition error at: 'c1'
line 7:14 token recognition error at: 'co'
line 7:16 token recognition error at: 'n'
line 7:17 token recognition error at: 't'
line 7:18 token recognition error at: 'r'
line 7:19 token recognition error at: 'o'
line 7:20 token recognition error at: 'l'
line 7:21 token recognition error at: 's '
line 7:23 token recognition error at: 'p1'
line 8:0 token recognition error at: '{'

请帮忙:)

将此添加到 pagebody 得到了我想要的东西:

OTHERS
 : .*? -> popMode,popMode,channel(HIDDEN)
 ;

干杯:)