63 lines
2.8 KiB
C++
63 lines
2.8 KiB
C++
#include "__set.h"
|
|
#include "Exception.h"
|
|
#include "Operand.h"
|
|
#include "KeywordValue.h"
|
|
#include <iostream>
|
|
|
|
namespace jet {
|
|
|
|
__set::__set(coreutils::ZString &in, coreutils::MString &parentOut, Global &global, Tag *parent) : Tag(in, parentOut, global, parent) {
|
|
output = false;
|
|
if(!variableDefined("name"))
|
|
throw coreutils::Exception("set tag must have name defined.");
|
|
if(!variableDefined("expr") && variableDefined("value") && hasContainer)
|
|
throw coreutils::Exception("set tag cannot have both value and a container.");
|
|
if(variableDefined("expr") && !variableDefined("value") && hasContainer)
|
|
throw coreutils::Exception("set tag cannot have both expr and a container.");
|
|
if(variableDefined("expr") && variableDefined("value") && !hasContainer)
|
|
throw coreutils::Exception("set tag cannot have both expr and value.");
|
|
if(!variableDefined("expr") && !variableDefined("value") && !hasContainer)
|
|
throw coreutils::Exception("set tag must have a value, expr or a container.");
|
|
if(variableDefined("expr") && variableDefined("eval"))
|
|
throw coreutils::Exception("Cannot use eval with expr.");
|
|
|
|
resolveKeyword("name");
|
|
|
|
if(variableDefined("expr")) {
|
|
resolveKeyword("expr");
|
|
if(!variableDefined("scope") || (variables["scope"] == "global"))
|
|
global.variables[variables["name"]] = Operand(variables["expr"]).string;
|
|
else if(variables["scope"] == "local")
|
|
parent->variables[variables["name"]] = Operand(variables["expr"]).string;
|
|
else if(variables["scope"] == "parent")
|
|
parent->parent->variables[variables["name"]] = Operand(variables["expr"]).string;
|
|
} else if(hasContainer) {
|
|
processContainer(container);
|
|
if(evaluate) {
|
|
if(!variableDefined("scope") || (variables["scope"] == "global"))
|
|
global.variables[variables["name"]] = out;
|
|
else if(variables["scope"] == "local")
|
|
parent->variables[variables["name"]] = out;
|
|
else if(variables["scope"] == "parent")
|
|
parent->parent->variables[variables["name"]] = out;
|
|
} else {
|
|
if(!variableDefined("scope") || (variables["scope"] == "global"))
|
|
global.variables[variables["name"]] = container;
|
|
else if(variables["scope"] == "local")
|
|
parent->variables[variables["name"]] = container;
|
|
else if(variables["scope"] == "parent")
|
|
parent->parent->variables[variables["name"]] = container;
|
|
}
|
|
} else {
|
|
resolveKeyword("value");
|
|
if(!variableDefined("scope") || (variables["scope"] == "global"))
|
|
global.variables[variables["name"]] = variables["value"];
|
|
else if(variables["scope"] == "local")
|
|
parent->variables[variables["name"]] = variables["value"];
|
|
else if(variables["scope"] == "parent")
|
|
parent->parent->variables[variables["name"]] = variables["value"];
|
|
}
|
|
|
|
}
|
|
}
|