diff --git a/Global.cpp b/Global.cpp index 2b18df2..012d763 100644 --- a/Global.cpp +++ b/Global.cpp @@ -59,15 +59,20 @@ namespace jet { throw coreutils::Exception("modifier not valid."); } - coreutils::MString Global::getVariable(coreutils::ZString &variable, std::map &lvariables) { + coreutils::MString Global::getVariable(coreutils::ZString &variable, + std::map &lvariables, + std::map &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 &lvariables) { + void Global::renderVariableName(coreutils::ZString &variable, + coreutils::MString &name, coreutils::MString &modifier, + std::map &lvariables, + std::map &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._-")) diff --git a/Global.h b/Global.h index 5d73d34..316e57a 100644 --- a/Global.h +++ b/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 &lvariables); - void renderVariableName(coreutils::ZString &variable, coreutils::MString &name, coreutils::MString &modifier, std::map &lvariables); + coreutils::MString getVariable(coreutils::ZString &variable, + std::map &lvariables, + std::map &keywords); + void renderVariableName(coreutils::ZString &variable, + coreutils::MString &name, + coreutils::MString &modifier, + std::map &lvariables, + std::map &keywords); __mysql * getSession(coreutils::MString sessionId); coreutils::ZString getSessionVariable(coreutils::MString &splitName); void outputHeaders(); diff --git a/KeywordValue.cpp b/KeywordValue.cpp index f30fa7f..5f5f882 100644 --- a/KeywordValue.cpp +++ b/KeywordValue.cpp @@ -3,10 +3,13 @@ namespace jet { - KeywordValue::KeywordValue(coreutils::ZString data, Global &global, std::map &variables) : MString() { + KeywordValue::KeywordValue(coreutils::ZString data, + Global &global, + std::map &variables, + std::map &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(); diff --git a/KeywordValue.h b/KeywordValue.h index 14402e8..98790e4 100644 --- a/KeywordValue.h +++ b/KeywordValue.h @@ -13,7 +13,9 @@ namespace jet { class KeywordValue : public coreutils::MString { public: - KeywordValue(coreutils::ZString data, Global &global, std::map &variables); + KeywordValue(coreutils::ZString data, Global &global, + std::map &variables, + std::map &keywords); virtual ~KeywordValue(); }; diff --git a/Operand.cpp b/Operand.cpp index 72595e5..1e1c64c 100644 --- a/Operand.cpp +++ b/Operand.cpp @@ -6,21 +6,24 @@ namespace jet { - Operand::Operand(coreutils::ZString &in, Global &global, std::map &lvariables) { + Operand::Operand(coreutils::ZString &in, + Global &global, + std::map &lvariables, + std::map &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); diff --git a/Operand.h b/Operand.h index d569e34..8e0a409 100644 --- a/Operand.h +++ b/Operand.h @@ -9,7 +9,10 @@ namespace jet { class Operand { public: - Operand(coreutils::ZString &in, Global &global, std::map &lvariables); + Operand(coreutils::ZString &in, + Global &global, + std::map &lvariables, + std::map &keywords); bool isNumber; diff --git a/Tag.cpp b/Tag.cpp index 444cc7d..a2c3578 100644 --- a/Tag.cpp +++ b/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()); } diff --git a/__cookie.cpp b/__cookie.cpp index a51665f..d5f1bf6 100644 --- a/__cookie.cpp +++ b/__cookie.cpp @@ -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) { diff --git a/__header.cpp b/__header.cpp index e583d21..b7fc588 100644 --- a/__header.cpp +++ b/__header.cpp @@ -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) { diff --git a/__if.cpp b/__if.cpp index b8f4f02..8707948 100644 --- a/__if.cpp +++ b/__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); diff --git a/__set.cpp b/__set.cpp index df9d7cb..c9d1f1f 100644 --- a/__set.cpp +++ b/__set.cpp @@ -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) { diff --git a/__until.cpp b/__until.cpp index 79ba915..09d9d98 100644 --- a/__until.cpp +++ b/__until.cpp @@ -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"]); diff --git a/__while.cpp b/__while.cpp index 4f17fe0..6f8a8fa 100644 --- a/__while.cpp +++ b/__while.cpp @@ -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"]); diff --git a/tests/dump.txt b/tests/dump.txt index aa366fb..9498a30 100644 --- a/tests/dump.txt +++ b/tests/dump.txt @@ -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] diff --git a/tests/testinclude.jet b/tests/testinclude.jet index 4724a8d..b9e87fe 100644 --- a/tests/testinclude.jet +++ b/tests/testinclude.jet @@ -1,6 +1,6 @@ -This is a container set with '#[name1]' +This is a container set with '$[%name1]' This is from an include tag. -localname='#[name1]' +localname='$[%name1]' test='#[testinclude]' diff --git a/tests/testjet.jet b/tests/testjet.jet index 0034cb6..96c6e86 100755 --- a/tests/testjet.jet +++ b/tests/testjet.jet @@ -3,7 +3,7 @@
This is a comment and should not show up in the output. - ---#[name1] + ---$[%name1] $[modified1;tohex] @@ -37,12 +37,12 @@ 5*3($[multiplication]) 5/3($[division]) - this is the value store in #[name1]. - this is the value store in #[name1]. + this is the value store in $[%name1]. + this is the value store in $[%name1]. another container value - + include: $[include] - localvar='#[localvar]' + localvar='#[localvar]' >>>$[noeval]<<< >>>$[thename]<<< diff --git a/tests/testvar.jet b/tests/testvar.jet index 61a5be6..ba457b0 100755 --- a/tests/testvar.jet +++ b/tests/testvar.jet @@ -1,6 +1,6 @@ #!../jet-2.0 - + test1=[$[test1]] @@ -8,7 +8,7 @@ test1=[$[test1]] -name1=[#[name1]] +name1=[$[%name1]] $[$[ix]var$[ix];tobinary] $[var$[ix]] $[var$[ix]var]