From: Jay Freeman (saurik) Date: Wed, 16 Dec 2015 13:35:27 +0000 (-0800) Subject: Move lexer hacks for \n=> and \n{ into Lex* rules. X-Git-Tag: v0.9.590~200 X-Git-Url: https://git.saurik.com/cycript.git/commitdiff_plain/12809e4cf4ce3b5ec8ae5f6086d533a980ed1d6d Move lexer hacks for \n=> and \n{ into Lex* rules. --- diff --git a/Parser.ypp.in b/Parser.ypp.in index d2d2775..b85edf6 100644 --- a/Parser.ypp.in +++ b/Parser.ypp.in @@ -152,11 +152,6 @@ _finline int yylex(cy::parser::semantic_type *semantic, CYLocation *location, CY token = tk::_yield__; break; - case tk::EqualRight: - if (driver.newline_ == CYDriver::NewLineLast) - token = tk::EqualRight_; - break; - case tk::HyphenHyphen: if (driver.newline_ == CYDriver::NewLineLast) token = tk::HyphenHyphen_; @@ -168,11 +163,6 @@ _finline int yylex(cy::parser::semantic_type *semantic, CYLocation *location, CY goto lex; break; - case tk::OpenBrace: - if (driver.newline_ == CYDriver::NewLineLast) - token = tk::OpenBrace_; - break; - case tk::PlusPlus: if (driver.newline_ == CYDriver::NewLineLast) token = tk::PlusPlus_; @@ -195,6 +185,12 @@ _finline int yylex(cy::parser::semantic_type *semantic, CYLocation *location, CY yyla.type = yytranslate_(token::to); \ } while (false) +#define CYLIN(from) do { \ + CYLEX(); \ + if (yyla.type == yytranslate_(token::from) && driver.newline_ == CYDriver::NewLineLast) \ + yyla.type = yytranslate_(token::from ## _); \ +} while (false) + #define CYERR(location, message) do { \ error(location, message); \ YYABORT; \ @@ -1146,7 +1142,7 @@ UnaryExpression_ ; UnaryExpression - : %prec "" PostfixExpression { $$ = $1; } + : %prec "" PostfixExpression LexOpenBrace { $$ = $1; } | LexSetRegExp UnaryExpression_ { $$ = $2; } ; /* }}} */ @@ -1655,8 +1651,12 @@ FunctionStatementList ; /* }}} */ /* 14.2 Arrow Function Definitions {{{ */ +LexEqualRight + : { CYLIN(EqualRight); } + ; + ArrowFunction - : LexSetRegExp ArrowParameters "=>" LexNoBrace ConciseBody { $$ = CYNew CYFatArrow($2, $5); } + : LexSetRegExp ArrowParameters LexEqualRight "=>" LexNoBrace ConciseBody { $$ = CYNew CYFatArrow($2, $6); } ; ArrowParameters @@ -2444,6 +2444,10 @@ RubyProcParametersOpt | LexSetRegExp { $$ = NULL; } ; +LexOpenBrace + : { CYLIN(OpenBrace); } + ; + RubyProcExpression : "{" RubyProcParametersOpt StatementListOpt "}" { $$ = CYNew CYRubyProc($2, $3); } ; @@ -2453,7 +2457,7 @@ PrimaryExpression ; PostfixExpression - : PostfixExpression RubyProcExpression { $$ = CYNew CYRubyBlock($1, $2); } + : PostfixExpression LexOpenBrace RubyProcExpression { $$ = CYNew CYRubyBlock($1, $3); } ; /* }}} */