macroprocessor: copy anything within "dates()" straight to preprocessing stage

time-shift
Houtan Bastani 2013-10-21 17:44:57 +02:00
parent 9eb34cee4a
commit 4f93207a30
2 changed files with 14 additions and 6 deletions

View File

@ -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

View File

@ -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-
<INITIAL>{DATE} { yylloc->step(); *yyout << "dates('" << yytext << "')"; }
<INITIAL>${DATE} { yylloc->step(); *yyout << yytext + 1; }
<INITIAL>dates{SPC}*\({SPC}* { yylloc->step(); *yyout << "dates("; BEGIN(DATE_MATCH); }
<DATE_MATCH>\'{SPC}*{DATE}{SPC}*\' { yylloc->step(); *yyout << yytext; BEGIN(CLOSE_DATE); }
<DATE_MATCH>{DATE} { yylloc->step(); *yyout << "'" << yytext << "'"; BEGIN(CLOSE_DATE); }
<CLOSE_DATE>{SPC}*\) { yylloc->step(); *yyout << ")"; BEGIN(INITIAL); }
<INITIAL>dates{SPC}*\({SPC}* { yylloc->step(); *yyout << "dates("; dates_parens_nb=1; BEGIN(COPY_DATE_INFO); }
<COPY_DATE_INFO><<EOF>> { driver.error(*yylloc, "Unexpected end of file in dates statement"); }
<COPY_DATE_INFO>{EOL} { yylloc->lines(1); yylloc->step(); }
<COPY_DATE_INFO>[^()] { yylloc->step(); *yyout << yytext; }
<COPY_DATE_INFO>\( { yylloc->step(); *yyout << yytext; dates_parens_nb++; }
<COPY_DATE_INFO>\) {
yylloc->step();
*yyout << yytext;
if (--dates_parens_nb == 0)
BEGIN(INITIAL);
}
<EXPR>\} { BEGIN(INITIAL); return token::EOL; }