And by string literals I mean those containing \123
-like characters too.
I've written something but I don't know if it's perfect:
<STRING> {
\" { yybegin(YYINITIAL);
return new Token(TokenType.STRING,string.toString()); }
\\[0-3][0-7][0-7] { string.append( yytext() ); }
\\[0-3][0-7] { string.append( yytext() ); }
\\[0-7] { string.append( yytext() ); }
[^\n\r\"\\]+ { string.append( yytext() ); }
\\t { string.append('\t'); }
\\n { string.append('\n'); }
\\r { string.append('\r'); }
\\\" { string.append('\"'); }
\\ { string.append('\\'); }
}
In fact, I know this isn't perfect, since for the three lines parsing \ddd
-like characters, I don't put the character itself in the string, but its representation instead.
I may try to convert it using Character methods, but then maybe I'm not exhaustive, maybe there are other escape sequences I didn't handle.... so if there is a canonical jflex file for that it would be perfect.