From d2e93452c3c8dea123a3318a8276713e516ad30c Mon Sep 17 00:00:00 2001 From: Houtan Bastani <houtan@dynare.org> Date: Mon, 18 Nov 2013 16:29:21 +0100 Subject: [PATCH] preprocessor: match dates in dynare syntax --- DynareFlex.ll | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/DynareFlex.ll b/DynareFlex.ll index b4dce1d7..7343a5ad 100644 --- a/DynareFlex.ll +++ b/DynareFlex.ll @@ -69,6 +69,9 @@ string eofbuff; // Increments location counter for every token read #define YY_USER_ACTION location_increment(yylloc, yytext); %} + +DATE -?[0-9]+([YyAa]|[Mm]([1-9]|1[0-2])|[Qq][1-4]|[Ww]([1-9]{1}|[1-4][0-9]|5[0-2])) + %% /* Code put at the beginning of yylex() */ %{ @@ -205,7 +208,24 @@ string eofbuff; <INITIAL>corr {BEGIN DYNARE_STATEMENT; return token::CORR;} /* Inside of a Dynare statement */ -<DYNARE_STATEMENT>dates {dates_parens_nb=0; BEGIN DATES_STATEMENT; yylval->string_val = new string("dates");} +<DYNARE_STATEMENT>{DATE} { + char *yycopy = strdup(yytext); + char *uput = yycopy + yyleng; + unput(')'); + unput('\''); + while (uput > yycopy) + unput(*--uput); + unput('\''); + unput('('); + unput('s'); + unput('e'); + unput('t'); + unput('a'); + unput('d'); + free( yycopy ); + } +<DYNARE_STATEMENT>${DATE} { yylloc->step(); *yyout << yytext + 1; } +<DYNARE_STATEMENT>dates {dates_parens_nb=0; BEGIN DATES_STATEMENT; yylval->string_val = new string("dates");} <DYNARE_STATEMENT>file {return token::FILE;} <DYNARE_STATEMENT>datafile {return token::DATAFILE;} <DYNARE_STATEMENT>nobs {return token::NOBS;} -- GitLab