ANTLR 4 $channel = HIDDEN and options

此生再无相见时 提交于 2019-11-30 02:49:22

The v4 equivalent would look like:

COMMENT
    :   ( '//' ~[\r\n]* '\r'? '\n'
        | '/*' .*? '*/'
        ) -> channel(HIDDEN)
    ;

which will put all single- and multi line comment on the HIDDEN channel. However, if you're not doing anything with these HIDDEN-tokens, you could also skip these tokens, which would look like this:

COMMENT
    :   ( '//' ~[\r\n]* '\r'? '\n'
        | '/*' .*? '*/'
        ) -> skip
    ;

Note that to tell the lexer or parser to match ungreedy, you don't use options {greedy=false;} anymore, but append a ?, similar to many regex implementations.

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