From ed00a330a416e8d4b9a658d9a217eb6b1e1b87de Mon Sep 17 00:00:00 2001 From: Brad Arant Date: Mon, 4 Nov 2024 16:48:14 -0800 Subject: [PATCH] Heavy work on while tag. Still needs work. --- Operand.cpp | 18 ++++++++++++------ Tag.cpp | 1 - __while.cpp | 39 +++++++++++++++++++++++---------------- tests/testfor.jet | 4 ++-- tests/testwhile.jet | 9 +++++++++ 5 files changed, 46 insertions(+), 25 deletions(-) create mode 100755 tests/testwhile.jet diff --git a/Operand.cpp b/Operand.cpp index ca823de..76e9bbf 100644 --- a/Operand.cpp +++ b/Operand.cpp @@ -70,7 +70,8 @@ namespace jet { unsigned int seed = (unsigned int)clock(); doubleValue = (double) rand_r(&seed) / (RAND_MAX + 1.0); isNumber = true; - string = std::format("{}", doubleValue); + string = std::format("{:.12f}", doubleValue); + string.removeTrailingZeros(); } else if(in.ifNext("true")) { boolean = true; string = "true"; @@ -79,7 +80,7 @@ namespace jet { string = "false"; } else if(in.startsWithNumber()) { doubleValue = in.asDouble(); - string = std::format("{}", doubleValue); + string = std::format("{:.12f}", doubleValue); isNumber = true; } else if(in.ifNext("'")) { string = in.getTokenExclude("'"); @@ -116,6 +117,7 @@ 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; @@ -238,7 +240,8 @@ namespace jet { Operand op(in); if(op.isNumber) { doubleValue += op.doubleValue; - string = std::format("{}", doubleValue); + string = std::format("{:.12f}", doubleValue); + string.removeTrailingZeros(); } else throw coreutils::Exception("operand is not a number."); } else @@ -248,7 +251,8 @@ namespace jet { Operand op(in); if(op.isNumber) { doubleValue -= op.doubleValue; - string = std::format("{}", doubleValue); + string = std::format("{:.12f}", doubleValue); + string.removeTrailingZeros(); } else throw coreutils::Exception("operand is not a number."); } else @@ -258,7 +262,8 @@ namespace jet { Operand op(in); if(op.isNumber) { doubleValue *= op.doubleValue; - string = std::format("{}", doubleValue); + string = std::format("{:.12f}", doubleValue); + string.removeTrailingZeros(); } else throw coreutils::Exception("operand is not a number."); } else @@ -268,7 +273,8 @@ namespace jet { Operand op(in); if(op.isNumber) { doubleValue /= op.doubleValue; - string = std::format("{}", doubleValue); + string = std::format("{:.12f}", doubleValue); + string.removeTrailingZeros(); } else throw coreutils::Exception("operand is not a number."); } else diff --git a/Tag.cpp b/Tag.cpp index 73a1f21..bb5c413 100644 --- a/Tag.cpp +++ b/Tag.cpp @@ -34,7 +34,6 @@ namespace jet { if(in.ifNext("<")) { name = in.getTokenInclude("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_!"); if(in.startsWith(" ") || in.startsWith("/") || in.startsWith(">")) { - coreutils::Log(coreutils::LOG_DEBUG_1) << "Processing tag: " << name; bool finished = false; while(!finished) { in.skipWhitespace(); diff --git a/__while.cpp b/__while.cpp index ea7e16b..b0ef60d 100644 --- a/__while.cpp +++ b/__while.cpp @@ -9,24 +9,17 @@ namespace jet { coreutils::MString result; bool booleanResult = false; + bool exprMethod = false; 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 +32,33 @@ 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."); + exprMethod = true; booleanResult = Operand(variables["expr"]).boolean; } while(booleanResult) { processContainer(container); container.reset(); + if(exprMethod) { + variables["expr"].reset(); + 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; + } } - + } } diff --git a/tests/testfor.jet b/tests/testfor.jet index d075685..825c7af 100755 --- a/tests/testfor.jet +++ b/tests/testfor.jet @@ -1,6 +1,6 @@ -#!./jet-2.0 +#!../jet-2.0 - + -->#[ix]<-- diff --git a/tests/testwhile.jet b/tests/testwhile.jet new file mode 100755 index 0000000..9d99ce2 --- /dev/null +++ b/tests/testwhile.jet @@ -0,0 +1,9 @@ +#!../jet-2.0 + + + + + -->$[check]-$[ix]<-- + + +