From 621134b8d82f434a4ca0bd6146fa50a0fa9899cf Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?S=C3=A9bastien=20Villemot?= <sebastien@dynare.org>
Date: Fri, 8 Apr 2022 15:06:29 +0200
Subject: [PATCH] Julia: more adaptation of DynamicSetAuxiliarySeries.jl for
 TimeDataFrame objects
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

– also use vectorized versions for .+ and .-
– add a space before vectorized operators to avoid syntactical ambiguity

This commits complements bfdcc546ecec16819dd2ac4b2c6376d003862ea6.
---
 src/ExprNode.cc | 32 ++++++++++++++++++++------------
 1 file changed, 20 insertions(+), 12 deletions(-)

diff --git a/src/ExprNode.cc b/src/ExprNode.cc
index ae80658f..ee8ac365 100644
--- a/src/ExprNode.cc
+++ b/src/ExprNode.cc
@@ -4585,20 +4585,28 @@ BinaryOpNode::writeOutput(ostream &output, ExprNodeOutputType output_type,
     output << "}";
 
   // Write current operator symbol
+  /* NB: Vectorized operators in Julia have a space before them to avoid
+     syntactical ambiguity when left operand is a numeric literal. */
   switch (op_code)
     {
     case BinaryOpcode::plus:
-      output << "+";
+      if (output_type == ExprNodeOutputType::juliaTimeDataFrame)
+        output << " .+";
+      else
+        output << "+";
       break;
     case BinaryOpcode::minus:
-      output << "-";
+      if (output_type == ExprNodeOutputType::juliaTimeDataFrame)
+        output << " .-";
+      else
+        output << "-";
       break;
     case BinaryOpcode::times:
       if (isLatexOutput(output_type))
         output << R"(\, )";
       else if (output_type == ExprNodeOutputType::occbinDifferenceFile // This file operates on vectors, see dynare#1826
                || output_type == ExprNodeOutputType::juliaTimeDataFrame)
-        output << ".*";
+        output << " .*";
       else
         output << "*";
       break;
@@ -4607,7 +4615,7 @@ BinaryOpNode::writeOutput(ostream &output, ExprNodeOutputType output_type,
         {
           if (output_type == ExprNodeOutputType::occbinDifferenceFile // This file operates on vectors, see dynare#1826
                || output_type == ExprNodeOutputType::juliaTimeDataFrame)
-            output << "./"; // This file operates on vectors, see dynare#1826
+            output << " ./";
           else
             output << "/";
         }
@@ -4615,19 +4623,19 @@ BinaryOpNode::writeOutput(ostream &output, ExprNodeOutputType output_type,
     case BinaryOpcode::power:
       if (output_type == ExprNodeOutputType::occbinDifferenceFile // This file operates on vectors, see dynare#1826
           || output_type == ExprNodeOutputType::juliaTimeDataFrame)
-        output << ".^"; // This file operates on vectors, see dynare#1826
+        output << " .^";
       else
         output << "^";
       break;
     case BinaryOpcode::less:
       if (output_type == ExprNodeOutputType::juliaTimeDataFrame)
-        output << ".<";
+        output << " .<";
       else
         output << "<";
       break;
     case BinaryOpcode::greater:
       if (output_type == ExprNodeOutputType::juliaTimeDataFrame)
-        output << ".>";
+        output << " .>";
       else
         output << ">";
       break;
@@ -4635,7 +4643,7 @@ BinaryOpNode::writeOutput(ostream &output, ExprNodeOutputType output_type,
       if (isLatexOutput(output_type))
         output << R"(\leq )";
       else if (output_type == ExprNodeOutputType::juliaTimeDataFrame)
-        output << ".<=";
+        output << " .<=";
       else
         output << "<=";
       break;
@@ -4643,13 +4651,13 @@ BinaryOpNode::writeOutput(ostream &output, ExprNodeOutputType output_type,
       if (isLatexOutput(output_type))
         output << R"(\geq )";
       else if (output_type == ExprNodeOutputType::juliaTimeDataFrame)
-        output << ".>=";
+        output << " .>=";
       else
         output << ">=";
       break;
     case BinaryOpcode::equalEqual:
       if (output_type == ExprNodeOutputType::juliaTimeDataFrame)
-        output << ".==";
+        output << " .==";
       else
         output << "==";
       break;
@@ -4659,7 +4667,7 @@ BinaryOpNode::writeOutput(ostream &output, ExprNodeOutputType output_type,
       else
         {
           if (output_type == ExprNodeOutputType::juliaTimeDataFrame)
-            output << ".!=";
+            output << " .!=";
           else if (isCOutput(output_type) || isJuliaOutput(output_type))
             output << "!=";
           else
@@ -4668,7 +4676,7 @@ BinaryOpNode::writeOutput(ostream &output, ExprNodeOutputType output_type,
       break;
     case BinaryOpcode::equal:
       if (output_type == ExprNodeOutputType::juliaTimeDataFrame)
-        output << ".=";
+        output << " .=";
       else
         output << "=";
       break;
-- 
GitLab