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) {
|
if(!finished) {
|
||||||
coreutils::ZString keywordName = in.getTokenInclude("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_");
|
coreutils::ZString keywordName = in.getTokenInclude("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_");
|
||||||
if(in.ifNext("=\"")) {
|
if(in.ifNext("=\"")) {
|
||||||
keywords[keywordName] = in.getTokenExclude("\"");
|
variables[keywordName] = in.getTokenExclude("\"");
|
||||||
}
|
}
|
||||||
if(!in.ifNext("\"")) {}
|
if(!in.ifNext("\"")) {}
|
||||||
}
|
}
|
||||||
@ -186,8 +186,8 @@ namespace jet {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Tag::keywordExists(coreutils::ZString keyword) {
|
bool Tag::variableDefined(coreutils::ZString keyword) {
|
||||||
return keywords.find(keyword) != keywords.end();
|
return variables.find(keyword) != variables.end();
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Tag::ifNested(coreutils::ZString &in) {
|
bool Tag::ifNested(coreutils::ZString &in) {
|
||||||
|
14
Tag.h
14
Tag.h
@ -18,21 +18,21 @@ namespace jet {
|
|||||||
|
|
||||||
protected:
|
protected:
|
||||||
bool hasContainer;
|
bool hasContainer;
|
||||||
std::map<coreutils::ZString, coreutils::ZString> keywords;
|
std::map<coreutils::ZString, coreutils::ZString> variables;
|
||||||
bool keywordExists(coreutils::ZString keyword);
|
bool variableDefined(coreutils::ZString variable);
|
||||||
void parseContainer(coreutils::ZString &in);
|
void parseContainer(coreutils::ZString &in);
|
||||||
void copyContainer(coreutils::ZString &in, coreutils::MString &out);
|
void copyContainer(coreutils::ZString &in, coreutils::MString &out);
|
||||||
|
|
||||||
private:
|
|
||||||
Global &global;
|
|
||||||
coreutils::MString &parent;
|
|
||||||
coreutils::MString out;
|
|
||||||
|
|
||||||
bool evaluate = true;
|
bool evaluate = true;
|
||||||
bool filterBlankLines = false;
|
bool filterBlankLines = false;
|
||||||
bool trim = false;
|
bool trim = false;
|
||||||
bool cleanWhitespace = false;
|
bool cleanWhitespace = false;
|
||||||
|
|
||||||
|
private:
|
||||||
|
Global &global;
|
||||||
|
coreutils::MString &parent;
|
||||||
|
coreutils::MString out;
|
||||||
|
|
||||||
int skipBlankLine(coreutils::ZString in);
|
int skipBlankLine(coreutils::ZString in);
|
||||||
|
|
||||||
void scanContainer(coreutils::ZString &in);
|
void scanContainer(coreutils::ZString &in);
|
||||||
|
@ -5,9 +5,9 @@
|
|||||||
namespace jet {
|
namespace jet {
|
||||||
|
|
||||||
__for::__for(coreutils::ZString &in, coreutils::MString &out, Global &global) : Tag(in, out, global) {
|
__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.");
|
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.");
|
throw coreutils::Exception("end keyword must be specified.");
|
||||||
|
|
||||||
for(;;) {
|
for(;;) {
|
||||||
|
16
__if.cpp
16
__if.cpp
@ -9,22 +9,22 @@ namespace jet {
|
|||||||
|
|
||||||
coreutils::MString result;
|
coreutils::MString result;
|
||||||
|
|
||||||
if(keywordExists("value1")) {
|
if(variableDefined("value1")) {
|
||||||
if(keywordExists("expr"))
|
if(variableDefined("expr"))
|
||||||
throw coreutils::Exception("Either value1 or expr can be specified but not both.");
|
throw coreutils::Exception("Either value1 or expr can be specified but not both.");
|
||||||
if(keywordExists("value2")) {
|
if(variableDefined("value2")) {
|
||||||
if(keywordExists("type")) {
|
if(variableDefined("type")) {
|
||||||
|
|
||||||
} else
|
} else
|
||||||
throw coreutils::Exception("type expected if value1 and value2 specified.");
|
throw coreutils::Exception("type expected if value1 and value2 specified.");
|
||||||
} else
|
} else
|
||||||
throw coreutils::Exception("value2 required if value1 specified.");
|
throw coreutils::Exception("value2 required if value1 specified.");
|
||||||
} else if(keywordExists("expr")) {
|
} else if(variableDefined("expr")) {
|
||||||
if(keywordExists("value2"))
|
if(variableDefined("value2"))
|
||||||
throw coreutils::Exception("value2 should not be specified with expr.");
|
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.");
|
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 << "result1: " << result << std::endl;
|
||||||
}
|
}
|
||||||
std::cout << "result2: " << result << std::endl;
|
std::cout << "result2: " << result << std::endl;
|
||||||
|
@ -4,7 +4,7 @@
|
|||||||
namespace jet {
|
namespace jet {
|
||||||
|
|
||||||
__read::__read(coreutils::ZString &in, coreutils::MString &out, Global &global) : Tag(in, out, global) {
|
__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.");
|
throw coreutils::Exception("file keyword must be specified.");
|
||||||
|
|
||||||
if(hasContainer)
|
if(hasContainer)
|
||||||
|
20
__set.cpp
20
__set.cpp
@ -5,14 +5,20 @@
|
|||||||
namespace jet {
|
namespace jet {
|
||||||
|
|
||||||
__set::__set(coreutils::ZString &in, coreutils::MString &out, Global &global) : Tag(in, out, global) {
|
__set::__set(coreutils::ZString &in, coreutils::MString &out, Global &global) : Tag(in, out, global) {
|
||||||
std::cout << "name: [" << keywords["name"] << "]" << std::endl;
|
std::cout << "name: [" << variables["name"] << "]" << std::endl;
|
||||||
std::cout << "value: [" << keywords["value"] << "]" << std::endl;
|
std::cout << "value: [" << variables["value"] << "]" << std::endl;
|
||||||
std::cout << "container: [" << container << "]" << std::endl;
|
std::cout << "container: [" << container << "]" << std::endl;
|
||||||
std::cout << "scope: [" << keywords["scope"] << "]" << std::endl;
|
std::cout << "scope: [" << variables["scope"] << "]" << std::endl;
|
||||||
std::cout << "var1: [" << global.variables.size() << "]" << std::endl;
|
|
||||||
global.variables[keywords["name"]] = container;
|
if(variables["scope"] == "local")
|
||||||
std::cout << "var2: [" << global.variables.size() << "]" << std::endl;
|
variables[variables["name"]] = variables["value"];
|
||||||
std::cout << "varx: [" << global.variables["varname"] << "]" << std::endl;
|
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) {
|
__while::__while(coreutils::ZString &in, coreutils::MString &out, Global &global) : Tag(in, out, global) {
|
||||||
|
|
||||||
if(keywordExists(coreutils::ZString("value1"))) {
|
if(variableDefined(coreutils::ZString("value1"))) {
|
||||||
if(keywordExists(coreutils::ZString("expr")))
|
if(variableDefined(coreutils::ZString("expr")))
|
||||||
throw coreutils::Exception("Either value1 or expr can be specified but not both.");
|
throw coreutils::Exception("Either value1 or expr can be specified but not both.");
|
||||||
if(keywordExists(coreutils::ZString("value2"))) {
|
if(variableDefined(coreutils::ZString("value2"))) {
|
||||||
if(keywordExists(coreutils::ZString("type"))) {
|
if(variableDefined(coreutils::ZString("type"))) {
|
||||||
// process here
|
// process here
|
||||||
} else
|
} else
|
||||||
throw coreutils::Exception("type expected if value1 and value2 specified.");
|
throw coreutils::Exception("type expected if value1 and value2 specified.");
|
||||||
} else
|
} else
|
||||||
throw coreutils::Exception("value2 required if value1 specified.");
|
throw coreutils::Exception("value2 required if value1 specified.");
|
||||||
} else if(keywordExists(coreutils::ZString("expr"))) {
|
} else if(variableDefined(coreutils::ZString("expr"))) {
|
||||||
if(keywordExists(coreutils::ZString("value2")))
|
if(variableDefined(coreutils::ZString("value2")))
|
||||||
throw coreutils::Exception("value2 should not be specified with expr.");
|
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.");
|
throw coreutils::Exception("type should not be specified with expr.");
|
||||||
// process here
|
// process here
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user