From f356a43d13a15542719b3d7f912e0b441aa4c075 Mon Sep 17 00:00:00 2001 From: "Jay Freeman (saurik)" Date: Thu, 17 Dec 2015 02:06:15 -0800 Subject: [PATCH] Use syntax-directed lexing to remove LexSetRegExp. --- Parser.ypp.in | 16 ++++++++++++++-- Scanner.lpp.in | 2 +- 2 files changed, 15 insertions(+), 3 deletions(-) diff --git a/Parser.ypp.in b/Parser.ypp.in index 5b0c18b..923a01b 100644 --- a/Parser.ypp.in +++ b/Parser.ypp.in @@ -447,7 +447,7 @@ _finline int yylex(cy::parser::semantic_type *semantic, CYLocation *location, CY %token Identifier_ %token NumericLiteral %token StringLiteral -%token RegularExpressionLiteral +%token RegularExpressionLiteral_ %token NoSubstitutionTemplate %token TemplateHead @@ -570,6 +570,8 @@ _finline int yylex(cy::parser::semantic_type *semantic, CYLocation *location, CY %type PropertyDefinitionList %type PropertyDefinitionListOpt %type PropertySetParameterList +%type RegularExpressionLiteral +%type RegularExpressionSlash %type RelationalExpression %type ReturnStatement %type RubyProcExpression @@ -714,7 +716,7 @@ LexOf ; LexSetRegExp - : { CYLEX(); if (yyla.type == yytranslate_(token::Slash)) { yyla.clear(); driver.SetRegEx(false); } else if (yyla.type == yytranslate_(token::SlashEqual)) { yyla.clear(); driver.SetRegEx(true); } } LexOf + : LexOf ; LexNewLine @@ -826,6 +828,16 @@ BooleanLiteral | "false" { $$ = CYNew CYFalse(); } ; /* }}} */ +/* 11.8.5 Regular Expression Literals {{{ */ +RegularExpressionSlash + : "/" { $$ = false; } + | "/=" { $$ = true; } + ; + +RegularExpressionLiteral + : RegularExpressionSlash { CYMPT(@$); driver.SetRegEx($1); } RegularExpressionLiteral_ { $$ = $3; } + ; +/* }}} */ /* 11.9 Automatic Semicolon Insertion {{{ */ StrictSemi diff --git a/Scanner.lpp.in b/Scanner.lpp.in index 399feb8..c2aa6e4 100644 --- a/Scanner.lpp.in +++ b/Scanner.lpp.in @@ -279,7 +279,7 @@ XMLName {XMLNameStart}{XMLNamePart}* /* RegEx {{{ */ { - \/{UnicodePart}* R CYLexBufferUnits(yytext, yyleng); CYLexBufferEnd(literal, RegEx, tk::RegularExpressionLiteral, hi::Constant); + \/{UnicodePart}* R CYLexBufferUnits(yytext, yyleng); CYLexBufferEnd(literal, RegEx, tk::RegularExpressionLiteral_, hi::Constant); \/{UnicodePart}*{UnicodeError} R E("invalid character"); {RegExCharacter}+ R CYLexBufferUnits(yytext, yyleng); -- 2.49.0