Inside parser rules, the ~
does not negate characters, but tokens. So ~('\r\n')
would match any token other than the literal '\r\n'
token (in your example, that would be a NUMBER
or EXCLAMATION
).
The lexer cannot be "driven" by the parser: after the parser matched a NUMBER
and a EXCLAMATION
, you can't tell the lexer to produce some other tokens than it has previously done. The lexer will always produce tokens based on some simple rules, regardless of what the parser "needs".
In other words: you can't handle this in the parser.