From 72effd0156ed738ad82abf1c2f03741894b74f3a Mon Sep 17 00:00:00 2001 From: Houtan Bastani Date: Mon, 21 Oct 2013 17:44:57 +0200 Subject: [PATCH] macroprocessor: copy anything within "dates()" straight to preprocessing stage --- macro/MacroDriver.hh | 2 ++ macro/MacroFlex.ll | 18 ++++++++++++------ 2 files changed, 14 insertions(+), 6 deletions(-) diff --git a/macro/MacroDriver.hh b/macro/MacroDriver.hh index 0945a329..0ae177ff 100644 --- a/macro/MacroDriver.hh +++ b/macro/MacroDriver.hh @@ -86,6 +86,8 @@ private: //! If current context is the body of a loop, contains the location of the beginning of the body Macro::parser::location_type for_body_loc; + //! Temporary variable used for counting parens in dates statement + int dates_parens_nb; //! Temporary variable used in FOR_BODY mode string for_body_tmp; //! Temporary variable used in FOR_BODY mode diff --git a/macro/MacroFlex.ll b/macro/MacroFlex.ll index 09c04da0..dc8fe29b 100644 --- a/macro/MacroFlex.ll +++ b/macro/MacroFlex.ll @@ -51,8 +51,7 @@ typedef Macro::parser::token token; %x FOR_BODY %x THEN_BODY %x ELSE_BODY -%x DATE_MATCH -%x CLOSE_DATE +%x COPY_DATE_INFO %{ // Increments location counter for every token read @@ -93,10 +92,17 @@ DATE (-[1-9][0-9]*|[0-9]+)([YyAa]|[Mm]([1-9]|1[0-2])|[Qq][1-4]|[Ww]([1-9]{1}|[1- {DATE} { yylloc->step(); *yyout << "dates('" << yytext << "')"; } ${DATE} { yylloc->step(); *yyout << yytext + 1; } -dates{SPC}*\({SPC}* { yylloc->step(); *yyout << "dates("; BEGIN(DATE_MATCH); } -\'{SPC}*{DATE}{SPC}*\' { yylloc->step(); *yyout << yytext; BEGIN(CLOSE_DATE); } -{DATE} { yylloc->step(); *yyout << "'" << yytext << "'"; BEGIN(CLOSE_DATE); } -{SPC}*\) { yylloc->step(); *yyout << ")"; BEGIN(INITIAL); } +dates{SPC}*\({SPC}* { yylloc->step(); *yyout << "dates("; dates_parens_nb=1; BEGIN(COPY_DATE_INFO); } +<> { driver.error(*yylloc, "Unexpected end of file in dates statement"); } +{EOL} { yylloc->lines(1); yylloc->step(); } +[^()] { yylloc->step(); *yyout << yytext; } +\( { yylloc->step(); *yyout << yytext; dates_parens_nb++; } +\) { + yylloc->step(); + *yyout << yytext; + if (--dates_parens_nb == 0) + BEGIN(INITIAL); + } \} { BEGIN(INITIAL); return token::EOL; }