]> git.saurik.com Git - cycript.git/commitdiff
Move LexSetRegEx to new "post-lookahead" paradigm.
authorJay Freeman (saurik) <saurik@saurik.com>
Tue, 8 Dec 2015 05:42:09 +0000 (21:42 -0800)
committerJay Freeman (saurik) <saurik@saurik.com>
Tue, 8 Dec 2015 05:42:09 +0000 (21:42 -0800)
Driver.hpp
Parser.ypp.in
Scanner.lpp.in

index 8b53c5b4379bf69696bdcb721df7e7ec7bed8e1f..efd2bc63ec6a28db9ca7230cf1afaeb01f38a68e 100644 (file)
@@ -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);
index 92e6424311df0523d0cb96749e301891fb92f9db..853c881aa41b71a151d3ab52582c87baa0b39e20 100644 (file)
@@ -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
index 5563b067ed0725b3cf22587f7d28e7cf667e085e..677d7e91d3dd784e7037ef2321fd44f30c88b04c 100644 (file)
@@ -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 {{{ */
-<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")
@@ -388,8 +384,8 @@ XMLName {XMLNameStart}{XMLNamePart}*
 "*="   L F(tk::StarEqual, hi::Operator);
 "~"    L F(tk::Tilde, hi::Operator);
 
-<Div,DivOrTemplateTail>"/"  L F(tk::Slash, hi::Operator);
-<Div,DivOrTemplateTail>"/=" 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);
-<Div,RegExp>"}" L S(template_); F(tk::CloseBrace, hi::Structure);
+<Div>"}" 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);
-<DivOrTemplateTail,RegExpOrTemplateTail>"}" L yyextra->tail_ = true; S(template_); CYLexBufferStart(StrictAccentString);
+<DivOrTemplateTail>"}" L yyextra->tail_ = true; S(template_); CYLexBufferStart(StrictAccentString);
 
 <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<struct yyguts_t *>(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_);