diff --git a/preprocessor/DynareFlex.ll b/preprocessor/DynareFlex.ll index a9be76298..f2b1b7b97 100644 --- a/preprocessor/DynareFlex.ll +++ b/preprocessor/DynareFlex.ll @@ -53,7 +53,7 @@ string eofbuff; %option case-insensitive noyywrap nounput batch debug never-interactive - /* NB: if new start conditions are defined, add them in the line for [\n]+ and <>*/ + /* NB: if new start conditions are defined, add them in the line for <> */ %x COMMENT %x DYNARE_STATEMENT %x DYNARE_BLOCK @@ -65,7 +65,7 @@ string eofbuff; %{ // Increments location counter for every token read -#define YY_USER_ACTION yylloc->columns(yyleng); +#define YY_USER_ACTION location_increment(yylloc, yytext); %} %% /* Code put at the beginning of yylex() */ @@ -88,7 +88,7 @@ string eofbuff; /* spaces, tabs and carriage returns are ignored */ <*>[ \t\r\f]+ { yylloc->step(); } -[\n]+ { yylloc->lines(yyleng); yylloc->step(); } +[\n]+ { yylloc->step(); } /* Comments */ ["%"].* @@ -620,6 +620,16 @@ DynareFlex::DynareFlex(istream* in, ostream* out) { } +void +DynareFlex::location_increment(Dynare::parser::location_type *yylloc, const char *yytext) +{ + while (*yytext != 0) + if (*yytext++ == '\n') + yylloc->lines(1); + else + yylloc->columns(1); +} + /* This implementation of DynareFlexLexer::yylex() is required to fill the * vtable of the class DynareFlexLexer. We define the scanner's main yylex * function via YY_DECL to reside in the DynareFlex class instead. */ diff --git a/preprocessor/ParsingDriver.hh b/preprocessor/ParsingDriver.hh index 3acb8460c..490d2bbaf 100644 --- a/preprocessor/ParsingDriver.hh +++ b/preprocessor/ParsingDriver.hh @@ -68,6 +68,9 @@ public: //! The filename being parsed /*! The bison parser locations (begin and end) contain a pointer to that string */ string filename; + + //! Increment the location counter given a token + void location_increment(Dynare::parser::location_type *yylloc, const char *yytext); }; //! Drives the scanning and parsing of the .mod file, and constructs its abstract representation