diff --git a/Tag.cpp b/Tag.cpp index 035c372..239b86f 100644 --- a/Tag.cpp +++ b/Tag.cpp @@ -33,7 +33,7 @@ namespace jet { if(!finished) { coreutils::ZString keywordName = in.getTokenInclude("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_"); if(in.ifNext("=\"")) { - keywords[keywordName] = in.getTokenExclude("\""); + variables[keywordName] = in.getTokenExclude("\""); } if(!in.ifNext("\"")) {} } @@ -186,8 +186,8 @@ namespace jet { } } - bool Tag::keywordExists(coreutils::ZString keyword) { - return keywords.find(keyword) != keywords.end(); + bool Tag::variableDefined(coreutils::ZString keyword) { + return variables.find(keyword) != variables.end(); } bool Tag::ifNested(coreutils::ZString &in) { diff --git a/Tag.h b/Tag.h index 719ee74..d0d54d6 100644 --- a/Tag.h +++ b/Tag.h @@ -18,21 +18,21 @@ namespace jet { protected: bool hasContainer; - std::map keywords; - bool keywordExists(coreutils::ZString keyword); + std::map variables; + bool variableDefined(coreutils::ZString variable); void parseContainer(coreutils::ZString &in); void copyContainer(coreutils::ZString &in, coreutils::MString &out); - private: - Global &global; - coreutils::MString &parent; - coreutils::MString out; - bool evaluate = true; bool filterBlankLines = false; bool trim = false; bool cleanWhitespace = false; + private: + Global &global; + coreutils::MString &parent; + coreutils::MString out; + int skipBlankLine(coreutils::ZString in); void scanContainer(coreutils::ZString &in); diff --git a/__for.cpp b/__for.cpp index 9f08809..81d114e 100644 --- a/__for.cpp +++ b/__for.cpp @@ -5,9 +5,9 @@ namespace jet { __for::__for(coreutils::ZString &in, coreutils::MString &out, Global &global) : Tag(in, out, global) { - if(!keywordExists(coreutils::ZString("begin"))) + if(!variableDefined(coreutils::ZString("begin"))) throw coreutils::Exception("begin keyword must be specified."); - if(!keywordExists(coreutils::ZString("end"))) + if(!variableDefined(coreutils::ZString("end"))) throw coreutils::Exception("end keyword must be specified."); for(;;) { diff --git a/__if.cpp b/__if.cpp index 0407d03..403f3dc 100644 --- a/__if.cpp +++ b/__if.cpp @@ -9,22 +9,22 @@ namespace jet { coreutils::MString result; - if(keywordExists("value1")) { - if(keywordExists("expr")) + if(variableDefined("value1")) { + if(variableDefined("expr")) throw coreutils::Exception("Either value1 or expr can be specified but not both."); - if(keywordExists("value2")) { - if(keywordExists("type")) { + if(variableDefined("value2")) { + if(variableDefined("type")) { } else throw coreutils::Exception("type expected if value1 and value2 specified."); } else throw coreutils::Exception("value2 required if value1 specified."); - } else if(keywordExists("expr")) { - if(keywordExists("value2")) + } else if(variableDefined("expr")) { + if(variableDefined("value2")) throw coreutils::Exception("value2 should not be specified with expr."); - if(keywordExists("type")) + if(variableDefined("type")) throw coreutils::Exception("type should not be specified with expr."); - result = Expression(keywords["expr"]); + result = Expression(variables["expr"]); std::cout << "result1: " << result << std::endl; } std::cout << "result2: " << result << std::endl; diff --git a/__read.cpp b/__read.cpp index cacadc5..099aa23 100644 --- a/__read.cpp +++ b/__read.cpp @@ -4,7 +4,7 @@ namespace jet { __read::__read(coreutils::ZString &in, coreutils::MString &out, Global &global) : Tag(in, out, global) { - if(!keywordExists(coreutils::ZString("file"))) + if(!variableDefined(coreutils::ZString("file"))) throw coreutils::Exception("file keyword must be specified."); if(hasContainer) diff --git a/__set.cpp b/__set.cpp index c85ab11..48d1090 100644 --- a/__set.cpp +++ b/__set.cpp @@ -5,14 +5,20 @@ namespace jet { __set::__set(coreutils::ZString &in, coreutils::MString &out, Global &global) : Tag(in, out, global) { - std::cout << "name: [" << keywords["name"] << "]" << std::endl; - std::cout << "value: [" << keywords["value"] << "]" << std::endl; + std::cout << "name: [" << variables["name"] << "]" << std::endl; + std::cout << "value: [" << variables["value"] << "]" << std::endl; std::cout << "container: [" << container << "]" << std::endl; - std::cout << "scope: [" << keywords["scope"] << "]" << std::endl; - std::cout << "var1: [" << global.variables.size() << "]" << std::endl; - global.variables[keywords["name"]] = container; - std::cout << "var2: [" << global.variables.size() << "]" << std::endl; - std::cout << "varx: [" << global.variables["varname"] << "]" << std::endl; + std::cout << "scope: [" << variables["scope"] << "]" << std::endl; + + if(variables["scope"] == "local") + variables[variables["name"]] = variables["value"]; + if(variables["scope"] == "global") + global.variables[variables["name"]] = container; + + std::cout << "localvar: [" << variables.size() << "]" << std::endl; + std::cout << "localvarx: [" << variables[variables["name"]] << "]" << std::endl; + std::cout << "globalvar: [" << global.variables.size() << "]" << std::endl; + std::cout << "globalvarx: [" << global.variables[variables["name"]] << "]" << std::endl; } } diff --git a/__while.cpp b/__while.cpp index 5f21393..022bca4 100644 --- a/__while.cpp +++ b/__while.cpp @@ -6,20 +6,20 @@ namespace jet { __while::__while(coreutils::ZString &in, coreutils::MString &out, Global &global) : Tag(in, out, global) { - if(keywordExists(coreutils::ZString("value1"))) { - if(keywordExists(coreutils::ZString("expr"))) + if(variableDefined(coreutils::ZString("value1"))) { + if(variableDefined(coreutils::ZString("expr"))) throw coreutils::Exception("Either value1 or expr can be specified but not both."); - if(keywordExists(coreutils::ZString("value2"))) { - if(keywordExists(coreutils::ZString("type"))) { + if(variableDefined(coreutils::ZString("value2"))) { + if(variableDefined(coreutils::ZString("type"))) { // process here } else throw coreutils::Exception("type expected if value1 and value2 specified."); } else throw coreutils::Exception("value2 required if value1 specified."); - } else if(keywordExists(coreutils::ZString("expr"))) { - if(keywordExists(coreutils::ZString("value2"))) + } else if(variableDefined(coreutils::ZString("expr"))) { + if(variableDefined(coreutils::ZString("value2"))) throw coreutils::Exception("value2 should not be specified with expr."); - if(keywordExists(coreutils::ZString("type"))) + if(variableDefined(coreutils::ZString("type"))) throw coreutils::Exception("type should not be specified with expr."); // process here } diff --git a/testjet b/testjet index e474196..fa2a619 100755 Binary files a/testjet and b/testjet differ