think migration is almost done, at least for set tag.

This commit is contained in:
barant 2025-01-08 17:04:36 -08:00
parent 5c27df59da
commit b3693e8017
3 changed files with 39 additions and 36 deletions

69
Tag.cpp
View File

@ -112,15 +112,16 @@ namespace jet {
coreutils::MString Tag::resolveKeyword(coreutils::ZString keyword) { coreutils::MString Tag::resolveKeyword(coreutils::ZString keyword) {
coreutils::MString resolved; coreutils::MString resolved;
keyword.reset(); keywords[keyword].reset();
while(!keyword.eod()) { while(!keywords[keyword].eod()) {
if(keyword.startsWith("$[") || keyword.startsWith("#[")) { if(keywords[keyword].startsWith("$[") || keywords[keyword].startsWith("#[")) {
resolved.write(getVariable(keyword)); resolved.write(getVariable(keywords[keyword]));
} else { } else {
resolved.write(keyword.charAt(0)); resolved.write(keywords[keyword].charAt(0));
keyword.nextChar(); keywords[keyword].nextChar();
} }
} }
keywords[keyword].reset();
return resolved; return resolved;
} }
@ -216,7 +217,7 @@ namespace jet {
} }
} else if(in.startsWith("$[") || in.startsWith("#[")) { } else if(in.startsWith("$[") || in.startsWith("#[")) {
global.errorCursor = in.getCursor(); global.errorCursor = in.getCursor();
out.write(getVariable(in)); out.write(getVariable(in, true));
} else { } else {
out.write(in.nextChar()); out.write(in.nextChar());
} }
@ -377,7 +378,7 @@ namespace jet {
return false; return false;
} }
coreutils::MString Tag::getVariable(coreutils::ZString &variable) { coreutils::MString Tag::getVariable(coreutils::ZString &variable, bool inContainer) {
if(variable.ifNext("$[")) { if(variable.ifNext("$[")) {
coreutils::MString name; coreutils::MString name;
coreutils::MString modifier; coreutils::MString modifier;
@ -386,7 +387,10 @@ namespace jet {
return global.variables[name]; return global.variables[name];
} else if(variable.ifNext("%")) { } else if(variable.ifNext("%")) {
renderVariableName(variable, name, modifier); renderVariableName(variable, name, modifier);
if(inContainer)
return keywords[name]; return keywords[name];
else
return parent->keywords[name];
} else if(variable.ifNext(":")) { } else if(variable.ifNext(":")) {
renderVariableName(variable, name, modifier); renderVariableName(variable, name, modifier);
if(name.find(":") == -1) { if(name.find(":") == -1) {
@ -440,37 +444,36 @@ namespace jet {
void Tag::storeVariable(coreutils::ZString variable) { void Tag::storeVariable(coreutils::ZString variable) {
if(keywordDefined("expr")) { if(keywordDefined("expr")) {
if(!keywordDefined("scope") || (keywords["scope"] == "global")) if(!keywordDefined("scope") || (resolveKeyword("scope") == "global"))
global.variables[keywords[variable]] = Operand(keywords["expr"], *this).string; global.variables[variable] = Operand(keywords["expr"], *this).string;
else if(keywords["scope"] == "local") else if(resolveKeyword("scope") == "local")
local->variables[keywords[variable]] = Operand(keywords["expr"], *this).string; local->variables[variable] = Operand(keywords["expr"], *this).string;
else if(keywords["scope"] == "parent") else if(resolveKeyword("scope") == "parent")
local->parent->variables[keywords[variable]] = Operand(keywords["expr"], *this).string; local->parent->variables[variable] = Operand(keywords["expr"], *this).string;
} else if(hasContainer) { } else if(hasContainer) {
processContainer(container); processContainer(container);
if(evaluate) { if(evaluate) {
if(!keywordDefined("scope") || (keywords["scope"] == "global")) if(!keywordDefined("scope") || (resolveKeyword("scope") == "global"))
global.variables[keywords[variable]] = out; global.variables[variable] = out;
else if(keywords["scope"] == "local") else if(resolveKeyword("scope") == "local")
local->variables[keywords[variable]] = out; local->variables[variable] = out;
else if(keywords["scope"] == "parent") else if(resolveKeyword("scope") == "parent")
local->parent->variables[keywords[variable]] = out; local->parent->variables[variable] = out;
} else { } else {
if(!keywordDefined("scope") || (keywords["scope"] == "global")) if(!keywordDefined("scope") || (resolveKeyword("scope") == "global"))
global.variables[keywords[variable]] = container; global.variables[variable] = container;
else if(keywords["scope"] == "local") else if(resolveKeyword("scope") == "local")
local->variables[keywords[variable]] = container; local->variables[variable] = container;
else if(keywords["scope"] == "parent") else if(resolveKeyword("scope") == "parent")
local->parent->variables[keywords[variable]] = container; local->parent->variables[variable] = container;
} }
} else { } else {
resolveKeyword("value"); if(!keywordDefined("scope") || (resolveKeyword("scope") == "global"))
if(!keywordDefined("scope") || (keywords["scope"] == "global")) global.variables[variable] = resolveKeyword("value");
global.variables[keywords[variable]] = keywords["value"]; else if(resolveKeyword("scope") == "local")
else if(keywords["scope"] == "local") local->variables[variable] = resolveKeyword("value");
local->variables[keywords[variable]] = keywords["value"]; else if(resolveKeyword("scope") == "parent")
else if(keywords["scope"] == "parent") local->parent->variables[variable] = resolveKeyword("value");
local->parent->variables[keywords[variable]] = keywords["value"];
} }
} }

2
Tag.h
View File

@ -14,7 +14,7 @@ namespace jet {
Tag(coreutils::ZString &in, coreutils::MString &parentOut, Global &global, Tag *parent = NULL, Tag *local = NULL, coreutils::ZString splitTagName = ""); Tag(coreutils::ZString &in, coreutils::MString &parentOut, Global &global, Tag *parent = NULL, Tag *local = NULL, coreutils::ZString splitTagName = "");
virtual ~Tag(); virtual ~Tag();
coreutils::MString getVariable(coreutils::ZString &variable); coreutils::MString getVariable(coreutils::ZString &variable, bool inContainer = false);
coreutils::MString resolveKeyword(coreutils::ZString keyword); coreutils::MString resolveKeyword(coreutils::ZString keyword);
std::map<coreutils::MString, coreutils::MString> variables; std::map<coreutils::MString, coreutils::MString> variables;

View File

@ -19,7 +19,7 @@ namespace jet {
if(keywordDefined("expr") && keywordDefined("eval")) if(keywordDefined("expr") && keywordDefined("eval"))
throw coreutils::Exception("Cannot use eval with expr."); throw coreutils::Exception("Cannot use eval with expr.");
storeVariable(keywords[resolveKeyword("name")]); storeVariable(resolveKeyword("name"));
} }