I have an ANTLR JavaScript grammar (taken from the Internet), which seem to support everything except for regex literals.
The problem with a regex literal is that you have two rules, essentially:
multiplicativeExpression
: unaryExpression (LT!* ('*' | '/' | '%')^ LT!* unaryExpression)*
and
regexLiteral
: '/' RegexLiteralChar* '/'
where the rule RegexLiteralChar uses different lexer rules than a normal expression (eg. a double quote does not terminate it).
This means that I need to, in some way, change some kind of lexer state from my parser. How can I do this? Is it even possible?
Looking at the grammar mentioned in the comment by Bart Kiers here, you can see this comment,
The areRegularExpressionsEnabled() function is defined as,
And then the function is used in the RegularExpressionLiteral expression,