Laid ground work for resolveKeyword method on Tag and to not resolve automatically.

This commit is contained in:
brad Arant 2024-11-10 13:07:53 -08:00
parent 169ad1aa11
commit d7936de84f
5 changed files with 22 additions and 9 deletions

View File

@ -51,7 +51,7 @@ namespace jet {
if(!finished) { if(!finished) {
coreutils::ZString keywordName = in.getTokenInclude("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_"); coreutils::ZString keywordName = in.getTokenInclude("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_");
if(in.ifNext("=\"")) { if(in.ifNext("=\"")) {
variables[keywordName] = KeywordValue(in.getTokenExclude("\""), global, parent->variables); variables[keywordName] = in.getTokenExclude("\"");
} }
if(!in.ifNext("\"")) {} if(!in.ifNext("\"")) {}
} }
@ -91,7 +91,7 @@ namespace jet {
} else if(variables["eval"] == "no") { } else if(variables["eval"] == "no") {
evaluate = false; evaluate = false;
} else } else
throw coreutils::Exception("Keyword 'eval' must be 'yes' or 'no'."); throw coreutils::Exception("keyword 'eval' must be 'yes' or 'no'.");
} }
} }
} else } else
@ -106,6 +106,10 @@ namespace jet {
copyContainer(container, parentOut); copyContainer(container, parentOut);
} }
void Tag::resolveKeyword(coreutils::ZString keyword) {
variables[keyword] = KeywordValue(variables[keyword], global, variables);
}
void Tag::processContainer(coreutils::ZString &container, coreutils::ZString container2) { void Tag::processContainer(coreutils::ZString &container, coreutils::ZString container2) {
if(hasContainer && evaluate) if(hasContainer && evaluate)
parseContainer(container, container2); parseContainer(container, container2);

1
Tag.h
View File

@ -14,6 +14,7 @@ namespace jet {
Tag(coreutils::ZString &in, coreutils::MString &parentOut, Global &global, Tag *parent, coreutils::ZString splitTagName = ""); Tag(coreutils::ZString &in, coreutils::MString &parentOut, Global &global, Tag *parent, coreutils::ZString splitTagName = "");
virtual ~Tag(); virtual ~Tag();
void resolveKeyword(coreutils::ZString keyword);
std::map<coreutils::ZString, coreutils::MString> variables; std::map<coreutils::ZString, coreutils::MString> variables;
coreutils::ZString name; coreutils::ZString name;
coreutils::ZString container; coreutils::ZString container;

View File

@ -10,6 +10,11 @@ namespace jet {
if(requestMethod == "POST") { if(requestMethod == "POST") {
coreutils::ZString contentLength(getenv("CONTENT_LENGTH")); coreutils::ZString contentLength(getenv("CONTENT_LENGTH"));
coreutils::ZString contentType(getenv("CONTENT_TYPE")); coreutils::ZString contentType(getenv("CONTENT_TYPE"));
if(contentType == "multipart/form-data") if(contentType == "multipart/form-data")
std::cout << "output multipart variables to global" << std::endl; std::cout << "output multipart variables to global" << std::endl;
else if(contentType == "application/x-www-form-urlencoded") else if(contentType == "application/x-www-form-urlencoded")

View File

@ -1,6 +1,7 @@
#include "__set.h" #include "__set.h"
#include "Exception.h" #include "Exception.h"
#include "Operand.h" #include "Operand.h"
#include "KeywordValue.h"
#include <iostream> #include <iostream>
namespace jet { namespace jet {
@ -20,7 +21,10 @@ namespace jet {
if(variableDefined("expr") && variableDefined("eval")) if(variableDefined("expr") && variableDefined("eval"))
throw coreutils::Exception("Cannot use eval with expr."); throw coreutils::Exception("Cannot use eval with expr.");
if(variableDefined("expr")) { resolveKeyword("name");
if(variableDefined("expr")) {
resolveKeyword("eval");
if(!variableDefined("scope") || (variables["scope"] == "global")) if(!variableDefined("scope") || (variables["scope"] == "global"))
global.variables[variables["name"]] = Operand(variables["expr"]).string; global.variables[variables["name"]] = Operand(variables["expr"]).string;
else if(variables["scope"] == "local") else if(variables["scope"] == "local")
@ -44,7 +48,8 @@ namespace jet {
else if(variables["scope"] == "parent") else if(variables["scope"] == "parent")
parent->parent->variables[variables["name"]] = container; parent->parent->variables[variables["name"]] = container;
} }
} else { } else {
resolveKeyword("value");
if(!variableDefined("scope") || (variables["scope"] == "global")) if(!variableDefined("scope") || (variables["scope"] == "global"))
global.variables[variables["name"]] = variables["value"]; global.variables[variables["name"]] = variables["value"];
else if(variables["scope"] == "local") else if(variables["scope"] == "local")

View File

@ -1,12 +1,10 @@
#!../jet-2.0 #!../jet-2.0
<jet filterblanklines="true" trimlines="true"> <set name="ix" value="1" />
<set name="ix" value="1" />
<set name="letterx" value="x" /> <set name="letterx" value="x" />
<set name="var1" value="this is a test" /> <set name="var$[ix]" value="this is a test $[ix]" />
<set name="1var1" value="This is another test" /> <set name="1var1" value="This is another test" />
<set name="var1var" value="Yet another test" /> <set name="var1var" value="Yet another test" />
<set name="var11" value="it seems to work." /> <set name="var11" value="it seems to work." />
$[$test]
$[$[ix]var$[ix]] $[$[ix]var$[ix]]
$[var$[ix]] $[var$[ix]]
$[var$[ix]var] $[var$[ix]var]
@ -14,4 +12,4 @@ $[var$[i$[letterx]]var]
$[letterx;TOHEX] $[letterx;TOHEX]
$[var$[i$[letterx]]$[ix]] $[var$[i$[letterx]]$[ix]]
$[var$[i$[letterx]]$[i$[letterx]]] $[var$[i$[letterx]]$[i$[letterx]]]
</jet>