From 6da620971e4c5a058856a6a3bc8a3c2ae054e385 Mon Sep 17 00:00:00 2001 From: brad Arant Date: Sun, 10 Nov 2024 18:45:12 -0800 Subject: [PATCH] Finished up the keyword resolution issue and fixed for, while and until. Other tags still need work. --- Operand.cpp | 9 +++------ Tag.cpp | 2 -- __for.cpp | 26 ++++++++++++++----------- __set.cpp | 4 ++-- __until.cpp | 47 +++++++++++++++++++++++++++------------------ __while.cpp | 14 +++++++++----- tests/testvar.jet | 3 +++ tests/testwhile.jet | 3 +-- 8 files changed, 61 insertions(+), 47 deletions(-) diff --git a/Operand.cpp b/Operand.cpp index 44f4e6e..68a0fa0 100644 --- a/Operand.cpp +++ b/Operand.cpp @@ -117,7 +117,6 @@ namespace jet { if(in.ifNext("<")) { Operand op(in); if(isNumber && op.isNumber) { - std::cout << doubleValue << " < " << op.doubleValue << std::endl; if(doubleValue < op.doubleValue) { boolean = true; isNumber = false; @@ -279,11 +278,9 @@ namespace jet { throw coreutils::Exception("operand is not a number."); } else throw coreutils::Exception("operand is not a number."); - } else { -// std::cout << ">" << string << std::endl; - return; - } - + } else + return; + } } diff --git a/Tag.cpp b/Tag.cpp index 1571999..aa91d8f 100644 --- a/Tag.cpp +++ b/Tag.cpp @@ -2,7 +2,6 @@ #include "Exception.h" #include "KeywordValue.h" #include "Global.h" -#include "Log.h" #include "__mysql.h" #include "__sql.h" #include "__whilerow.h" @@ -63,7 +62,6 @@ namespace jet { trimLines = variables["trimlines"] == "true" ? true: false; } if(hasContainer) { - coreutils::Log(coreutils::LOG_DEBUG_2) << "has Container: " << hasContainer; bool hasSplitTag = splitTagName == "" ? false: true; char *start = in.getCursor(); while(!in.eod()) { diff --git a/__for.cpp b/__for.cpp index 659ec5c..9ca41e8 100644 --- a/__for.cpp +++ b/__for.cpp @@ -5,20 +5,24 @@ namespace jet { __for::__for(coreutils::ZString &in, coreutils::MString &parentOut, Global &global, Tag *parent) : Tag(in, parentOut, global, parent) { - double counter = 0.0f; - double end = 0.0f; - double step = 0.0f; + double counter = 0.0f; bool nameDefined = variableDefined("name"); - if(variableDefined(coreutils::ZString("start"))) { + if(variableDefined("start")) { + resolveKeyword("start"); counter = variables["start"].asDouble(); + variables["start"].reset(); } - if(variableDefined(coreutils::ZString("end"))) { - end = variables["end"].asDouble(); - } - if(variableDefined(coreutils::ZString("step"))) { - step = variables["step"].asDouble(); - } - for(double ix = counter; ix <= end; ix += step) { + if(variableDefined("end")) + resolveKeyword("end"); + else + throw coreutils::Exception("for tag requires end keyword."); + if(variableDefined("step")) + resolveKeyword("step"); + else + throw coreutils::Exception("for tag requires step keyword."); + for(double ix = counter; ix <= variables["end"].asDouble(); ix += variables["step"].asDouble()) { + variables["end"].reset(); + variables["step"].reset(); if(nameDefined) variables[variables["name"]] = ix; processContainer(container); diff --git a/__set.cpp b/__set.cpp index d67f5da..707ada9 100644 --- a/__set.cpp +++ b/__set.cpp @@ -24,9 +24,9 @@ namespace jet { resolveKeyword("name"); if(variableDefined("expr")) { - resolveKeyword("eval"); + resolveKeyword("expr"); if(!variableDefined("scope") || (variables["scope"] == "global")) - global.variables[variables["name"]] = Operand(variables["expr"]).string; + global.variables[variables["name"]] = Operand(variables["expr"]).string; else if(variables["scope"] == "local") parent->variables[variables["name"]] = Operand(variables["expr"]).string; else if(variables["scope"] == "parent") diff --git a/__until.cpp b/__until.cpp index 82d7a44..e0e2e9b 100644 --- a/__until.cpp +++ b/__until.cpp @@ -9,24 +9,18 @@ namespace jet { coreutils::MString result; bool booleanResult = false; + bool exprMethod = false; + coreutils::MString exprSaved; if(variableDefined("value1")) { - + if(variableDefined("expr")) - throw coreutils::Exception("Either value1 or expr can be specified but not both."); - if(variableDefined("value2")) { - - if(variableDefined("type")) { - - - } - else - throw coreutils::Exception("type expected if value1 and value2 specified."); - } - else + throw coreutils::Exception("either value1 or expr can be specified but not both."); + if(!variableDefined("value2")) throw coreutils::Exception("value2 required if value1 specified."); - if(!variableDefined("type")) - throw coreutils::Exception("type required for a value1 and value2 comparison."); + if(!variableDefined("type")) + throw coreutils::Exception("type expected if value1 and value2 specified."); + int rc = variables["value1"].compare(variables["value2"]); if(((variables["type"] == "eq") && (rc == 0)) || ((variables["type"] == "ne") && (rc != 0)) || @@ -39,19 +33,34 @@ namespace jet { throw coreutils::Exception("type value must be 'eq','ne','lt','le','gt','ge'."); } else if(variableDefined("expr")) { - if(variableDefined("value2")) throw coreutils::Exception("value2 should not be specified with expr."); if(variableDefined("type")) throw coreutils::Exception("type should not be specified with expr."); - booleanResult = Operand(variables["expr"]).boolean; + exprMethod = true; + exprSaved = variables["expr"]; } - - do { + do { processContainer(container); container.reset(); + if(exprMethod) { + variables["expr"].reset(); + variables["expr"] = exprSaved; + resolveKeyword("expr"); + booleanResult = Operand(variables["expr"]).boolean; + } else { + booleanResult = false; + int rc = variables["value1"].compare(variables["value2"]); + if(((variables["type"] == "eq") && (rc == 0)) || + ((variables["type"] == "ne") && (rc != 0)) || + ((variables["type"] == "lt") && (rc == -1)) || + ((variables["type"] == "le") && (rc != 1)) || + ((variables["type"] == "gt") && (rc == 1)) || + ((variables["type"] == "ge") && (rc != -1))) + booleanResult = true; + } } while(booleanResult); - + } } diff --git a/__while.cpp b/__while.cpp index b0ef60d..c10829f 100644 --- a/__while.cpp +++ b/__while.cpp @@ -10,6 +10,7 @@ namespace jet { coreutils::MString result; bool booleanResult = false; bool exprMethod = false; + coreutils::MString exprSaved; if(variableDefined("value1")) { @@ -37,15 +38,18 @@ namespace jet { if(variableDefined("type")) throw coreutils::Exception("type should not be specified with expr."); exprMethod = true; + exprSaved = variables["expr"]; + resolveKeyword("expr"); booleanResult = Operand(variables["expr"]).boolean; } - - while(booleanResult) { + while(booleanResult) { processContainer(container); container.reset(); - if(exprMethod) { - variables["expr"].reset(); - booleanResult = Operand(variables["expr"]).boolean; + if(exprMethod) { + variables["expr"].reset(); + variables["expr"] = exprSaved; + resolveKeyword("expr"); + booleanResult = Operand(variables["expr"]).boolean; } else { booleanResult = false; int rc = variables["value1"].compare(variables["value2"]); diff --git a/tests/testvar.jet b/tests/testvar.jet index b58f703..8527c75 100755 --- a/tests/testvar.jet +++ b/tests/testvar.jet @@ -12,3 +12,6 @@ $[var$[i$[letterx]]var] $[letterx;TOHEX] $[var$[i$[letterx]]$[ix]] $[var$[i$[letterx]]$[i$[letterx]]] +$[ix] + +$[ix] diff --git a/tests/testwhile.jet b/tests/testwhile.jet index 9d99ce2..ad8f82e 100755 --- a/tests/testwhile.jet +++ b/tests/testwhile.jet @@ -2,8 +2,7 @@ - - -->$[check]-$[ix]<-- + -->$[ix]<--