JetCore/__for.cpp

34 lines
1014 B
C++

#include "__for.h"
#include "Exception.h"
#include <iostream>
namespace jet {
__for::__for(coreutils::ZString &in, coreutils::MString &parentOut, Global &global, Tag *parent) : Tag(in, parentOut, global, parent) {
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)
variables[variables["name"]] = ix;
processContainer(container);
container.reset();
}
}
}