If you need to lex re'd as STRING_LITERAL token then use the following rule
TOKEN : { < SINGLE_QUOTE : "'" > }
TOKEN : { < STRING_LITERAL : "'"? (~["\n","\r"])* "'"?>
I didn't see the rule for matching "re" separately.
In javacc, definition of your lexical specification STRING_LITERAL
is to start with "'"
single quot. But your input doesn't have the "'"
at starting.
The "?"
added in the STRING_LITERAL
makes the single quot optional and if present only one. so this will match your input and lex as STRING_LITERAL
.
JavaCC decision making rules:
1.) JavaCC will looks for the longest match.
Here in this case even if the input starts with the "'"
the possible matches are SINGLE_QUOTE
and STRING_LITERAL
. the second input character tells which token to choose STRING_LITERAL.
2.) JavaCC takes the the rule declared first in the grammar.
Here if the input is only "'"
then it will be lexed as SINGLE_QUOTE
even if there is the possible two matches SINGLE_QUOTE
and STRING_LITERAL
.
Hope this will help you...