]> git.saurik.com Git - cycript.git/commitdiff
Use macros to simplify semantic actions for lexer.
authorJay Freeman (saurik) <saurik@saurik.com>
Thu, 17 Dec 2015 08:22:30 +0000 (00:22 -0800)
committerJay Freeman (saurik) <saurik@saurik.com>
Thu, 17 Dec 2015 08:22:30 +0000 (00:22 -0800)
Parser.ypp.in

index befd87a2483282a5d95ea0af9ceced480cd7507b..5b0c18bbd5a8c14e46b4a8a2bd91bcf5f3cce64e 100644 (file)
@@ -181,9 +181,19 @@ _finline int yylex(cy::parser::semantic_type *semantic, CYLocation *location, CY
     YYABORT; \
 } while (false)
 
+#define CYEOK() do { \
+    yyerrok; \
+    driver.errors_.pop_back(); \
+} while (false)
+
 #define CYNOT(location) \
     CYERR(location, "unimplemented feature")
 
+#define CYMPT(location) do { \
+    if (!yyla.empty() && yyla.type_get() != yyeof_) \
+        CYERR(location, "unexpected lookahead"); \
+} while (false)
+
 }
 
 %name-prefix "cy"
@@ -708,7 +718,7 @@ LexSetRegExp
     ;
 
 LexNewLine
-    : { if (!yyla.empty() && yyla.type_get() != yyeof_) CYERR(@$, "unexpected lookahead"); driver.next_ = true; }
+    : { CYMPT(@$); driver.next_ = true; }
     ;
 
 LexNoStar
@@ -829,7 +839,7 @@ TerminatorSoft
 
 Terminator
     : ";"
-    | error { if (yyla.type_get() != yyeof_ && yyla.type != yytranslate_(token::CloseBrace) && driver.newline_ == CYDriver::NewLineNone) { CYERR(@1, "required semi-colon"); } else { yyerrok; driver.errors_.pop_back(); } } StrictSemi
+    | error { if (yyla.type_get() != yyeof_ && yyla.type != yytranslate_(token::CloseBrace) && driver.newline_ == CYDriver::NewLineNone) CYERR(@1, "required semi-colon"); else CYEOK(); } StrictSemi
     ;
 
 TerminatorOpt