Skip to content
Snippets Groups Projects
Select Git revision
  • 127361971f8f2b5356dee11f795167fc430bf42a
  • master default protected
  • pac_composite_target_mce
  • ramsey_k_order
  • 4.6
  • occbin
  • uop
  • rework_pac
  • aux_vars_fix
  • created_preprocessor_repo
10 results

Statement.cc

Blame
  • Forked from Dynare / preprocessor
    Source project has a limited visibility.
    Statement.cc 12.20 KiB
    /*
     * Copyright © 2006-2021 Dynare Team
     *
     * This file is part of Dynare.
     *
     * Dynare is free software: you can redistribute it and/or modify
     * it under the terms of the GNU General Public License as published by
     * the Free Software Foundation, either version 3 of the License, or
     * (at your option) any later version.
     *
     * Dynare is distributed in the hope that it will be useful,
     * but WITHOUT ANY WARRANTY; without even the implied warranty of
     * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
     * GNU General Public License for more details.
     *
     * You should have received a copy of the GNU General Public License
     * along with Dynare.  If not, see <https://www.gnu.org/licenses/>.
     */
    
    #include "Statement.hh"
    #pragma GCC diagnostic push
    #pragma GCC diagnostic ignored "-Wold-style-cast"
    #include <boost/xpressive/xpressive.hpp>
    #pragma GCC diagnostic pop
    #include <utility>
    
    void
    Statement::checkPass(ModFileStructure &mod_file_struct, WarningConsolidation &warnings)
    {
    }
    
    void
    Statement::computingPass(const ModFileStructure &mod_file_struct)
    {
    }
    
    NativeStatement::NativeStatement(string native_statement_arg) :
      native_statement{move(native_statement_arg)}
    {
    }
    
    void
    NativeStatement::writeOutput(ostream &output, const string &basename, bool minimal_workspace) const
    {
      using namespace boost::xpressive;
      string date_regex = R"((-?\d+([YyAa]|[Mm]([1-9]|1[0-2])|[Qq][1-4]|[SsHh][1-2])))";
      sregex regex_lookbehind = sregex::compile(R"((?<!\$|\d|[a-zA-Z_]|-|'))" + date_regex);
      sregex regex_dollar = sregex::compile(R"((\$))" + 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
    NativeStatement::writeJsonOutput(ostream &output) const
    {
      output << R"({"statementName": "native")"
             << R"(, "string": ")";
    
      // A similar code is in VerbatimStatement::writeJsonOutput()
      for (auto ch : native_statement)
        switch (ch)
          {
          case '\b':
    	output << R"(\b)";
    	break;
    
          case '\f':
    	output << R"(\f)";