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?
views:
39answers:
1
+1
A:
Try something like this:
StringLiteral
: '"' (EscapeSequence | StringChar)* '"'
;
EscapeSequence
: '\\' ('"' | '\\')
;
StringChar
: ~('"' | '\\')
;
Bart Kiers
2009-12-10 10:11:54
I ended up going with a non-greedy anychar consumption, but this ought to do nicely to answer the question.
RCIX
2009-12-10 21:20:52