You will never, ever be able to write a lexeme / token definition (a
regular expression) to recognize the syntax of regular expressions.
Parsing regular expressions requires a push-down automata, owing to the
balanced, nestable constructs such as parentheses and (in certain
dialects) character classes and its use of infix operators (i.e.,
alternation).
I know. I don't want to parse RE with lexer (tokens). It would be enough for me to just represent RE as token.
It could almost be done with this simple definition:
< REGEX_LITERAL:
"/"
( (~["/","\n","\r"]) | ("\\" "/")
)*
"/"
>
And the problem is not with RE syntax. But with math expression. Because now int this expression:
my_variable = 2/3/4;
I'll get REGEX_LITERAL token.
But Tom Copeland helped me with this problem by sending me ECMAScript grammar. It looks that the problem is solved there on the parser level.
Thank you all for help :-)
Krzysztof