Skip to content
Snippets Groups Projects
Verified Commit 487c3729 authored by Sébastien Villemot's avatar Sébastien Villemot
Browse files

Macroprocessor: fix newlines in output when under Windows and input uses CR+LF convention

If the input .mod file uses CR+LF convention, and if the user is under Windows,
then the output of the macroprocessor (as given by the “savemacro” option) had
incorrect end of lines: those would be CR+CR+LF.

The reason is that some TextNode(s) internally created by the macroprocessor
would themselves contain CR+LF sequences, which would then be transformed into
CR+CR+LF in the output (because MinGW transforms LF into CR+LF in output
streams).

The fix consists in changing the nature of the EOL token: the parsed text is no
longer attached to it, so that the Bison file now systematically turns it into
a LF inside TextNode(s).

Closes: #80
parent 1041f205
No related branches found
No related tags found
No related merge requests found
// -*- C++ -*- // -*- C++ -*-
/* /*
* Copyright © 2019-2020 Dynare Team * Copyright © 2019-2021 Dynare Team
* *
* This file is part of Dynare. * This file is part of Dynare.
* *
...@@ -89,7 +89,8 @@ using namespace macro; ...@@ -89,7 +89,8 @@ using namespace macro;
%precedence CAST %precedence CAST
%nonassoc POWER %nonassoc POWER
%token <string> NAME TEXT QUOTED_STRING NUMBER EOL %token EOL
%token <string> NAME TEXT QUOTED_STRING NUMBER
%type <DirectivePtr> statement %type <DirectivePtr> statement
%type <DirectivePtr> directive directive_one_line directive_multiline for if ifdef ifndef text eval %type <DirectivePtr> directive directive_one_line directive_multiline for if ifdef ifndef text eval
...@@ -284,7 +285,7 @@ else : else_begin EOL ...@@ -284,7 +285,7 @@ else : else_begin EOL
text : TEXT text : TEXT
{ $$ = make_shared<TextNode>($1, @$); } { $$ = make_shared<TextNode>($1, @$); }
| EOL | EOL
{ $$ = make_shared<TextNode>($1, @$); } { $$ = make_shared<TextNode>("\n", @$); }
; ;
eval : BEGIN_EVAL expr END_EVAL eval : BEGIN_EVAL expr END_EVAL
......
/* -*- C++ -*- */ /* -*- C++ -*- */
/* /*
* Copyright © 2019 Dynare Team * Copyright © 2019-2021 Dynare Team
* *
* This file is part of Dynare. * This file is part of Dynare.
* *
...@@ -180,7 +180,6 @@ CONT \\\\{SPC}* ...@@ -180,7 +180,6 @@ CONT \\\\{SPC}*
<expr,end_line>{CONT}("//".*)?{SPC}*{EOL} { yylloc->lines(1); yylloc->step(); } <expr,end_line>{CONT}("//".*)?{SPC}*{EOL} { yylloc->lines(1); yylloc->step(); }
<expr,end_line>{SPC}*("//".*)?{EOL} { <expr,end_line>{SPC}*("//".*)?{EOL} {
yylval->build<string>("\n");
yylloc->lines(1); yylloc->lines(1);
BEGIN(INITIAL); BEGIN(INITIAL);
return token::EOL; return token::EOL;
...@@ -188,8 +187,7 @@ CONT \\\\{SPC}* ...@@ -188,8 +187,7 @@ CONT \\\\{SPC}*
<INITIAL>^{SPC}*@#{SPC}* { BEGIN(directive); } <INITIAL>^{SPC}*@#{SPC}* { BEGIN(directive); }
<INITIAL>@\{ { BEGIN(eval); return token::BEGIN_EVAL; } <INITIAL>@\{ { BEGIN(eval); return token::BEGIN_EVAL; }
<INITIAL>{SPC}*{EOL} { <INITIAL>{EOL} {
yylval->build<string>(yytext);
yylloc->lines(1); yylloc->lines(1);
return token::EOL; return token::EOL;
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment