JetCore/__for.cpp

40 lines
1.3 KiB
C++

#include "__for.h"
#include "Exception.h"
#include <iostream>
namespace jet {
__for::__for(coreutils::ZString &in, coreutils::MString &parentOut, Global &global, Tag *parent, Tag *local) : Tag(in, parentOut, global, parent, this) {
double counter = 0.0f;
bool nameDefined = variableDefined("name");
if(variableDefined("start")) {
resolveKeyword("start");
counter = variables["start"].asDouble();
variables["start"].reset();
}
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) {
if(!variableDefined("scope") || (variables["scope"] == "global"))
global.variables[variables["name"]] = ix;
else if(variables["scope"] == "local")
local->variables[variables["name"]] = ix;
else if(variables["scope"] == "parent")
parent->local->variables[variables["name"]] = ix;
}
processContainer(container);
container.reset();
}
}
}