Bind ANTLR4 subrules of a rule

狂风中的少年 提交于 2019-12-08 08:01:26

Use list labels

search : K_SEARCH entity
     ( K_QUERY  q=expr )?
     ( K_FILTER f=expr )?
     ( K_SELECT1 s1+=expr ( COMMA s1+=expr )* )?
     ( K_SELECT2 s2+=expr ( COMMA s2+=expr )* )?
     ( K_SELECT3 s3+=expr ( COMMA s3+=expr )* )?
;

Antlr will generate these additional variables within the SearchContext class:

ExprContext q;
ExprContext f;
List<ExprContext> s1;
List<ExprContext> s2;
List<ExprContext> s3;

The values will be non-null iff the corresponding subterms matched.

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!