From e12726a353cba9288815437f00c269527474420a Mon Sep 17 00:00:00 2001
From: Houtan Bastani <houtan@dynare.org>
Date: Tue, 19 Nov 2013 16:35:12 +0100
Subject: [PATCH] preprocessor: deal with dates in NativeStatement

---
 Statement.cc | 10 +++++++++-
 1 file changed, 9 insertions(+), 1 deletion(-)

diff --git a/Statement.cc b/Statement.cc
index 53d06911..4dbf8ba5 100644
--- a/Statement.cc
+++ b/Statement.cc
@@ -18,6 +18,7 @@
  */
 
 #include "Statement.hh"
+#include <boost/xpressive/xpressive.hpp>
 
 ModFileStructure::ModFileStructure() :
   check_present(false),
@@ -74,7 +75,14 @@ NativeStatement::NativeStatement(const string &native_statement_arg) :
 void
 NativeStatement::writeOutput(ostream &output, const string &basename) const
 {
-  output << native_statement << endl;
+  using namespace boost::xpressive;
+  string date_regex = "(-?\\d+([YyAa]|[Mm]([1-9]|1[0-2])|[Qq][1-4]|[Ww]([1-9]{1}|[1-4]\\d|5[0-2])))";
+  sregex regex_lookbehind = sregex::compile("(?<!\\$|\\d|[a-zA-Z]|\\')" + date_regex);
+  sregex regex_dollar = sregex::compile("(\\$)"+date_regex);
+
+  string ns = regex_replace(native_statement, regex_lookbehind, "dates('$&')");
+  ns = regex_replace(ns, regex_dollar, "$2" ); //replace $DATE with DATE
+  output << ns << endl;
 }
 
 void
-- 
GitLab