From 299e68470db378c369503fb68a12779126ede4ff Mon Sep 17 00:00:00 2001 From: sebastien Date: Tue, 9 Dec 2008 16:13:03 +0000 Subject: [PATCH] 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 --- preprocessor/macro/MacroDriver.hh | 4 ++++ preprocessor/macro/MacroFlex.ll | 13 ++++++++++--- 2 files changed, 14 insertions(+), 3 deletions(-) diff --git a/preprocessor/macro/MacroDriver.hh b/preprocessor/macro/MacroDriver.hh index cb8a29e25..1b95a9f36 100644 --- a/preprocessor/macro/MacroDriver.hh +++ b/preprocessor/macro/MacroDriver.hh @@ -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 diff --git a/preprocessor/macro/MacroFlex.ll b/preprocessor/macro/MacroFlex.ll index 557b97330..291d30df2 100644 --- a/preprocessor/macro/MacroFlex.ll +++ b/preprocessor/macro/MacroFlex.ll @@ -92,6 +92,13 @@ CONT \\\\ {CONT}{SPC}*{EOL} { yylloc->lines(1); yylloc->step(); } {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_tmp.append(yytext); yylloc->step(); } -<> { driver.error(*yylloc, "Unexpected end of file: @#for loop not matched by an @#endfor"); } +<> { driver.error(for_stmt_loc_tmp, "@#for loop not matched by an @#endfor (unexpected end of file)"); } ^{SPC}*@#{SPC}*endfor{SPC}*{EOL} { yylloc->lines(1); yylloc->step(); @@ -212,7 +219,7 @@ CONT \\\\ yylloc->step(); } . { then_body_tmp.append(yytext); yylloc->step(); } -<> { driver.error(*yylloc, "Unexpected end of file: @#if not matched by an @#endif"); } +<> { driver.error(if_stmt_loc_tmp, "@#if not matched by an @#endif (unexpected end of file)"); } ^{SPC}*@#{SPC}*else{SPC}*{EOL} { yylloc->lines(1); yylloc->step(); @@ -254,7 +261,7 @@ CONT \\\\ yylloc->step(); } . { else_body_tmp.append(yytext); yylloc->step(); } -<> { driver.error(*yylloc, "Unexpected end of file: @#if not matched by an @#endif"); } +<> { driver.error(if_stmt_loc_tmp, "@#if not matched by an @#endif (unexpected end of file)"); } ^{SPC}*@#{SPC}*endif{SPC}*{EOL} { yylloc->lines(1);