more sever scoping work.
This commit is contained in:
parent
07e43d3f5a
commit
ca7aabd73f
@ -63,7 +63,7 @@ namespace jet {
|
||||
return lastConverted;
|
||||
}
|
||||
|
||||
coreutils::ZString Global::getVariable(coreutils::ZString &variable, std::map<coreutils::ZString, coreutils::MString> &lvariables) {
|
||||
coreutils::ZString Global::getVariable(coreutils::ZString &variable, std::map<coreutils::MString, coreutils::MString> &lvariables) {
|
||||
if(variable.ifNext("$[")) {
|
||||
coreutils::MString name;
|
||||
coreutils::MString modifier;
|
||||
@ -99,7 +99,7 @@ namespace jet {
|
||||
throw coreutils::Exception("Expecting a variable initializer ('$[' or '#[').");
|
||||
}
|
||||
|
||||
void Global::renderVariableName(coreutils::ZString &variable, coreutils::MString &name, coreutils::MString &modifier, std::map<coreutils::ZString, coreutils::MString> &lvariables) {
|
||||
void Global::renderVariableName(coreutils::ZString &variable, coreutils::MString &name, coreutils::MString &modifier, std::map<coreutils::MString, coreutils::MString> &lvariables) {
|
||||
while(!variable.ifNext("]")) {
|
||||
name << variable.getTokenInclude("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789._-");
|
||||
if(variable.ifNext(";")) {
|
||||
|
4
Global.h
4
Global.h
@ -20,8 +20,8 @@ namespace jet {
|
||||
void addSession(coreutils::MString sessionId, __mysql *mysql);
|
||||
void removeSession(coreutils::MString sessionId);
|
||||
coreutils::MString& processModifier(coreutils::MString &value, coreutils::MString &modifier);
|
||||
coreutils::ZString getVariable(coreutils::ZString &variable, std::map<coreutils::ZString, coreutils::MString> &lvariables);
|
||||
void renderVariableName(coreutils::ZString &variable, coreutils::MString &name, coreutils::MString &modifier, std::map<coreutils::ZString, coreutils::MString> &lvariables);
|
||||
coreutils::ZString getVariable(coreutils::ZString &variable, std::map<coreutils::MString, coreutils::MString> &lvariables);
|
||||
void renderVariableName(coreutils::ZString &variable, coreutils::MString &name, coreutils::MString &modifier, std::map<coreutils::MString, coreutils::MString> &lvariables);
|
||||
__mysql * getSession(coreutils::MString sessionId);
|
||||
coreutils::ZString getSessionVariable(coreutils::MString &splitName);
|
||||
void outputHeaders();
|
||||
|
@ -3,7 +3,7 @@
|
||||
|
||||
namespace jet {
|
||||
|
||||
KeywordValue::KeywordValue(coreutils::ZString data, Global &global, std::map<coreutils::ZString, coreutils::MString> &variables) : MString() {
|
||||
KeywordValue::KeywordValue(coreutils::ZString data, Global &global, std::map<coreutils::MString, coreutils::MString> &variables) : MString() {
|
||||
while(!data.eod()) {
|
||||
if(data.startsWith("$[") || data.startsWith("#[")) {
|
||||
write(global.getVariable(data, variables));
|
||||
|
@ -13,7 +13,7 @@ namespace jet {
|
||||
class KeywordValue : public coreutils::MString {
|
||||
|
||||
public:
|
||||
KeywordValue(coreutils::ZString data, Global &global, std::map<coreutils::ZString, coreutils::MString> &variables);
|
||||
KeywordValue(coreutils::ZString data, Global &global, std::map<coreutils::MString, coreutils::MString> &variables);
|
||||
virtual ~KeywordValue();
|
||||
};
|
||||
|
||||
|
@ -6,7 +6,7 @@
|
||||
|
||||
namespace jet {
|
||||
|
||||
Operand::Operand(coreutils::ZString &in, Global &global, std::map<coreutils::ZString, coreutils::MString> &lvariables) {
|
||||
Operand::Operand(coreutils::ZString &in, Global &global, std::map<coreutils::MString, coreutils::MString> &lvariables) {
|
||||
|
||||
doubleValue = 0;
|
||||
|
||||
|
@ -9,7 +9,7 @@ namespace jet {
|
||||
class Operand {
|
||||
|
||||
public:
|
||||
Operand(coreutils::ZString &in, Global &global, std::map<coreutils::ZString, coreutils::MString> &lvariables);
|
||||
Operand(coreutils::ZString &in, Global &global, std::map<coreutils::MString, coreutils::MString> &lvariables);
|
||||
|
||||
bool isNumber;
|
||||
|
||||
|
8
Tag.cpp
8
Tag.cpp
@ -28,8 +28,8 @@
|
||||
|
||||
namespace jet {
|
||||
|
||||
Tag::Tag(coreutils::ZString &in, coreutils::MString &parentOut, Global &global, Tag *parent, coreutils::ZString splitTagName)
|
||||
: ZString(in), parentOut(parentOut), global(global), parent(parent) {
|
||||
Tag::Tag(coreutils::ZString &in, coreutils::MString &parentOut, Global &global, Tag *parent, Tag *local, coreutils::ZString splitTagName)
|
||||
: ZString(in), parentOut(parentOut), global(global), parent(parent), local(local) {
|
||||
this->splitTagName = splitTagName;
|
||||
global.errorCursor = in.getCursor();
|
||||
if(parent && in.ifNext("<")) {
|
||||
@ -145,7 +145,7 @@ namespace jet {
|
||||
__ifrow _ifrow(in, out, global, this);
|
||||
continue;
|
||||
} else if(ifTagName(in, "include")) {
|
||||
__include _include(in, out, global, parent);
|
||||
__include _include(in, out, global, this);
|
||||
continue;
|
||||
} else if(ifTagName(in, "jet")) {
|
||||
__jet _jet(in, out, global, this);
|
||||
@ -157,7 +157,7 @@ namespace jet {
|
||||
__write _write(in, out, global, this);
|
||||
continue;
|
||||
} else if(ifTagName(in, "set")) {
|
||||
__set _set(in, out, global, parent);
|
||||
__set _set(in, out, global, this);
|
||||
continue;
|
||||
} else if(ifTagName(in, "call")) {
|
||||
__call _call(in, out, global, this);
|
||||
|
5
Tag.h
5
Tag.h
@ -11,15 +11,16 @@ namespace jet {
|
||||
class Tag : public coreutils::ZString {
|
||||
|
||||
public:
|
||||
Tag(coreutils::ZString &in, coreutils::MString &parentOut, Global &global, Tag *parent = NULL, coreutils::ZString splitTagName = "");
|
||||
Tag(coreutils::ZString &in, coreutils::MString &parentOut, Global &global, Tag *parent = NULL, Tag *local = NULL, coreutils::ZString splitTagName = "");
|
||||
virtual ~Tag();
|
||||
|
||||
void resolveKeyword(coreutils::ZString keyword);
|
||||
std::map<coreutils::ZString, coreutils::MString> variables;
|
||||
std::map<coreutils::MString, coreutils::MString> variables;
|
||||
coreutils::ZString name;
|
||||
coreutils::ZString container;
|
||||
coreutils::ZString container2;
|
||||
Tag *parent;
|
||||
Tag *local;
|
||||
|
||||
protected:
|
||||
bool hasContainer;
|
||||
|
@ -9,7 +9,7 @@
|
||||
|
||||
namespace jet {
|
||||
|
||||
__call::__call(coreutils::ZString &in, coreutils::MString &parentOut, Global &global, Tag *parent) : Tag(in, parentOut, global, parent) {
|
||||
__call::__call(coreutils::ZString &in, coreutils::MString &parentOut, Global &global, Tag *parent) : Tag(in, parentOut, global, parent, parent) {
|
||||
if(hasContainer)
|
||||
throw coreutils::Exception("call tag cannot have a container.");
|
||||
if(!variableDefined("pgm"))
|
||||
|
@ -3,7 +3,7 @@
|
||||
|
||||
namespace jet {
|
||||
|
||||
__comment::__comment(coreutils::ZString &in, coreutils::MString &parentOut, Global &global, Tag *parent) : Tag(in, parentOut, global, parent) {
|
||||
__comment::__comment(coreutils::ZString &in, coreutils::MString &parentOut, Global &global, Tag *parent) : Tag(in, parentOut, global, parent, this) {
|
||||
if(!hasContainer)
|
||||
throw coreutils::Exception("comment must have a container.");
|
||||
output = false;
|
||||
|
@ -3,7 +3,7 @@
|
||||
|
||||
namespace jet {
|
||||
|
||||
__dotag::__dotag(coreutils::ZString &in, coreutils::MString &parentOut, Global &global, Tag *parent) : Tag(in, parentOut, global, parent) {
|
||||
__dotag::__dotag(coreutils::ZString &in, coreutils::MString &parentOut, Global &global, Tag *parent) : Tag(in, parentOut, global, parent, this) {
|
||||
if(hasContainer)
|
||||
parseContainer(container, containerOut);
|
||||
containerOut.reset();
|
||||
|
@ -5,7 +5,7 @@
|
||||
|
||||
namespace jet {
|
||||
|
||||
__dump::__dump(coreutils::ZString &in, coreutils::MString &parentOut, Global &global, Tag *parent) : Tag(in, parentOut, global, parent) {
|
||||
__dump::__dump(coreutils::ZString &in, coreutils::MString &parentOut, Global &global, Tag *parent) : Tag(in, parentOut, global, parent, this) {
|
||||
if(!variableDefined("file"))
|
||||
throw coreutils::Exception("file must be sppecified for dump tag.");
|
||||
|
||||
|
@ -4,7 +4,7 @@
|
||||
|
||||
namespace jet {
|
||||
|
||||
__for::__for(coreutils::ZString &in, coreutils::MString &parentOut, Global &global, Tag *parent) : Tag(in, parentOut, global, parent) {
|
||||
__for::__for(coreutils::ZString &in, coreutils::MString &parentOut, Global &global, Tag *parent) : Tag(in, parentOut, global, parent, this) {
|
||||
double counter = 0.0f;
|
||||
bool nameDefined = variableDefined("name");
|
||||
if(variableDefined("start")) {
|
||||
|
@ -5,7 +5,7 @@
|
||||
|
||||
namespace jet {
|
||||
|
||||
__header::__header(coreutils::ZString &in, coreutils::MString &parentOut, Global &global, Tag *parent) : Tag(in, parentOut, global, parent) {
|
||||
__header::__header(coreutils::ZString &in, coreutils::MString &parentOut, Global &global, Tag *parent) : Tag(in, parentOut, global, parent, parent) {
|
||||
output = false;
|
||||
if(!variableDefined("name"))
|
||||
throw coreutils::Exception("header tag must have name defined.");
|
||||
|
2
__if.cpp
2
__if.cpp
@ -5,7 +5,7 @@
|
||||
|
||||
namespace jet {
|
||||
|
||||
__if::__if(coreutils::ZString &in, coreutils::MString &parentOut, Global &global, Tag *parent) : Tag(in, parentOut, global, parent, "else") {
|
||||
__if::__if(coreutils::ZString &in, coreutils::MString &parentOut, Global &global, Tag *parent) : Tag(in, parentOut, global, parent, this, "else") {
|
||||
|
||||
coreutils::MString result;
|
||||
bool booleanResult = false;
|
||||
|
@ -7,7 +7,7 @@
|
||||
|
||||
namespace jet {
|
||||
|
||||
__ifrow::__ifrow(coreutils::ZString &in, coreutils::MString &parentOut, Global &global, Tag *parent) : Tag(in, parentOut, global, parent, "else") {
|
||||
__ifrow::__ifrow(coreutils::ZString &in, coreutils::MString &parentOut, Global &global, Tag *parent) : Tag(in, parentOut, global, parent, this, "else") {
|
||||
output = false;
|
||||
if(!hasContainer)
|
||||
throw coreutils::Exception("ifrow tag must have a container.");
|
||||
|
@ -4,8 +4,7 @@
|
||||
|
||||
namespace jet {
|
||||
|
||||
__include::__include(coreutils::ZString &in, coreutils::MString &parentOut, Global &global, Tag *parent) : Tag(in, parentOut, global, parent) {
|
||||
resolveContainerParent = true;
|
||||
__include::__include(coreutils::ZString &in, coreutils::MString &parentOut, Global &global, Tag *parent) : Tag(in, parentOut, global, parent, parent) {
|
||||
if(!variableDefined("file"))
|
||||
throw coreutils::Exception("file keyword must be specified.");
|
||||
if(hasContainer)
|
||||
|
@ -5,7 +5,7 @@
|
||||
|
||||
namespace jet {
|
||||
|
||||
__jet::__jet(coreutils::ZString &in, coreutils::MString &parentOut, Global &global, Tag *parent) : Tag(in, parentOut, global, parent) {
|
||||
__jet::__jet(coreutils::ZString &in, coreutils::MString &parentOut, Global &global, Tag *parent) : Tag(in, parentOut, global, parent, this) {
|
||||
if(variableDefined("cgi"))
|
||||
resolveKeyword("cgi");
|
||||
if(variables["cgi"] == "true") {
|
||||
|
@ -4,7 +4,7 @@
|
||||
|
||||
namespace jet {
|
||||
|
||||
__mysql::__mysql(coreutils::ZString &in, coreutils::MString &parentOut, Global &global, Tag *parent) : Tag(in, parentOut, global, parent) {
|
||||
__mysql::__mysql(coreutils::ZString &in, coreutils::MString &parentOut, Global &global, Tag *parent) : Tag(in, parentOut, global, parent, this) {
|
||||
|
||||
if(!variableDefined("host"))
|
||||
throw coreutils::Exception("host must be specified for mysql tag.");
|
||||
|
@ -6,7 +6,7 @@
|
||||
|
||||
namespace jet {
|
||||
|
||||
__read::__read(coreutils::ZString &in, coreutils::MString &parentOut, Global &global, Tag *parent) : Tag(in, parentOut, global, parent) {
|
||||
__read::__read(coreutils::ZString &in, coreutils::MString &parentOut, Global &global, Tag *parent) : Tag(in, parentOut, global, parent, this) {
|
||||
if(!variableDefined("file"))
|
||||
throw coreutils::Exception("file keyword must be specified.");
|
||||
if(!variableDefined("name"))
|
||||
|
18
__set.cpp
18
__set.cpp
@ -6,7 +6,7 @@
|
||||
|
||||
namespace jet {
|
||||
|
||||
__set::__set(coreutils::ZString &in, coreutils::MString &parentOut, Global &global, Tag *parent) : Tag(in, parentOut, global, parent) {
|
||||
__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.");
|
||||
@ -27,34 +27,34 @@ namespace jet {
|
||||
if(!variableDefined("scope") || (variables["scope"] == "global"))
|
||||
global.variables[variables["name"]] = Operand(variables["expr"], global, parent->variables).string;
|
||||
else if(variables["scope"] == "local")
|
||||
parent->variables[variables["name"]] = Operand(variables["expr"], global, parent->variables).string;
|
||||
local->variables[variables["name"]] = Operand(variables["expr"], global, parent->variables).string;
|
||||
else if(variables["scope"] == "parent")
|
||||
parent->parent->variables[variables["name"]] = Operand(variables["expr"], global, parent->variables).string;
|
||||
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")
|
||||
parent->variables[variables["name"]] = out;
|
||||
local->variables[variables["name"]] = out;
|
||||
else if(variables["scope"] == "parent")
|
||||
parent->parent->variables[variables["name"]] = out;
|
||||
local->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;
|
||||
local->variables[variables["name"]] = container;
|
||||
else if(variables["scope"] == "parent")
|
||||
parent->parent->variables[variables["name"]] = container;
|
||||
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")
|
||||
parent->variables[variables["name"]] = variables["value"];
|
||||
local->variables[variables["name"]] = variables["value"];
|
||||
else if(variables["scope"] == "parent")
|
||||
parent->parent->variables[variables["name"]] = variables["value"];
|
||||
local->parent->variables[variables["name"]] = variables["value"];
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -9,7 +9,7 @@
|
||||
|
||||
namespace jet {
|
||||
|
||||
__sql::__sql(coreutils::ZString &in, coreutils::MString &parentOut, Global &global, Tag *parent) : Tag(in, parentOut, global, parent) {
|
||||
__sql::__sql(coreutils::ZString &in, coreutils::MString &parentOut, Global &global, Tag *parent) : Tag(in, parentOut, global, parent, parent) {
|
||||
output = false;
|
||||
if(!hasContainer)
|
||||
throw coreutils::Exception("sql tag must have a container.");
|
||||
|
@ -3,7 +3,7 @@
|
||||
|
||||
namespace jet {
|
||||
|
||||
__stream::__stream(coreutils::ZString &in, coreutils::MString &parentOut, Global &global, Tag *parent) : Tag(in, parentOut, global, parent) {
|
||||
__stream::__stream(coreutils::ZString &in, coreutils::MString &parentOut, Global &global, Tag *parent) : Tag(in, parentOut, global, parent, this) {
|
||||
if(!variableDefined("name"))
|
||||
throw coreutils::Exception("stream tag must have a file name to stream.");
|
||||
|
||||
|
@ -8,7 +8,7 @@
|
||||
|
||||
namespace jet {
|
||||
|
||||
__system::__system(coreutils::ZString &in, coreutils::MString &parentOut, Global &global, Tag *parent) : Tag(in, parentOut, global, parent) {
|
||||
__system::__system(coreutils::ZString &in, coreutils::MString &parentOut, Global &global, Tag *parent) : Tag(in, parentOut, global, parent, parent) {
|
||||
if(hasContainer)
|
||||
throw coreutils::Exception("system tag cannot have a container.");
|
||||
if(!variableDefined(coreutils::ZString("cmd")))
|
||||
|
@ -3,7 +3,7 @@
|
||||
|
||||
namespace jet {
|
||||
|
||||
__tag::__tag(coreutils::ZString &in, coreutils::MString &parentOut, Global &global, Tag *parent) : Tag(in, parentOut, global, parent) {
|
||||
__tag::__tag(coreutils::ZString &in, coreutils::MString &parentOut, Global &global, Tag *parent) : Tag(in, parentOut, global, this) {
|
||||
evaluate = false;
|
||||
output = false;
|
||||
if(!variableDefined("name"))
|
||||
|
@ -5,7 +5,7 @@
|
||||
|
||||
namespace jet {
|
||||
|
||||
__until::__until(coreutils::ZString &in, coreutils::MString &parentOut, Global &global, Tag *parent) : Tag(in, parentOut, global, parent) {
|
||||
__until::__until(coreutils::ZString &in, coreutils::MString &parentOut, Global &global, Tag *parent) : Tag(in, parentOut, global, parent, this) {
|
||||
|
||||
coreutils::MString result;
|
||||
bool booleanResult = false;
|
||||
|
@ -5,7 +5,7 @@
|
||||
|
||||
namespace jet {
|
||||
|
||||
__while::__while(coreutils::ZString &in, coreutils::MString &parentOut, Global &global, Tag *parent) : Tag(in, parentOut, global, parent) {
|
||||
__while::__while(coreutils::ZString &in, coreutils::MString &parentOut, Global &global, Tag *parent) : Tag(in, parentOut, global, parent, this) {
|
||||
|
||||
coreutils::MString result;
|
||||
bool booleanResult = false;
|
||||
|
@ -8,7 +8,7 @@
|
||||
|
||||
namespace jet {
|
||||
|
||||
__whiledir::__whiledir(coreutils::ZString &in, coreutils::MString &parentOut, Global &global, Tag *parent) : Tag(in, parentOut, global, parent) {
|
||||
__whiledir::__whiledir(coreutils::ZString &in, coreutils::MString &parentOut, Global &global, Tag *parent) : Tag(in, parentOut, global, parent, this) {
|
||||
if(!variableDefined("path"))
|
||||
throw coreutils::Exception("whiledir tag must specify a path.");
|
||||
resolveKeyword("path");
|
||||
|
@ -7,7 +7,7 @@
|
||||
|
||||
namespace jet {
|
||||
|
||||
__write::__write(coreutils::ZString &in, coreutils::MString &parentOut, Global &global, Tag *parent) : Tag(in, parentOut, global, parent) {
|
||||
__write::__write(coreutils::ZString &in, coreutils::MString &parentOut, Global &global, Tag *parent) : Tag(in, parentOut, global, parent, this) {
|
||||
output = false;
|
||||
int mode = 0;
|
||||
int len;
|
||||
|
29
tests/dump.txt
Normal file
29
tests/dump.txt
Normal file
@ -0,0 +1,29 @@
|
||||
*** CGI VARIABLES ***
|
||||
*** GLOBAL VARIABLES ***
|
||||
=[xxx]
|
||||
addition=[8]
|
||||
complete=[ABCD;tohex]
|
||||
division=[1.666666666667]
|
||||
divisor=[8]
|
||||
error=[]
|
||||
include=[yes]
|
||||
ix=[1]
|
||||
lefty=[01234]
|
||||
modified1=[ABCD]
|
||||
multiplication=[15]
|
||||
nested=[64]
|
||||
newname=[another container value]
|
||||
noeval=[this is the value store in #[name1].]
|
||||
nonexistant=[]
|
||||
numbers=[0123456789]
|
||||
subtraction=[2]
|
||||
testinclude=[xThis is a container set with ''x]
|
||||
theexpr=[bcd]
|
||||
thename=[this is the value store in .]
|
||||
tohex=[tohex]
|
||||
varname1=[vardata]
|
||||
x=[]
|
||||
*** LOCAL VARIABLES ***
|
||||
file=[./testinclude.jet]
|
||||
localvar=[This is a container set with '']
|
||||
name1=[]
|
@ -4,3 +4,4 @@ localname='#[name1]'
|
||||
<set name="include" value="yes" />
|
||||
<set name="testinclude" value="x#[localvar]x" />
|
||||
test='$[testinclude]'
|
||||
<dump file="./dump.txt" />
|
@ -1,8 +1,10 @@
|
||||
#!../jet-2.0
|
||||
<jet cgi="true" name1="localname" filterblanklines="true" trimlines="true">
|
||||
<set name="name2" value="localname2" scope="local" />
|
||||
<set name="name3" value="global" />
|
||||
<set name="x" value="#[name1]" />
|
||||
localname=#[name1]
|
||||
localname2=#[name2]
|
||||
localname through x=$[x]
|
||||
<dump file="./dump.txt" />
|
||||
</jet>
|
||||
|
Loading…
x
Reference in New Issue
Block a user