JetCore/__set.cpp

62 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 *local) : Tag(in, parentOut, global, parent, local) {
output = false;
if(!keywordDefined("name"))
throw coreutils::Exception("set tag must have name defined.");
if(!keywordDefined("expr") && keywordDefined("value") && hasContainer)
throw coreutils::Exception("set tag cannot have both value and a container.");
if(keywordDefined("expr") && !keywordDefined("value") && hasContainer)
throw coreutils::Exception("set tag cannot have both expr and a container.");
if(keywordDefined("expr") && keywordDefined("value") && !hasContainer)
throw coreutils::Exception("set tag cannot have both expr and value.");
if(!keywordDefined("expr") && !keywordDefined("value") && !hasContainer)
throw coreutils::Exception("set tag must have a value, expr or a container.");
if(keywordDefined("expr") && keywordDefined("eval"))
throw coreutils::Exception("Cannot use eval with expr.");
resolveKeyword("name");
if(keywordDefined("expr")) {
if(!keywordDefined("scope") || (keywords["scope"] == "global"))
global.variables[keywords["name"]] = Operand(keywords["expr"], global, parent->variables).string;
else if(keywords["scope"] == "local")
local->variables[keywords["name"]] = Operand(keywords["expr"], global, parent->variables).string;
else if(keywords["scope"] == "parent")
local->parent->variables[keywords["name"]] = Operand(keywords["expr"], global, parent->variables).string;
} else if(hasContainer) {
processContainer(container);
if(evaluate) {
if(!keywordDefined("scope") || (keywords["scope"] == "global"))
global.variables[keywords["name"]] = out;
else if(keywords["scope"] == "local")
local->variables[keywords["name"]] = out;
else if(keywords["scope"] == "parent")
local->parent->variables[keywords["name"]] = out;
} else {
if(!keywordDefined("scope") || (keywords["scope"] == "global"))
global.variables[keywords["name"]] = container;
else if(keywords["scope"] == "local")
local->variables[keywords["name"]] = container;
else if(keywords["scope"] == "parent")
local->parent->variables[keywords["name"]] = container;
}
} else {
resolveKeyword("value");
if(!keywordDefined("scope") || (keywords["scope"] == "global"))
global.variables[keywords["name"]] = keywords["value"];
else if(keywords["scope"] == "local")
local->variables[keywords["name"]] = keywords["value"];
else if(keywords["scope"] == "parent")
local->parent->variables[keywords["name"]] = keywords["value"];
}
}
}