42 lines
1.4 KiB
C++
42 lines
1.4 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")
|
|
this->local->variables[variables["name"]] = ix;
|
|
else if(variables["scope"] == "parent")
|
|
parent->local->variables[variables["name"]] = ix;
|
|
else
|
|
throw coreutils::Exception("scope value is not valid.");
|
|
}
|
|
processContainer(container);
|
|
container.reset();
|
|
}
|
|
}
|
|
|
|
}
|