From 0eca1351d9d326a31004672cb44ab38f4a1ae281 Mon Sep 17 00:00:00 2001 From: sebastien Date: Fri, 8 Feb 2008 13:10:10 +0000 Subject: [PATCH] v4 preprocessor: ignore Ctrl-M in macro-processor git-svn-id: https://www.dynare.org/svn/dynare/dynare_v4@1699 ac1d8469-bf42-47a9-8791-bf33cf982152 --- preprocessor/DynareFlex.ll | 2 +- preprocessor/macro/MacroFlex.ll | 24 ++++++++++++++---------- 2 files changed, 15 insertions(+), 11 deletions(-) diff --git a/preprocessor/DynareFlex.ll b/preprocessor/DynareFlex.ll index 5a31230f4..7bf9202d5 100644 --- a/preprocessor/DynareFlex.ll +++ b/preprocessor/DynareFlex.ll @@ -72,7 +72,7 @@ int sigma_e = 0; /* Rules for matching @line directives */ <*>^@line\ \" { line_caller = YYSTATE; BEGIN(LINE1); } -[^\"\n]* { +[^\"]* { if (yylloc->begin.filename) delete yylloc->begin.filename; yylloc->begin.filename = yylloc->end.filename = new string(yytext); diff --git a/preprocessor/macro/MacroFlex.ll b/preprocessor/macro/MacroFlex.ll index f51bdb235..0ef1f967f 100644 --- a/preprocessor/macro/MacroFlex.ll +++ b/preprocessor/macro/MacroFlex.ll @@ -62,11 +62,11 @@ typedef Macro::parser::token token; %} /* Ignore @line declarations, replace them by a blank line */ -^@line[^\n]*\n { yylloc->lines(1); yylloc->step(); *yyout << endl; } +^@line[^\r\n]*(\r)?\n { yylloc->lines(1); yylloc->step(); *yyout << endl; } -^@include[ \t]+\" BEGIN(INCLUDE); +^@include[ \t]+\" BEGIN(INCLUDE); -[^\"\n]* { +[^\"\r\n]* { driver.ifs = new ifstream(yytext); if (driver.ifs->fail()) driver.error(*yylloc, "Could not open " + string(yytext)); @@ -88,13 +88,13 @@ typedef Macro::parser::token token; BEGIN(INITIAL); } -\"[^\n]*\n { - yylloc->lines(1); - yylloc->step(); - *yyout << "@line \"" << *yylloc->begin.filename << "\" " - << yylloc->begin.line << endl; - BEGIN(INITIAL); - } +\"[^\r\n]*(\r)?\n { + yylloc->lines(1); + yylloc->step(); + *yyout << "@line \"" << *yylloc->begin.filename << "\" " + << yylloc->begin.line << endl; + BEGIN(INITIAL); + } <> { /* We don't use yypop_buffer_state(), since it doesn't exist in @@ -116,6 +116,10 @@ typedef Macro::parser::token token; BEGIN(END_INCLUDE); } + /* Ignore Ctrl-M */ +(\r)+ { yylloc->step(); } + + /* Copy everything else to output */ [\n]+ { yylloc->lines(yyleng); yylloc->step(); ECHO; } . { yylloc->step(); ECHO; }