Negated lexer rules/tokens

旧城冷巷雨未停 提交于 2020-05-17 08:49:28

问题


I am trying to match (and ignore) c-style block comments. To me the sequence is (1) /* followed by (2) anything other than /* or */ until (3) */.

BLOCK_COMMENT_START
    : "/*"
    ;

BLOCK_COMMENT_END
    : "*/"
    ;

BLOCK_COMMENT
    : BLOCK_COMMENT_START ( ~( BLOCK_COMMENT_START | BLOCK_COMMENT_END ) )* BLOCK_COMMENT_END {
        // again, we want to skip the entire match from the lexer stream
        $setType( Token.SKIP );
    }
    ;

But Antlr does not think like I do ;)

sql-stmt.g:121:34: This subrule cannot be inverted.  Only subrules of the form:
    (T1|T2|T3...) or
    ('c1'|'c2'|'c3'...)
may be inverted (ranges are also allowed).

So the error message is a little cryptic, but I think it is trying to say that only ranges, single-char alts or token alts can be negated. But isn't that what I have? Both BLOCK_COMMENT_START and BLOCK_COMMENT_END are tokens. What am I missing?

Thanks a lot for any help.

来源:https://stackoverflow.com/questions/61821211/negated-lexer-rules-tokens

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