From 98168dabd81b16d480e597d20991e0232c495d9d Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?S=C3=A9bastien=20Villemot?= <sebastien.villemot@ens.fr>
Date: Mon, 6 Dec 2010 17:59:30 +0100
Subject: [PATCH] MOD files ending with @#endif/@#endfor but no newline now
 work (closes #73)

---
 macro/MacroDriver.cc | 13 +++++++++++--
 1 file changed, 11 insertions(+), 2 deletions(-)

diff --git a/macro/MacroDriver.cc b/macro/MacroDriver.cc
index fd05edee..dc1a1496 100644
--- a/macro/MacroDriver.cc
+++ b/macro/MacroDriver.cc
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 2008-2009 Dynare Team
+ * Copyright (C) 2008-2010 Dynare Team
  *
  * This file is part of Dynare.
  *
@@ -20,6 +20,7 @@
 #include <cstdlib>
 #include <iostream>
 #include <fstream>
+#include <sstream>
 
 #include "MacroDriver.hh"
 
@@ -46,7 +47,15 @@ MacroDriver::parse(const string &f, ostream &out, bool debug, bool no_line_macro
       exit(EXIT_FAILURE);
     }
 
-  lexer = new MacroFlex(&in, &out, no_line_macro);
+  /*
+    Copy the file into a stringstream, and add an extra end-of-line. This is a
+    workaround for trac ticket #73: with this workaround, MOD files ending with
+    an @#endif or an @#endfor - but no newline - no longer trigger an error.
+  */
+  stringstream file_with_endl;
+  file_with_endl << in.rdbuf() << endl;
+
+  lexer = new MacroFlex(&file_with_endl, &out, no_line_macro);
   lexer->set_debug(debug);
 
   Macro::parser parser(*this, out);
-- 
GitLab