Updated logic for while tag.

This commit is contained in:
Brad Arant 2024-10-30 17:35:30 -07:00
parent 9dcedd302b
commit 08218e3530

View File

@ -1,32 +1,56 @@
#include "__while.h" #include "__while.h"
#include "Exception.h" #include "Exception.h"
#include "Operand.h"
#include <iostream> #include <iostream>
namespace jet { namespace jet {
__while::__while(coreutils::ZString &in, coreutils::MString &parentOut, Global &global, Tag *parent) : Tag(in, parentOut, global, parent) { __while::__while(coreutils::ZString &in, coreutils::MString &parentOut, Global &global, Tag *parent) : Tag(in, parentOut, global, parent) {
if(variableDefined(coreutils::ZString("value1"))) { coreutils::MString result;
if(variableDefined(coreutils::ZString("expr"))) bool booleanResult = false;
if(variableDefined("value1")) {
if(variableDefined("expr"))
throw coreutils::Exception("Either value1 or expr can be specified but not both."); throw coreutils::Exception("Either value1 or expr can be specified but not both.");
if(variableDefined(coreutils::ZString("value2"))) { if(variableDefined("value2")) {
if(variableDefined(coreutils::ZString("type"))) {
// process here if(variableDefined("type")) {
} else
}
else
throw coreutils::Exception("type expected if value1 and value2 specified."); throw coreutils::Exception("type expected if value1 and value2 specified.");
} else }
else
throw coreutils::Exception("value2 required if value1 specified."); throw coreutils::Exception("value2 required if value1 specified.");
} else if(variableDefined(coreutils::ZString("expr"))) { if(!variableDefined("type"))
if(variableDefined(coreutils::ZString("value2"))) throw coreutils::Exception("type required for a value1 and value2 comparison.");
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;
else
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."); throw coreutils::Exception("value2 should not be specified with expr.");
if(variableDefined(coreutils::ZString("type"))) if(variableDefined("type"))
throw coreutils::Exception("type should not be specified with expr."); throw coreutils::Exception("type should not be specified with expr.");
// process here booleanResult = Operand(variables["expr"]).boolean;
} }
while(true) { while(booleanResult) {
processContainer(container); processContainer(container);
} container.reset();
}
} }