开发者

How to exclude more than one character in rule?

开发者 https://www.devze.com 2022-12-13 13:24 出处:网络
I\'m trying to write a string matching rule in ANTLRWorks, and I need开发者_如何学运维 to match either escaped quotes or any non quote character. I can match escaped quotes but I\'m having trouble wit

I'm trying to write a string matching rule in ANTLRWorks, and I need开发者_如何学运维 to match either escaped quotes or any non quote character. I can match escaped quotes but I'm having trouble with the other part: ~'\'' | ~'\"' will end up matching everything and ~'\'\"' seems to be ignored by the grammar generator (at least the visual display). What sequence of characters will get me what I want?


Try something like this:

StringLiteral
    :    '"' (EscapeSequence | StringChar)* '"'
    ;

EscapeSequence
    :    '\\' ('"' | '\\')
    ;

StringChar
    :    ~('"' | '\\')
    ;
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号