#include "__set.h" #include "Exception.h" #include "Operand.h" #include "KeywordValue.h" #include namespace jet { __set::__set(coreutils::ZString &in, coreutils::MString &parentOut, Global &global, Tag *parent) : Tag(in, parentOut, global, parent, 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")) { if(!variableDefined("scope") || (variables["scope"] == "global")) global.variables[variables["name"]] = Operand(variables["expr"], global, parent->variables).string; else if(variables["scope"] == "local") local->variables[variables["name"]] = Operand(variables["expr"], global, parent->variables).string; else if(variables["scope"] == "parent") local->parent->variables[variables["name"]] = Operand(variables["expr"], global, parent->variables).string; } else if(hasContainer) { processContainer(container); if(evaluate) { if(!variableDefined("scope") || (variables["scope"] == "global")) global.variables[variables["name"]] = out; else if(variables["scope"] == "local") local->variables[variables["name"]] = out; else if(variables["scope"] == "parent") local->parent->variables[variables["name"]] = out; } else { if(!variableDefined("scope") || (variables["scope"] == "global")) global.variables[variables["name"]] = container; else if(variables["scope"] == "local") local->variables[variables["name"]] = container; else if(variables["scope"] == "parent") local->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") local->variables[variables["name"]] = variables["value"]; else if(variables["scope"] == "parent") local->parent->variables[variables["name"]] = variables["value"]; } } }