I am working on an Antlr grammar in which single quotes are used both as operators and in string literals, something like:
operand: DIGIT | STRINGLIT | reference;
expression: operand SQUOTE;
STRINGLIT: '\'' ~('\\'|'\'')* '\'';
Expressions like 1'
parse correctly, but when there is input that matches ~('\\'|'\'')*
after the quote, such as 1'+2
, the lexer attempts to match STRINGLIT
and fails. I'd like to be able to recover and emit SQUOTE
. Any ideas how to accomplish it?
Thanks.