From c6beb6c5c6360468b58b3b6e8d295dc22c8bde8b Mon Sep 17 00:00:00 2001 From: Houtan Bastani <houtan@dynare.org> Date: Fri, 22 Nov 2019 13:39:37 +0100 Subject: [PATCH] macro processor: ignore `@#line` directive --- src/macro/Parser.yy | 8 +++++++- src/macro/Tokenizer.ll | 1 + 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/src/macro/Parser.yy b/src/macro/Parser.yy index b6bf3893..29090570 100644 --- a/src/macro/Parser.yy +++ b/src/macro/Parser.yy @@ -59,7 +59,7 @@ using namespace macro; %token FOR ENDFOR IF IFDEF IFNDEF ELSEIF ELSE ENDIF TRUE FALSE %token INCLUDE INCLUDEPATH DEFINE EQUAL D_ECHO ERROR %token COMMA LPAREN RPAREN LBRACKET RBRACKET WHEN -%token BEGIN_EVAL END_EVAL ECHOMACROVARS SAVE +%token BEGIN_EVAL END_EVAL ECHOMACROVARS SAVE LINE %token EXP LOG LN LOG10 SIN COS TAN ASIN ACOS ATAN %token SQRT CBRT SIGN MAX MIN FLOOR CEIL TRUNC SUM MOD @@ -145,6 +145,12 @@ directive_one_line : INCLUDE expr { $$ = make_shared<EchoMacroVars>(true, driver.env, @$); } | ECHOMACROVARS LPAREN SAVE RPAREN name_list { $$ = make_shared<EchoMacroVars>(true, $5, driver.env, @$); } + | LINE QUOTED_STRING NUMBER + { + // `@#line` is ignored; adjust newlines in output to accord + auto l = static_cast<Tokenizer::parser::location_type>(@$); + $$ = make_shared<TextNode>(string(l.end.line - l.begin.line + 1, '\n'), driver.env, @$); + } ; name_list : NAME diff --git a/src/macro/Tokenizer.ll b/src/macro/Tokenizer.ll index e93b4f79..4d646878 100644 --- a/src/macro/Tokenizer.ll +++ b/src/macro/Tokenizer.ll @@ -64,6 +64,7 @@ CONT \\\\{SPC}* yylloc->step(); %} +<directive>line { BEGIN(expr); return token::LINE; } <directive>include { BEGIN(expr); return token::INCLUDE; } <directive>includepath { BEGIN(expr); return token::INCLUDEPATH; } <directive>define { BEGIN(expr); return token::DEFINE; } -- GitLab