From: Jay Freeman (saurik) Date: Tue, 8 Dec 2015 05:42:09 +0000 (-0800) Subject: Move LexSetRegEx to new "post-lookahead" paradigm. X-Git-Tag: v0.9.590~236 X-Git-Url: https://git.saurik.com/cycript.git/commitdiff_plain/98711170da204fa86f2889672770c6a3feb4c4db?ds=inline Move LexSetRegEx to new "post-lookahead" paradigm. --- diff --git a/Driver.hpp b/Driver.hpp index 8b53c5b..efd2bc6 100644 --- a/Driver.hpp +++ b/Driver.hpp @@ -72,7 +72,6 @@ class _visible CYDriver { bool highlight_; enum Condition { - RegExpCondition, XMLContentCondition, XMLTagCondition, }; @@ -128,6 +127,7 @@ class _visible CYDriver { bool Parse(CYMark mark = CYMarkScript); void Replace(CYOptions &options); + void SetRegEx(bool equal); void SetCondition(Condition condition); void PushCondition(Condition condition); diff --git a/Parser.ypp.in b/Parser.ypp.in index 92e6424..853c881 100644 --- a/Parser.ypp.in +++ b/Parser.ypp.in @@ -129,9 +129,14 @@ _finline int yylex(cy::parser::semantic_type *semantic, CYLocation *location, CY return token; } +#define CYLEX() do if (yyla.empty()) { \ + YYCDEBUG << "Mapping a token: "; \ + yyla.type = yytranslate_(yylex(&yyla.value, &yyla.location, driver)); \ + YY_SYMBOL_PRINT("Next token is", yyla); \ +} while (false) + #define CYMAP(to, from) do { \ - if (yyla.empty()) \ - yyla.type = yytranslate_(yylex(&yyla.value, &yyla.location, driver)); \ + CYLEX(); \ if (yyla.type == yytranslate_(token::from)) \ yyla.type = yytranslate_(token::to); \ } while (false) @@ -649,7 +654,7 @@ LexPushYieldOff: { driver.yield_.push(false); }; LexPopYield: { driver.yield_.pop(); }; LexSetRegExp - : { driver.SetCondition(CYDriver::RegExpCondition); } + : { CYLEX(); if (yyla.type == yytranslate_(token::Slash)) { yyla.clear(); driver.SetRegEx(false); } else if (yyla.type == yytranslate_(token::SlashEqual)) { yyla.clear(); driver.SetRegEx(true); } } ; LexNewLine diff --git a/Scanner.lpp.in b/Scanner.lpp.in index 5563b06..677d7e9 100644 --- a/Scanner.lpp.in +++ b/Scanner.lpp.in @@ -266,8 +266,6 @@ XMLName {XMLNameStart}{XMLNamePart}* %s Div %s DivOrTemplateTail -%s RegExp -%s RegExpOrTemplateTail @begin E4X %x XMLContent @@ -277,8 +275,6 @@ XMLName {XMLNameStart}{XMLNamePart}* %% /* RegEx {{{ */ -\/ L CYLexBufferStart(RegularExpression); CYLexBufferUnit('/'); - { \/{UnicodePart}* R CYLexBufferUnits(yytext, yyleng); CYLexBufferEnd(literal, RegEx, tk::RegularExpressionLiteral, hi::Constant); \/{UnicodePart}*{UnicodeFail} R E("invalid flags") @@ -388,8 +384,8 @@ XMLName {XMLNameStart}{XMLNamePart}* "*=" L F(tk::StarEqual, hi::Operator); "~" L F(tk::Tilde, hi::Operator); -"/" L F(tk::Slash, hi::Operator); -"/=" L F(tk::SlashEqual, hi::Operator); +"/" L F(tk::Slash, hi::Operator); +"/=" L F(tk::SlashEqual, hi::Operator); ":" L F(tk::Colon, hi::Structure); "," L F(tk::Comma, hi::Structure); @@ -400,7 +396,7 @@ XMLName {XMLNameStart}{XMLNamePart}* ")" L F(tk::CloseParen, hi::Structure); "{" L yyextra->template_.push(false); F(yyextra->newline_ ? tk::OpenBrace_ : tk::OpenBrace, hi::Structure); -"}" L S(template_); F(tk::CloseBrace, hi::Structure); +
"}" L S(template_); F(tk::CloseBrace, hi::Structure); "[" L F(tk::OpenBracket, hi::Structure); "]" L F(tk::CloseBracket, hi::Structure); @@ -584,7 +580,7 @@ XMLName {XMLNameStart}{XMLNamePart}* /* }}} */ /* Template {{{ */ "`" L yyextra->tail_ = false; CYLexBufferStart(StrictAccentString); -"}" L yyextra->tail_ = true; S(template_); CYLexBufferStart(StrictAccentString); +"}" L yyextra->tail_ = true; S(template_); CYLexBufferStart(StrictAccentString); { "`" R CYLexBufferEnd(string, String, yyextra->tail_ ? tk::TemplateTail : tk::NoSubstitutionTemplate, hi::Constant); @@ -645,6 +641,10 @@ XMLName {XMLNameStart}{XMLNamePart}* %% +#undef yyextra +#define yyextra this +#define yyscanner scanner_ + void CYDriver::ScannerInit() { cylex_init(&scanner_); cyset_extra(this, scanner_); @@ -654,13 +654,17 @@ void CYDriver::ScannerDestroy() { cylex_destroy(scanner_); } +void CYDriver::SetRegEx(bool equal) { + CYLexBufferStart(RegularExpression); + CYLexBufferUnit('/'); + if (equal) + CYLexBufferUnit('='); +} + void CYDriver::SetCondition(Condition condition) { struct yyguts_t *yyg(reinterpret_cast(scanner_)); switch (condition) { - case RegExpCondition: - BEGIN(template_.top() ? RegExpOrTemplateTail : RegExp); - break; @begin E4X case XMLContentCondition: BEGIN(XMLContent); @@ -676,9 +680,6 @@ void CYDriver::SetCondition(Condition condition) { void CYDriver::PushCondition(Condition condition) { switch (condition) { - case RegExpCondition: - yy_push_state(RegExp, scanner_); - break; @begin E4X case XMLContentCondition: yy_push_state(XMLContent, scanner_);