From: Jay Freeman (saurik) Date: Thu, 17 Dec 2015 08:22:30 +0000 (-0800) Subject: Use macros to simplify semantic actions for lexer. X-Git-Tag: v0.9.590~194 X-Git-Url: https://git.saurik.com/cycript.git/commitdiff_plain/6244bca0d4d6048c9c27e501648dbc955882d7cf?ds=sidebyside;hp=b41e4739f5df2002322dcc5695c8c5c431c63667 Use macros to simplify semantic actions for lexer. --- diff --git a/Parser.ypp.in b/Parser.ypp.in index befd87a..5b0c18b 100644 --- a/Parser.ypp.in +++ b/Parser.ypp.in @@ -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