Made $[%name] to retrieve keyword values in a tag. Has bugs.
This commit is contained in:
parent
9622b5cf8c
commit
f6dda8496c
28
Global.cpp
28
Global.cpp
@ -59,15 +59,20 @@ namespace jet {
|
||||
throw coreutils::Exception("modifier not valid.");
|
||||
}
|
||||
|
||||
coreutils::MString Global::getVariable(coreutils::ZString &variable, std::map<coreutils::MString, coreutils::MString> &lvariables) {
|
||||
coreutils::MString Global::getVariable(coreutils::ZString &variable,
|
||||
std::map<coreutils::MString, coreutils::MString> &lvariables,
|
||||
std::map<coreutils::MString, coreutils::MString> &keywords) {
|
||||
if(variable.ifNext("$[")) {
|
||||
coreutils::MString name;
|
||||
coreutils::MString modifier;
|
||||
if(variable.ifNext("!")) {
|
||||
renderVariableName(variable, name, modifier, lvariables);
|
||||
renderVariableName(variable, name, modifier, lvariables, keywords);
|
||||
return variables[name];
|
||||
} if(variable.ifNext(":")) {
|
||||
renderVariableName(variable, name, modifier, lvariables);
|
||||
} else if(variable.ifNext("%")) {
|
||||
renderVariableName(variable, name, modifier, lvariables, keywords);
|
||||
return keywords[name];
|
||||
} else if(variable.ifNext(":")) {
|
||||
renderVariableName(variable, name, modifier, lvariables, keywords);
|
||||
if(name.find(":") == -1) {
|
||||
name << ":0";
|
||||
}
|
||||
@ -75,10 +80,10 @@ namespace jet {
|
||||
} if(variable.ifNext("@")) {
|
||||
// TODO: should only allow session variables. Allow substitution.
|
||||
} if(variable.ifNext("%")) {
|
||||
renderVariableName(variable, name, modifier, lvariables);
|
||||
renderVariableName(variable, name, modifier, lvariables, keywords);
|
||||
return getenv(name.c_str());
|
||||
} else {
|
||||
renderVariableName(variable, name, modifier, lvariables);
|
||||
renderVariableName(variable, name, modifier, lvariables, keywords);
|
||||
name.split(".");
|
||||
if(name.getList().size() == 1) {
|
||||
if(variables.find(name[0]) == variables.end())
|
||||
@ -91,7 +96,7 @@ namespace jet {
|
||||
} if(variable.ifNext("#[")) {
|
||||
coreutils::MString name;
|
||||
coreutils::MString modifier;
|
||||
renderVariableName(variable, name, modifier, lvariables);
|
||||
renderVariableName(variable, name, modifier, lvariables, keywords);
|
||||
if(lvariables.find(name) == lvariables.end())
|
||||
throw coreutils::Exception("local variable is not initialized.");
|
||||
return lvariables[name];
|
||||
@ -99,16 +104,19 @@ 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::MString, coreutils::MString> &lvariables) {
|
||||
void Global::renderVariableName(coreutils::ZString &variable,
|
||||
coreutils::MString &name, coreutils::MString &modifier,
|
||||
std::map<coreutils::MString, coreutils::MString> &lvariables,
|
||||
std::map<coreutils::MString, coreutils::MString> &keywords) {
|
||||
while(!variable.ifNext("]")) {
|
||||
name << variable.getTokenInclude("?ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789._-");
|
||||
if(variable.ifNext(";")) {
|
||||
renderVariableName(variable, modifier, modifier, lvariables);
|
||||
renderVariableName(variable, modifier, modifier, lvariables, keywords);
|
||||
return;
|
||||
} else if(variable.ifNext(":")) {
|
||||
name << ":";
|
||||
} else if(variable.startsWith("$[") || variable.startsWith("#[")) {
|
||||
name << getVariable(variable, lvariables);
|
||||
name << getVariable(variable, lvariables, keywords);
|
||||
} else if(variable.ifNext("]"))
|
||||
return;
|
||||
else if(!variable.ifNextInclude("?ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789._-"))
|
||||
|
10
Global.h
10
Global.h
@ -19,8 +19,14 @@ namespace jet {
|
||||
void addSession(coreutils::MString sessionId, __mysql *mysql);
|
||||
void removeSession(coreutils::MString sessionId);
|
||||
coreutils::MString processModifier(coreutils::MString &value, coreutils::MString &modifier);
|
||||
coreutils::MString 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);
|
||||
coreutils::MString getVariable(coreutils::ZString &variable,
|
||||
std::map<coreutils::MString, coreutils::MString> &lvariables,
|
||||
std::map<coreutils::MString, coreutils::MString> &keywords);
|
||||
void renderVariableName(coreutils::ZString &variable,
|
||||
coreutils::MString &name,
|
||||
coreutils::MString &modifier,
|
||||
std::map<coreutils::MString, coreutils::MString> &lvariables,
|
||||
std::map<coreutils::MString, coreutils::MString> &keywords);
|
||||
__mysql * getSession(coreutils::MString sessionId);
|
||||
coreutils::ZString getSessionVariable(coreutils::MString &splitName);
|
||||
void outputHeaders();
|
||||
|
@ -3,10 +3,13 @@
|
||||
|
||||
namespace jet {
|
||||
|
||||
KeywordValue::KeywordValue(coreutils::ZString data, Global &global, std::map<coreutils::MString, coreutils::MString> &variables) : MString() {
|
||||
KeywordValue::KeywordValue(coreutils::ZString data,
|
||||
Global &global,
|
||||
std::map<coreutils::MString, coreutils::MString> &variables,
|
||||
std::map<coreutils::MString, coreutils::MString> &keywords) : MString() {
|
||||
while(!data.eod()) {
|
||||
if(data.startsWith("$[") || data.startsWith("#[")) {
|
||||
write(global.getVariable(data, variables));
|
||||
write(global.getVariable(data, variables, keywords));
|
||||
} else {
|
||||
write(data.charAt(0));
|
||||
data.nextChar();
|
||||
|
@ -13,7 +13,9 @@ namespace jet {
|
||||
class KeywordValue : public coreutils::MString {
|
||||
|
||||
public:
|
||||
KeywordValue(coreutils::ZString data, Global &global, std::map<coreutils::MString, coreutils::MString> &variables);
|
||||
KeywordValue(coreutils::ZString data, Global &global,
|
||||
std::map<coreutils::MString, coreutils::MString> &variables,
|
||||
std::map<coreutils::MString, coreutils::MString> &keywords);
|
||||
virtual ~KeywordValue();
|
||||
};
|
||||
|
||||
|
43
Operand.cpp
43
Operand.cpp
@ -6,21 +6,24 @@
|
||||
|
||||
namespace jet {
|
||||
|
||||
Operand::Operand(coreutils::ZString &in, Global &global, std::map<coreutils::MString, coreutils::MString> &lvariables) {
|
||||
Operand::Operand(coreutils::ZString &in,
|
||||
Global &global,
|
||||
std::map<coreutils::MString, coreutils::MString> &lvariables,
|
||||
std::map<coreutils::MString, coreutils::MString> &keywords) {
|
||||
|
||||
doubleValue = 0;
|
||||
|
||||
in.skipWhitespace();
|
||||
|
||||
if(in.startsWith("$[") || in.startsWith("#[")) {
|
||||
string = global.getVariable(in, lvariables);
|
||||
string = global.getVariable(in, lvariables, keywords);
|
||||
doubleValue = string.asDouble();
|
||||
isNumber = string.eod();
|
||||
string.reset();
|
||||
if((string == "false") || (string == "true"))
|
||||
boolean = true;
|
||||
} else if(in.ifNext("(")) {
|
||||
Operand op(in, global, lvariables);
|
||||
Operand op(in, global, lvariables, keywords);
|
||||
string = op.string;
|
||||
doubleValue = op.doubleValue;
|
||||
if(!in.ifNext(")"))
|
||||
@ -28,15 +31,15 @@ namespace jet {
|
||||
} else if(in.ifNextIgnoreCase("SUBSTRING")) {
|
||||
if(!in.ifNext("("))
|
||||
throw coreutils::Exception("Expecting ( for SUBSTRING parameters.");
|
||||
Operand parm1(in, global, lvariables);
|
||||
Operand parm1(in, global, lvariables, keywords);
|
||||
if(!in.ifNext(","))
|
||||
throw coreutils::Exception("Expecting , in SUBSTRING expression.");
|
||||
Operand parm2(in, global, lvariables);
|
||||
Operand parm2(in, global, lvariables, keywords);
|
||||
if(in.ifNext(")")) {
|
||||
string = parm1.string.substring(parm2.string.asInteger());
|
||||
} else if(!in.ifNext(","))
|
||||
throw coreutils::Exception("Expecting , in SUBSTRING expression.");
|
||||
Operand parm3(in, global, lvariables);
|
||||
Operand parm3(in, global, lvariables, keywords);
|
||||
if(in.ifNext(")")) {
|
||||
string = parm1.string.substring(parm2.string.asInteger(), parm3.string.asInteger());
|
||||
} else
|
||||
@ -44,10 +47,10 @@ namespace jet {
|
||||
} else if(in.ifNextIgnoreCase("LEFT")) {
|
||||
if(!in.ifNext("("))
|
||||
throw coreutils::Exception("Expecting ( for LEFT parameters.");
|
||||
Operand parm1(in, global, lvariables);
|
||||
Operand parm1(in, global, lvariables, keywords);
|
||||
if(!in.ifNext(","))
|
||||
throw coreutils::Exception("Expecting , in LEFT expression.");
|
||||
Operand parm2(in, global, lvariables);
|
||||
Operand parm2(in, global, lvariables, keywords);
|
||||
if(in.ifNext(")")) {
|
||||
string = parm1.string.substring(0, parm2.string.asInteger());
|
||||
} else
|
||||
@ -55,9 +58,9 @@ namespace jet {
|
||||
} else if(in.ifNextIgnoreCase("EXPR")) {
|
||||
if(!in.ifNext("("))
|
||||
throw coreutils::Exception("Expecting ( for EXPR parameters.");
|
||||
Operand parm1(in, global, lvariables);
|
||||
Operand parm1(in, global, lvariables, keywords);
|
||||
if(in.ifNext(")")) {
|
||||
Operand op(parm1.string, global, lvariables);
|
||||
Operand op(parm1.string, global, lvariables, keywords);
|
||||
string = op.string;
|
||||
isNumber = op.isNumber;
|
||||
boolean = op.boolean;
|
||||
@ -105,7 +108,7 @@ namespace jet {
|
||||
in.skipWhitespace();
|
||||
|
||||
if(in.ifNext("!=") || in.ifNext("<>")) {
|
||||
Operand op(in, global, lvariables);
|
||||
Operand op(in, global, lvariables, keywords);
|
||||
if(isNumber && op.isNumber) {
|
||||
if(doubleValue != op.doubleValue) {
|
||||
boolean = true;
|
||||
@ -129,7 +132,7 @@ namespace jet {
|
||||
}
|
||||
}
|
||||
if(in.ifNext("<=")) {
|
||||
Operand op(in, global, lvariables);
|
||||
Operand op(in, global, lvariables, keywords);
|
||||
if(isNumber && op.isNumber) {
|
||||
if(doubleValue <= op.doubleValue) {
|
||||
boolean = true;
|
||||
@ -153,7 +156,7 @@ namespace jet {
|
||||
}
|
||||
}
|
||||
if(in.ifNext(">=")) {
|
||||
Operand op(in, global, lvariables);
|
||||
Operand op(in, global, lvariables, keywords);
|
||||
if(isNumber && op.isNumber) {
|
||||
if(doubleValue >= op.doubleValue) {
|
||||
boolean = true;
|
||||
@ -177,7 +180,7 @@ namespace jet {
|
||||
}
|
||||
}
|
||||
if(in.ifNext("=")) {
|
||||
Operand op(in, global, lvariables);
|
||||
Operand op(in, global, lvariables, keywords);
|
||||
if(isNumber && op.isNumber) {
|
||||
if(doubleValue == op.doubleValue) {
|
||||
boolean = true;
|
||||
@ -201,7 +204,7 @@ namespace jet {
|
||||
}
|
||||
}
|
||||
if(in.ifNext("<")) {
|
||||
Operand op(in, global, lvariables);
|
||||
Operand op(in, global, lvariables, keywords);
|
||||
if(isNumber && op.isNumber) {
|
||||
if(doubleValue < op.doubleValue) {
|
||||
boolean = true;
|
||||
@ -225,7 +228,7 @@ namespace jet {
|
||||
}
|
||||
}
|
||||
if(in.ifNext(">")) {
|
||||
Operand op(in, global, lvariables);
|
||||
Operand op(in, global, lvariables, keywords);
|
||||
if(isNumber && op.isNumber) {
|
||||
if(doubleValue > op.doubleValue) {
|
||||
boolean = true;
|
||||
@ -250,7 +253,7 @@ namespace jet {
|
||||
}
|
||||
if(in.ifNext("+")) {
|
||||
if(isNumber) {
|
||||
Operand op(in, global, lvariables);
|
||||
Operand op(in, global, lvariables, keywords);
|
||||
if(op.isNumber) {
|
||||
doubleValue += op.doubleValue;
|
||||
string = std::format("{:.12f}", doubleValue);
|
||||
@ -261,7 +264,7 @@ namespace jet {
|
||||
throw coreutils::Exception("operand is not a number.");
|
||||
} else if(in.ifNext("-")) {
|
||||
if(isNumber) {
|
||||
Operand op(in, global, lvariables);
|
||||
Operand op(in, global, lvariables, keywords);
|
||||
if(op.isNumber) {
|
||||
doubleValue -= op.doubleValue;
|
||||
string = std::format("{:.12f}", doubleValue);
|
||||
@ -272,7 +275,7 @@ namespace jet {
|
||||
throw coreutils::Exception("operand is not a number.");
|
||||
} else if(in.ifNext("*")) {
|
||||
if(isNumber) {
|
||||
Operand op(in, global, lvariables);
|
||||
Operand op(in, global, lvariables, keywords);
|
||||
if(op.isNumber) {
|
||||
doubleValue *= op.doubleValue;
|
||||
string = std::format("{:.12f}", doubleValue);
|
||||
@ -283,7 +286,7 @@ namespace jet {
|
||||
throw coreutils::Exception("operand is not a number.");
|
||||
} else if(in.ifNext("/")) {
|
||||
if(isNumber) {
|
||||
Operand op(in, global, lvariables);
|
||||
Operand op(in, global, lvariables, keywords);
|
||||
if(op.isNumber) {
|
||||
doubleValue /= op.doubleValue;
|
||||
string = std::format("{:.12f}", doubleValue);
|
||||
|
@ -9,7 +9,10 @@ namespace jet {
|
||||
class Operand {
|
||||
|
||||
public:
|
||||
Operand(coreutils::ZString &in, Global &global, std::map<coreutils::MString, coreutils::MString> &lvariables);
|
||||
Operand(coreutils::ZString &in,
|
||||
Global &global,
|
||||
std::map<coreutils::MString, coreutils::MString> &lvariables,
|
||||
std::map<coreutils::MString, coreutils::MString> &keywords);
|
||||
|
||||
bool isNumber;
|
||||
|
||||
|
4
Tag.cpp
4
Tag.cpp
@ -111,7 +111,7 @@ namespace jet {
|
||||
}
|
||||
|
||||
void Tag::resolveKeyword(coreutils::ZString keyword) {
|
||||
keywords[keyword] = KeywordValue(keywords[keyword], global, parent->local->variables);
|
||||
keywords[keyword] = KeywordValue(keywords[keyword], global, parent->local->variables, keywords);
|
||||
}
|
||||
|
||||
void Tag::processContainer(coreutils::ZString &container) {
|
||||
@ -206,7 +206,7 @@ namespace jet {
|
||||
}
|
||||
} else if(in.startsWith("$[") || in.startsWith("#[")) {
|
||||
global.errorCursor = in.getCursor();
|
||||
out.write(global.getVariable(in, local->variables));
|
||||
out.write(global.getVariable(in, local->variables, keywords));
|
||||
} else {
|
||||
out.write(in.nextChar());
|
||||
}
|
||||
|
@ -22,7 +22,7 @@ namespace jet {
|
||||
if(keywordDefined("expr")) {
|
||||
if(keywordDefined("eval"))
|
||||
throw coreutils::Exception("Cannot use eval with expr.");
|
||||
global.headers[keywords["name"]] = Operand(keywords["expr"], global, parent->variables).string;
|
||||
global.headers[keywords["name"]] = Operand(keywords["expr"], global, parent->variables, keywords).string;
|
||||
} else if(hasContainer) {
|
||||
processContainer(container);
|
||||
if(evaluate) {
|
||||
|
@ -21,7 +21,7 @@ namespace jet {
|
||||
if(keywordDefined("expr")) {
|
||||
if(keywordDefined("eval"))
|
||||
throw coreutils::Exception("Cannot use eval with expr.");
|
||||
global.headers[keywords["name"]] = Operand(keywords["expr"], global, parent->variables).string;
|
||||
global.headers[keywords["name"]] = Operand(keywords["expr"], global, parent->variables, keywords).string;
|
||||
} else if(hasContainer) {
|
||||
processContainer(container);
|
||||
if(evaluate) {
|
||||
|
2
__if.cpp
2
__if.cpp
@ -34,7 +34,7 @@ namespace jet {
|
||||
throw coreutils::Exception("value2 should not be specified with expr.");
|
||||
if(keywordDefined("type"))
|
||||
throw coreutils::Exception("type should not be specified with expr.");
|
||||
booleanResult = Operand(keywords["expr"], global, parent->variables).boolean;
|
||||
booleanResult = Operand(keywords["expr"], global, parent->variables, keywords).boolean;
|
||||
}
|
||||
if(booleanResult)
|
||||
processContainer(container);
|
||||
|
@ -25,11 +25,11 @@ namespace jet {
|
||||
|
||||
if(keywordDefined("expr")) {
|
||||
if(!keywordDefined("scope") || (keywords["scope"] == "global"))
|
||||
global.variables[keywords["name"]] = Operand(keywords["expr"], global, parent->variables).string;
|
||||
global.variables[keywords["name"]] = Operand(keywords["expr"], global, parent->variables, keywords).string;
|
||||
else if(keywords["scope"] == "local")
|
||||
local->variables[keywords["name"]] = Operand(keywords["expr"], global, parent->variables).string;
|
||||
local->variables[keywords["name"]] = Operand(keywords["expr"], global, parent->variables, keywords).string;
|
||||
else if(keywords["scope"] == "parent")
|
||||
local->parent->variables[keywords["name"]] = Operand(keywords["expr"], global, parent->variables).string;
|
||||
local->parent->variables[keywords["name"]] = Operand(keywords["expr"], global, parent->variables, keywords).string;
|
||||
} else if(hasContainer) {
|
||||
processContainer(container);
|
||||
if(evaluate) {
|
||||
|
@ -47,7 +47,7 @@ namespace jet {
|
||||
keywords["expr"].reset();
|
||||
keywords["expr"] = exprSaved;
|
||||
resolveKeyword("expr");
|
||||
booleanResult = Operand(keywords["expr"], global, parent->variables).boolean;
|
||||
booleanResult = Operand(keywords["expr"], global, parent->variables, keywords).boolean;
|
||||
} else {
|
||||
booleanResult = false;
|
||||
int rc = keywords["value1"].compare(keywords["value2"]);
|
||||
|
@ -39,7 +39,7 @@ namespace jet {
|
||||
throw coreutils::Exception("type should not be specified with expr.");
|
||||
exprMethod = true;
|
||||
exprSaved = keywords["expr"];
|
||||
booleanResult = Operand(keywords["expr"], global, parent->variables).boolean;
|
||||
booleanResult = Operand(keywords["expr"], global, parent->variables, keywords).boolean;
|
||||
}
|
||||
while(booleanResult) {
|
||||
processContainer(container);
|
||||
@ -47,7 +47,7 @@ namespace jet {
|
||||
if(exprMethod) {
|
||||
keywords["expr"].reset();
|
||||
keywords["expr"] = exprSaved;
|
||||
booleanResult = Operand(keywords["expr"], global, parent->variables).boolean;
|
||||
booleanResult = Operand(keywords["expr"], global, parent->variables, keywords).boolean;
|
||||
} else {
|
||||
booleanResult = false;
|
||||
int rc = keywords["value1"].compare(keywords["value2"]);
|
||||
|
@ -14,17 +14,13 @@ modified1=[ABCD]
|
||||
multiplication=[15]
|
||||
nested=[64]
|
||||
newname=[another container value]
|
||||
noeval=[this is the value store in #[name1].]
|
||||
noeval=[this is the value store in $[%name1].]
|
||||
numbers=[0123456789]
|
||||
subtraction=[2]
|
||||
theexpr=[bcd]
|
||||
thename=[this is the value store in localname.]
|
||||
thename=[this is the value store in .]
|
||||
tohex=[tohex]
|
||||
varname1=[vardata]
|
||||
*** LOCAL VARIABLES ***
|
||||
cgi=[true]
|
||||
filterblanklines=[true]
|
||||
localvar=[This is a container set with 'localname']
|
||||
name1=[localname]
|
||||
testinclude=[xThis is a container set with 'localname'x]
|
||||
trimlines=[true]
|
||||
localvar=[This is a container set with '']
|
||||
testinclude=[xThis is a container set with ''x]
|
||||
|
@ -1,6 +1,6 @@
|
||||
<set name="localvar" scope="local">This is a container set with '#[name1]'</set>
|
||||
<set name="localvar" scope="local">This is a container set with '$[%name1]'</set>
|
||||
This is from an include tag.
|
||||
localname='#[name1]'
|
||||
localname='$[%name1]'
|
||||
<set name="include" value="yes" />
|
||||
<set name="testinclude" value="x#[localvar]x" scope="local" />
|
||||
test='#[testinclude]'
|
||||
|
@ -3,7 +3,7 @@
|
||||
<header name="Content-Type" value="text/html" />
|
||||
<comment>This is a comment and should not show up in the output.</comment>
|
||||
<html>
|
||||
---#[name1]
|
||||
---$[%name1]
|
||||
<set name="modified1" value="ABCD" />
|
||||
$[modified1;tohex]
|
||||
<set name="tohex" value="tohex" />
|
||||
@ -37,12 +37,12 @@
|
||||
5*3($[multiplication])
|
||||
5/3($[division])
|
||||
<set name="varname$[ix]" value="vardata" scope="global" />
|
||||
<set name="noeval" eval="no">this is the value store in #[name1].</set>
|
||||
<set name="thename" eval="yes">this is the value store in #[name1].</set>
|
||||
<set name="noeval" eval="no">this is the value store in $[%name1].</set>
|
||||
<set name="thename" eval="yes">this is the value store in $[%name1].</set>
|
||||
<set name="newname" scope="global">another container value</set>
|
||||
<include file="./testinclude.jet" />
|
||||
<comment><include file="./testinclude.jet" />
|
||||
include: $[include]
|
||||
localvar='#[localvar]'
|
||||
localvar='#[localvar]'</comment>
|
||||
>>>$[noeval]<<<
|
||||
>>>$[thename]<<<
|
||||
<set name="iz" value="data" />
|
||||
|
@ -1,6 +1,6 @@
|
||||
#!../jet-2.0
|
||||
<jet name1="localhost" filterblanklines="true" trimlines="true">
|
||||
<set name="test1" value="#[name1]" />
|
||||
<set name="test1" value="$[%name1]" />
|
||||
test1=[$[test1]]
|
||||
<set name="ix" value="1" />
|
||||
<set name="letterx" value="x" />
|
||||
@ -8,7 +8,7 @@ test1=[$[test1]]
|
||||
<set name="1var1" value="This is another test" />
|
||||
<set name="var1var" value="Yet another test" />
|
||||
<set name="var11" value="it seems to work." />
|
||||
name1=[#[name1]]
|
||||
name1=[$[%name1]]
|
||||
$[$[ix]var$[ix];tobinary]
|
||||
$[var$[ix]]
|
||||
$[var$[ix]var]
|
||||
|
Loading…
x
Reference in New Issue
Block a user