Skip to content
Snippets Groups Projects
Commit 1910d02e authored by Sébastien Villemot's avatar Sébastien Villemot
Browse files

Preprocessor: fix line numbering problems due to native MATLAB statements (bug...

Preprocessor: fix line numbering problems due to native MATLAB statements (bug introduced in a0cd4b33aea0965d9baa9b4c66d0c875fa0aa7d0 and 6582341799d35e80c59f6f3559dbd18e70443747)
parent 705b14f5
No related branches found
No related tags found
No related merge requests found
......@@ -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 <<EOF>>*/
/* NB: if new start conditions are defined, add them in the line for <<EOF>> */
%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(); }
<INITIAL,DYNARE_STATEMENT,DYNARE_BLOCK,COMMENT,LINE1,LINE2,LINE3>[\n]+ { yylloc->lines(yyleng); yylloc->step(); }
<INITIAL,DYNARE_STATEMENT,DYNARE_BLOCK,COMMENT,LINE1,LINE2,LINE3>[\n]+ { yylloc->step(); }
/* Comments */
<INITIAL,DYNARE_STATEMENT,DYNARE_BLOCK>["%"].*
......@@ -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. */
......
......@@ -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
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment