Ambiguous call expression in ANTLR4 grammar

被刻印的时光 ゝ 提交于 2019-11-28 14:32:00

The solution to this is to temporary "unhide" whitespace in your second alternative. Have a look at this question for how this can be done.

With that solution your code could look somthing like this

expression
    :   Identifier
    |   {enableWS();} expression '(' {disableWS();} expression? ')'
    |   '(' expression ')'
    ;

That way the second alternative matches the input WS-sensitive and will therefore only be matched if the identifier is directly followed by the bracket.

See here for the implementation of the MultiChannelTokenStream that is mentioned in the linked question.

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