RCIX
RCIX

Reputation: 39437

How to exclude more than one character in rule?

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?

Upvotes: 0

Views: 169

Answers (1)

Bart Kiers
Bart Kiers

Reputation: 170178

Try something like this:

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

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

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

Upvotes: 1

Related Questions