-<RegExp,RegExpOrTemplateTail>{
- \/{RegularExpressionBody}\/{RegularExpressionFlags} L I(literal, RegEx(Y), tk::RegularExpressionLiteral, hi::Constant);
- \/{RegularExpressionBody}\/{RegularExpressionFlags}{UnicodeFail} L E("invalid flags")
- \/{RegularExpressionBody}?\\? L E("unterminated regex")
+<RegExp,RegExpOrTemplateTail>\/ L CYLexBufferStart(RegularExpression); CYLexBufferUnit('/');
+
+<RegularExpression>{
+ \/{UnicodePart}* R CYLexBufferUnits(yytext, yyleng); CYLexBufferEnd(literal, RegEx, tk::RegularExpressionLiteral, hi::Constant);
+ \/{UnicodePart}*{UnicodeFail} R E("invalid flags")
+
+ {RegExCharacter}+ R CYLexBufferUnits(yytext, yyleng);
+ {RegExCharacter}*{UnicodeFail} R E("invalid character");
+
+ {RegularExpressionBackslashSequence} R CYLexBufferUnits(yytext, yyleng);
+ \\{UnicodeFail}? R E("invalid escape")
+
+ "["{RegularExpressionClassChars}"]" R CYLexBufferUnits(yytext, yyleng);
+ "["{RegularExpressionClassChars}\\? R E("invalid class");
+ "["{RegularExpressionClassChars}\\?{UnicodeFail} R E("invalid character");
+ "["{RegularExpressionClassChars}\\?{LineTerminatorSequence} R E("invalid newline");
+
+ (\\|{RegExCharacter}+)?{LineTerminatorSequence} R E("invalid newline");
+ <<EOF>> R E("unterminated regex")