diff --git a/Expression.cpp b/Expression.cpp index ec98ee0..bb0aede 100644 --- a/Expression.cpp +++ b/Expression.cpp @@ -3,20 +3,22 @@ namespace jet { - Expression::Expression(coreutils::ZString &expression) : MString("zzz") { + Expression::Expression(coreutils::ZString &expression) : MString() { std::cout << "Expression construction:" << expression << std::endl; -// if(expression.equals("true")) -// MString("true"); -// else if(expression.equals("false")) -// MString("false"); -// else if(expression.equals("")) -// MString("false"); -// else -// MString("true"); + + if(isNumber(0, expression)) { + + } else if(expression.equals("true")) + write(expression); + else if(expression.equals("false")) + write(expression); } - Expression::~Expression() { - std::cout << "Expression destruction:" << getLength() << std::endl; - } + Expression::~Expression() {} + bool Expression::isNumber(int reg, coreutils::ZString &expression) { + + return false; + } + } diff --git a/Expression.h b/Expression.h index 3a6e508..1aeabad 100644 --- a/Expression.h +++ b/Expression.h @@ -10,6 +10,9 @@ namespace jet { public: Expression(coreutils::ZString &expression); virtual ~Expression(); + + private: + bool isNumber(int reg, coreutils::ZString &expression); }; } diff --git a/KeywordValue.cpp b/KeywordValue.cpp index 0ef32ae..9b245eb 100644 --- a/KeywordValue.cpp +++ b/KeywordValue.cpp @@ -3,12 +3,19 @@ namespace jet { - KeywordValue::KeywordValue(coreutils::ZString &data) { - + KeywordValue::KeywordValue(coreutils::ZString data, Global &global) : MString() { + while(!data.eod()) { + if(data.ifNext("$[")) { + coreutils::ZString varName(data.getTokenExclude("]")); + data.ifNext("]"); + write(global.variables[varName]); + } else { + write(data.charAt(0)); + data.nextChar(); + } + } } - KeywordValue::~KeywordValue() { - std::cout << "KeywordValue destruction: " << getLength() << std::endl; - } + KeywordValue::~KeywordValue() {} } diff --git a/KeywordValue.h b/KeywordValue.h index 343278f..3b98484 100644 --- a/KeywordValue.h +++ b/KeywordValue.h @@ -2,17 +2,18 @@ #define __KeywordValue_h__ #include "MString.h" +#include "Global.h" namespace jet { /// - /// KeywordValue will read the data ZString until a double quote (") is reached. + /// KeywordValue will read the data ZString and convert any variable references. /// class KeywordValue : public coreutils::MString { public: - KeywordValue(coreutils::ZString &data); + KeywordValue(coreutils::ZString data, Global &global); virtual ~KeywordValue(); }; diff --git a/Tag.cpp b/Tag.cpp index 550e41b..974d57d 100644 --- a/Tag.cpp +++ b/Tag.cpp @@ -1,5 +1,6 @@ #include "Tag.h" #include "Exception.h" +#include "KeywordValue.h" #include "Log.h" #include "__mysql.h" #include "__for.h" @@ -12,8 +13,9 @@ namespace jet { - Tag::Tag(coreutils::ZString &in, coreutils::MString &parent, Global &global) + Tag::Tag(coreutils::ZString &in, coreutils::MString &parent, Global &global, coreutils::ZString splitTagName) : ZString(in), parent(parent), global(global) { + this->splitTagName = splitTagName; if(in.ifNext("<")) { name = in.getTokenInclude("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_!"); if(in.startsWith(" ") || in.startsWith("/") || in.startsWith(">")) { @@ -23,38 +25,54 @@ namespace jet { in.skipWhitespace(); if(in.ifNext(">")) { hasContainer = true; + hasContainer2 = false; finished = true; break; } else if(in.ifNext("/>")) { hasContainer = false; + hasContainer2 = false; finished = true; break; } if(!finished) { coreutils::ZString keywordName = in.getTokenInclude("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_"); if(in.ifNext("=\"")) { - variables[keywordName] = in.getTokenExclude("\""); + variables[keywordName] = KeywordValue(in.getTokenExclude("\""), global); } if(!in.ifNext("\"")) {} } } if(hasContainer) { coreutils::Log(coreutils::LOG_DEBUG_2) << "has Container: " << hasContainer; + bool hasSplitTag = splitTagName == "" ? false: true; char *start = in.getCursor(); - while(!in.eod()) { - char *end = in.getCursor(); + while(!in.eod()) { + char *end = in.getCursor(); if(ifEndTagName(in)) { - container = coreutils::ZString(start, end - start); - coreutils::Log(coreutils::LOG_DEBUG_2) << "Container: [" << container << "]"; + if(hasContainer2) + container2 = coreutils::ZString(start, end - start); + else + container = coreutils::ZString(start, end - start); break; - } else if(ifNested(in)) {} - else + } else if(hasSplitTag && ifSplitTagName(in)) { + hasContainer2 = true; + container = coreutils::ZString(start, end - start); + in.ifNext(""); + start = in.getCursor(); + } else if(ifNested(in)) { + } else in.nextChar(); } } setZString(in.parsed()); - if(hasContainer && evaluate) - parseContainer(container); + if(variableDefined("eval")) { + if(variables["eval"] == "yes") { + evaluate = true; + } else if(variables["eval"] == "no") { + evaluate = false; + } else + throw coreutils::Exception("Keyword 'eval' must be 'yes' or 'no'."); + } } } else throw coreutils::Exception("First character of (in) must be a <."); @@ -67,9 +85,13 @@ namespace jet { else if(output) copyContainer(container, parent); - std::cout << "Destructing " << name << std::endl; } - + + void Tag::processContainer(coreutils::ZString &container) { + if(hasContainer && evaluate) + parseContainer(container); + } + void Tag::parseContainer(coreutils::ZString &in) { char *start = in.getCursor(); while(!in.eod()) { @@ -95,10 +117,26 @@ namespace jet { } else if(ifTagName(in, "while")) { __while _while(in, out, global); continue; - } - } - out.write(in.charAt(0)); - in.nextChar(); + } else { + out.write(in.charAt(0)); + in.nextChar(); + } + } else if(in.ifNext("#[")) { + coreutils::MString varName = in.getTokenInclude("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_"); + if(in.ifNext("]")) + out.write(variables[varName]); + else + throw coreutils::Exception("Local variable name has a syntax error."); + } else if(in.ifNext("$[")) { + coreutils::MString varName = in.getTokenInclude("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_"); + if(in.ifNext("]")) + out.write(global.variables[varName]); + else + throw coreutils::Exception("Global variable name has a syntax error."); + } else { + out.write(in.charAt(0)); + in.nextChar(); + } } } @@ -161,6 +199,18 @@ namespace jet { in.pop(); return false; } + + bool Tag::ifSplitTagName(coreutils::ZString &in) { + in.push(); + if(in.ifNext("<")) + if(in.getTokenInclude("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_").equals(splitTagName)) { + if(in.ifNext(">")) + in.pop(); + return true; + } + in.pop(); + return false; + } int Tag::skipBlankLine(coreutils::ZString in) { ZString temp = in.getTokenInclude(" \t"); diff --git a/Tag.h b/Tag.h index 9be072d..8aebee6 100644 --- a/Tag.h +++ b/Tag.h @@ -11,18 +11,23 @@ namespace jet { class Tag : public coreutils::ZString { public: - Tag(coreutils::ZString &in, coreutils::MString &parent, Global &global); + Tag(coreutils::ZString &in, coreutils::MString &parent, Global &global, coreutils::ZString splitTagName = ""); virtual ~Tag(); coreutils::ZString name; coreutils::ZString container; + coreutils::ZString container2; protected: bool hasContainer; + bool hasContainer2; std::map variables; bool variableDefined(coreutils::ZString variable); void parseContainer(coreutils::ZString &in); + void processContainer(coreutils::ZString &container); void copyContainer(coreutils::ZString &in, coreutils::MString &out); + coreutils::MString out; + bool output = true; bool evaluate = true; bool filterBlankLines = false; @@ -32,7 +37,7 @@ namespace jet { private: Global &global; coreutils::MString &parent; - coreutils::MString out; + coreutils::ZString splitTagName; int skipBlankLine(coreutils::ZString in); @@ -41,6 +46,7 @@ namespace jet { bool ifTagName(coreutils::ZString &in, const char *tag); bool ifTagName(coreutils::ZString &in); bool ifEndTagName(coreutils::ZString &in); + bool ifSplitTagName(coreutils::ZString &in); }; diff --git a/__for.cpp b/__for.cpp index 81d114e..9ef4b13 100644 --- a/__for.cpp +++ b/__for.cpp @@ -5,15 +5,29 @@ namespace jet { __for::__for(coreutils::ZString &in, coreutils::MString &out, Global &global) : Tag(in, out, global) { - if(!variableDefined(coreutils::ZString("begin"))) - throw coreutils::Exception("begin keyword must be specified."); - if(!variableDefined(coreutils::ZString("end"))) - throw coreutils::Exception("end keyword must be specified."); - - for(;;) { - parseContainer(container); + double counter = 0.0f; + double end = 0.0f; + double step = 0.0f; + bool nameDefined = variableDefined("name"); + if(variableDefined(coreutils::ZString("start"))) { + counter = variables["start"].asDouble(); } - + if(variableDefined(coreutils::ZString("end"))) { + end = variables["end"].asDouble(); + } + if(variableDefined(coreutils::ZString("step"))) { + step = variables["step"].asDouble(); + } + for(double ix = counter; ix <= end; ix += step) { + if(nameDefined) + variables[variables["name"]] = ix; + processContainer(container); + container.reset(); + } + +// for (auto i = variables.begin(); i != variables.end(); i++) +// std::cout << i->first << "=[" << i->second << "]" << std::endl;} + } - + } diff --git a/__for.h b/__for.h index 3fa23e7..b20d6a1 100644 --- a/__for.h +++ b/__for.h @@ -9,7 +9,7 @@ namespace jet { class __for : public Tag { public: - __for(coreutils::ZString &in, coreutils::MString &out, Global &global); + __for(coreutils::ZString &in, coreutils::MString &parent, Global &global); }; diff --git a/__if.cpp b/__if.cpp index 403f3dc..cb8e2a5 100644 --- a/__if.cpp +++ b/__if.cpp @@ -1,3 +1,4 @@ + #include "__if.h" #include "Exception.h" #include @@ -5,7 +6,7 @@ namespace jet { - __if::__if(coreutils::ZString &in, coreutils::MString &out, Global &global) : Tag(in, out, global) { + __if::__if(coreutils::ZString &in, coreutils::MString &parent, Global &global) : Tag(in, parent, global, "else") { coreutils::MString result; @@ -14,7 +15,7 @@ namespace jet { throw coreutils::Exception("Either value1 or expr can be specified but not both."); if(variableDefined("value2")) { if(variableDefined("type")) { - + result = "true"; } else throw coreutils::Exception("type expected if value1 and value2 specified."); } else @@ -25,13 +26,13 @@ namespace jet { if(variableDefined("type")) throw coreutils::Exception("type should not be specified with expr."); result = Expression(variables["expr"]); - std::cout << "result1: " << result << std::endl; } - std::cout << "result2: " << result << std::endl; - if(result.boolValue()) { - parseContainer(container); - } - + if(result.boolValue()) + processContainer(container); + else + if(hasContainer2) + processContainer(container2); + } } diff --git a/__if.h b/__if.h index 8d844d4..0d0ee1b 100644 --- a/__if.h +++ b/__if.h @@ -11,7 +11,7 @@ namespace jet { class __if : public Tag { public: - __if(coreutils::ZString &in, coreutils::MString &out, Global &global); + __if(coreutils::ZString &in, coreutils::MString &parent, Global &global); }; diff --git a/__jet.cpp b/__jet.cpp index b6ca688..da46c16 100644 --- a/__jet.cpp +++ b/__jet.cpp @@ -3,8 +3,8 @@ namespace jet { - __jet::__jet(coreutils::ZString &in, coreutils::MString &out, Global &global) : Tag(in, out, global) { - parseContainer(container); + __jet::__jet(coreutils::ZString &in, coreutils::MString &parent, Global &global) : Tag(in, parent, global) { + processContainer(container); } - } + diff --git a/__jet.h b/__jet.h index 87f6e37..b277cf0 100644 --- a/__jet.h +++ b/__jet.h @@ -10,7 +10,7 @@ namespace jet { class __jet : public Tag { public: - __jet(coreutils::ZString &in, coreutils::MString &out, Global &global); + __jet(coreutils::ZString &in, coreutils::MString &parent, Global &global); }; diff --git a/__mysql.cpp b/__mysql.cpp index 2ad9c38..ea1b380 100644 --- a/__mysql.cpp +++ b/__mysql.cpp @@ -3,8 +3,8 @@ namespace jet { - __mysql::__mysql(coreutils::ZString &in, coreutils::MString &out, Global &global) : Tag(in, out, global) { - parseContainer(container); + __mysql::__mysql(coreutils::ZString &in, coreutils::MString &parent, Global &global) : Tag(in, parent, global) { + processContainer(container); } } diff --git a/__mysql.h b/__mysql.h index 086a922..a51f15b 100644 --- a/__mysql.h +++ b/__mysql.h @@ -11,7 +11,7 @@ namespace jet { class __mysql : public Tag { public: - __mysql(coreutils::ZString &in, coreutils::MString &out, Global &global); + __mysql(coreutils::ZString &in, coreutils::MString &parent, Global &global); }; diff --git a/__read.cpp b/__read.cpp index 099aa23..76242f6 100644 --- a/__read.cpp +++ b/__read.cpp @@ -3,12 +3,12 @@ namespace jet { - __read::__read(coreutils::ZString &in, coreutils::MString &out, Global &global) : Tag(in, out, global) { + __read::__read(coreutils::ZString &in, coreutils::MString &parent, Global &global) : Tag(in, parent, global) { if(!variableDefined(coreutils::ZString("file"))) throw coreutils::Exception("file keyword must be specified."); if(hasContainer) - throw coreutils::Exception("missing / at end of tag definition."); + throw coreutils::Exception("Missing / at end of tag definition. Not a container tag."); // process file request here. diff --git a/__read.h b/__read.h index 39a0ced..3bded82 100644 --- a/__read.h +++ b/__read.h @@ -8,7 +8,7 @@ namespace jet { class __read : public Tag { public: - __read(coreutils::ZString &in, coreutils::MString &out, Global &global); + __read(coreutils::ZString &in, coreutils::MString &parent, Global &global); }; diff --git a/__set.cpp b/__set.cpp index 6dd8a74..6b5fead 100644 --- a/__set.cpp +++ b/__set.cpp @@ -1,20 +1,34 @@ #include "__set.h" #include "Exception.h" +#include "Expression.h" #include namespace jet { - __set::__set(coreutils::ZString &in, coreutils::MString &out, Global &global) : Tag(in, out, global) { + __set::__set(coreutils::ZString &in, coreutils::MString &parent, Global &global) : Tag(in, parent, global) { output = false; + processContainer(container); if(!variableDefined("name")) throw coreutils::Exception("set tag must have name defined."); - if(variableDefined("value") && hasContainer) + if(!variableDefined("expr") && variableDefined("value") && hasContainer) throw coreutils::Exception("set tag cannot have both value and a container."); - if(!variableDefined("value") && !hasContainer) - throw coreutils::Exception("set tag must have a value or a container."); + if(variableDefined("expr") && !variableDefined("value") && hasContainer) + throw coreutils::Exception("set tag cannot have both expr and a container."); + if(variableDefined("expr") && variableDefined("value") && !hasContainer) + throw coreutils::Exception("set tag cannot have both expr and value."); + if(!variableDefined("expr") && !variableDefined("value") && !hasContainer) + throw coreutils::Exception("set tag must have a value, expr or a container."); if(!variableDefined("scope") || (variables["scope"] == "global")) { - if(hasContainer) { - global.variables[variables["name"]] = container.parsed(); + if(variableDefined("expr")) { + if(variableDefined("eval")) + throw coreutils::Exception("Cannot use eval with expr."); + global.variables[variables["name"]] = Expression(variables["expr"]); + } else if(hasContainer) { + if(evaluate) { + global.variables[variables["name"]] = out; + } else { + global.variables[variables["name"]] = container; + } } else global.variables[variables["name"]] = variables["value"]; } else { diff --git a/__set.h b/__set.h index 4536505..8ea39c7 100644 --- a/__set.h +++ b/__set.h @@ -11,8 +11,10 @@ namespace jet { class __set : public Tag { public: - __set(coreutils::ZString &in, coreutils::MString &out, Global &global); - + __set(coreutils::ZString &in, coreutils::MString &parent, Global &global); + + protected: + }; } diff --git a/testjet b/testjet index 238ca8b..0542a46 100755 Binary files a/testjet and b/testjet differ diff --git a/testjet.cpp b/testjet.cpp index 4528dae..a15d66f 100644 --- a/testjet.cpp +++ b/testjet.cpp @@ -5,20 +5,41 @@ int main(int argc, char **argv) { - coreutils::ZString data("\n" - " \n" - " this is the value\n" + coreutils::ZString data("\n" + " \n" + " \n" + " \n" + " \n" + " this is the value store in #[name].\n" + " this is the value store in #[name].\n" " another container value\n" + " >>>$[noeval]<<<\n" + " >>>$[thename]<<<\n" + " local: >>>#[name]<<<\n" " \n" " \n" " 789\n" - " \n" + " \n" " 123\n" + " \n" + " 456\n" " \n" " \n" " \n" + " \n" + " -->#[ix]<--\n" + " \n" + " \n" "\n"); + coreutils::ZString data2("\n" + " \n" + " XXX\n" + " \n" + " YYY\n" + " \n" + "\n"); + // coreutils::ZString data("ABCHIJXYZ\n"); std::cout << "---------\n" << data << "----------\n" << std::endl;