Commit 299e6847 authored by sebastien's avatar sebastien
Browse files

trunk preprocessor/macro: report the location of @#for or @#if statement when...

trunk preprocessor/macro: report the location of @#for or @#if statement when not matched by an @#endfor or an @#endif

git-svn-id: https://www.dynare.org/svn/dynare/dynare_v4@2304 ac1d8469-bf42-47a9-8791-bf33cf982152
parent ca182d3a
......@@ -81,6 +81,8 @@ private:
string for_body_tmp;
//! Temporary variable used in FOR_BODY mode
Macro::parser::location_type for_body_loc_tmp;
//! Temporary variable used in FOR_BODY mode. Keeps track of the location of the @#for statement, for reporting messages
Macro::parser::location_type for_stmt_loc_tmp;
//! Temporary variable used in FOR_BODY mode. Keeps track of number of nested @#for/@#endfor
int nested_for_nb;
//! Set to true while parsing a FOR statement (only the statement, not the loop body)
......@@ -92,6 +94,8 @@ private:
string then_body_tmp;
//! Temporary variable used in THEN_BODY mode
Macro::parser::location_type then_body_loc_tmp;
//! Temporary variable used in THEN_BODY mode. Keeps track of the location of the @#if statement, for reporting messages
Macro::parser::location_type if_stmt_loc_tmp;
//! Temporary variable used in ELSE_BODY mode
string else_body_tmp;
//! Temporary variable used in ELSE_BODY mode
......
......@@ -92,6 +92,13 @@ CONT \\\\
<STMT>{CONT}{SPC}*{EOL} { yylloc->lines(1); yylloc->step(); }
<STMT>{EOL} {
/* If parsing a @#for or an @#if, keep the location
for reporting message in case of error */
if (reading_for_statement)
for_stmt_loc_tmp = *yylloc;
else if (reading_if_statement)
if_stmt_loc_tmp = *yylloc;
yylloc->lines(1);
yylloc->step();
if (reading_for_statement)
......@@ -180,7 +187,7 @@ CONT \\\\
yylloc->step();
}
<FOR_BODY>. { for_body_tmp.append(yytext); yylloc->step(); }
<FOR_BODY><<EOF>> { driver.error(*yylloc, "Unexpected end of file: @#for loop not matched by an @#endfor"); }
<FOR_BODY><<EOF>> { driver.error(for_stmt_loc_tmp, "@#for loop not matched by an @#endfor (unexpected end of file)"); }
<FOR_BODY>^{SPC}*@#{SPC}*endfor{SPC}*{EOL} {
yylloc->lines(1);
yylloc->step();
......@@ -212,7 +219,7 @@ CONT \\\\
yylloc->step();
}
<THEN_BODY>. { then_body_tmp.append(yytext); yylloc->step(); }
<THEN_BODY><<EOF>> { driver.error(*yylloc, "Unexpected end of file: @#if not matched by an @#endif"); }
<THEN_BODY><<EOF>> { driver.error(if_stmt_loc_tmp, "@#if not matched by an @#endif (unexpected end of file)"); }
<THEN_BODY>^{SPC}*@#{SPC}*else{SPC}*{EOL} {
yylloc->lines(1);
yylloc->step();
......@@ -254,7 +261,7 @@ CONT \\\\
yylloc->step();
}
<ELSE_BODY>. { else_body_tmp.append(yytext); yylloc->step(); }
<ELSE_BODY><<EOF>> { driver.error(*yylloc, "Unexpected end of file: @#if not matched by an @#endif"); }
<ELSE_BODY><<EOF>> { driver.error(if_stmt_loc_tmp, "@#if not matched by an @#endif (unexpected end of file)"); }
<ELSE_BODY>^{SPC}*@#{SPC}*endif{SPC}*{EOL} {
yylloc->lines(1);
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment