attempt at getting variables to work.
This commit is contained in:
parent
59fe0d5bd6
commit
50270bbc91
6
Tag.cpp
6
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) {
|
||||
|
14
Tag.h
14
Tag.h
@ -18,21 +18,21 @@ namespace jet {
|
||||
|
||||
protected:
|
||||
bool hasContainer;
|
||||
std::map<coreutils::ZString, coreutils::ZString> keywords;
|
||||
bool keywordExists(coreutils::ZString keyword);
|
||||
std::map<coreutils::ZString, coreutils::ZString> 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);
|
||||
|
@ -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(;;) {
|
||||
|
16
__if.cpp
16
__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;
|
||||
|
@ -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)
|
||||
|
20
__set.cpp
20
__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;
|
||||
}
|
||||
|
||||
}
|
||||
|
14
__while.cpp
14
__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
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user