From 6244bca0d4d6048c9c27e501648dbc955882d7cf Mon Sep 17 00:00:00 2001 From: "Jay Freeman (saurik)" Date: Thu, 17 Dec 2015 00:22:30 -0800 Subject: [PATCH 1/1] Use macros to simplify semantic actions for lexer. --- Parser.ypp.in | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) 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 -- 2.45.2