Initial repository commit.
This commit is contained in:
commit
fce97e04ff
17
.vscode/c_cpp_properties.json
vendored
Normal file
17
.vscode/c_cpp_properties.json
vendored
Normal file
@ -0,0 +1,17 @@
|
||||
{
|
||||
"configurations": [
|
||||
{
|
||||
"name": "Linux",
|
||||
"includePath": [
|
||||
"${workspaceFolder}/**"
|
||||
],
|
||||
"defines": [],
|
||||
"compilerPath": "/usr/bin/gcc",
|
||||
"cStandard": "gnu17",
|
||||
"cppStandard": "gnu++14",
|
||||
"intelliSenseMode": "linux-gcc-x64",
|
||||
"configurationProvider": "ms-vscode.cmake-tools"
|
||||
}
|
||||
],
|
||||
"version": 4
|
||||
}
|
3
.vscode/settings.json
vendored
Normal file
3
.vscode/settings.json
vendored
Normal file
@ -0,0 +1,3 @@
|
||||
{
|
||||
"cmake.configureOnOpen": false
|
||||
}
|
220
Tag.cpp
Normal file
220
Tag.cpp
Normal file
@ -0,0 +1,220 @@
|
||||
#include "Tag.h"
|
||||
#include "Exception.h"
|
||||
#include "Log.h"
|
||||
#include "__mysql.h"
|
||||
#include "__for.h"
|
||||
#include "__if.h"
|
||||
#include "__read.h"
|
||||
#include "__set.h"
|
||||
#include "__jet.h"
|
||||
#include "__while.h"
|
||||
#include <iostream>
|
||||
|
||||
namespace jet {
|
||||
|
||||
Tag::Tag(coreutils::ZString &in, coreutils::MString &parent)
|
||||
: ZString(in), parent(parent) {
|
||||
if(in.ifNext("<")) {
|
||||
name = in.getTokenInclude("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_!");
|
||||
if(in.startsWith(" ") || in.startsWith("/") || in.startsWith(">")) {
|
||||
coreutils::Log(coreutils::LOG_DEBUG_1) << "Processing tag: " << name;
|
||||
bool finished = false;
|
||||
while(!finished) {
|
||||
in.skipWhitespace();
|
||||
if(in.ifNext(">")) {
|
||||
hasContainer = true;
|
||||
finished = true;
|
||||
break;
|
||||
} else if(in.ifNext("/>")) {
|
||||
hasContainer = false;
|
||||
finished = true;
|
||||
break;
|
||||
}
|
||||
if(!finished) {
|
||||
coreutils::ZString keywordName = in.getTokenInclude("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_");
|
||||
if(in.ifNext("=\"")) {
|
||||
keywords[keywordName] = in.getTokenExclude("\"");
|
||||
}
|
||||
if(!in.ifNext("\"")) {}
|
||||
}
|
||||
}
|
||||
if(hasContainer) {
|
||||
coreutils::Log(coreutils::LOG_DEBUG_2) << "has Container: " << hasContainer;
|
||||
char *start = 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 << "]";
|
||||
break;
|
||||
} else if(ifNested(in)) {}
|
||||
else
|
||||
in.nextChar();
|
||||
}
|
||||
}
|
||||
setZString(in.parsed());
|
||||
if(hasContainer && evaluate)
|
||||
parseContainer(container);
|
||||
}
|
||||
} else
|
||||
throw coreutils::Exception("First character of (in) must be a <.");
|
||||
}
|
||||
|
||||
Tag::~Tag() {
|
||||
if(evaluate) {
|
||||
copyContainer(out, parent);
|
||||
} else {
|
||||
copyContainer(container, parent);
|
||||
}
|
||||
}
|
||||
|
||||
void Tag::parseContainer(coreutils::ZString &in) {
|
||||
char *start = in.getCursor();
|
||||
while(!in.eod()) {
|
||||
if(in.startsWith("<")) {
|
||||
if(ifTagName(in, "mysql")) {
|
||||
__mysql _mysql(in, out);
|
||||
continue;
|
||||
} else if(ifTagName(in, "for")) {
|
||||
__for _for(in, out);
|
||||
continue;
|
||||
} else if(ifTagName(in, "if")) {
|
||||
__if _if(in, out);
|
||||
continue;
|
||||
} else if(ifTagName(in, "jet")) {
|
||||
__jet _jet(in, out);
|
||||
continue;
|
||||
} else if(ifTagName(in, "read")) {
|
||||
__read _read(in, out);
|
||||
continue;
|
||||
} else if(ifTagName(in, "set")) {
|
||||
__set _set(in, out);
|
||||
continue;
|
||||
} else if(ifTagName(in, "while")) {
|
||||
__while _while(in, out);
|
||||
continue;
|
||||
}
|
||||
}
|
||||
out.write(in.charAt(0));
|
||||
in.nextChar();
|
||||
}
|
||||
}
|
||||
|
||||
void Tag::scanContainer(coreutils::ZString &in) {
|
||||
while(!in.eod()) {
|
||||
if(ifEndTagName(in))
|
||||
return;
|
||||
else if(ifNested(in)) {}
|
||||
else in.nextChar();
|
||||
}
|
||||
}
|
||||
|
||||
bool Tag::ifTagName(coreutils::ZString &in, const char *tag) {
|
||||
in.push();
|
||||
if(in.ifNext("<"))
|
||||
if(in.getTokenInclude("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_").equals(tag)) {
|
||||
if(in.ifNext(" ")) {
|
||||
in.pop();
|
||||
return true;
|
||||
} else if(in.ifNext("/>")) {
|
||||
in.pop();
|
||||
return true;
|
||||
} else if(in.ifNext(">")) {
|
||||
in.pop();
|
||||
return true;
|
||||
}
|
||||
}
|
||||
in.pop();
|
||||
return false;
|
||||
}
|
||||
|
||||
bool Tag::ifTagName(coreutils::ZString &in) {
|
||||
in.push();
|
||||
if(in.ifNext("<"))
|
||||
if(in.getTokenInclude("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_").equals(name)) {
|
||||
in.push();
|
||||
if(in.ifNext(" ")) {
|
||||
in.pop();
|
||||
return true;
|
||||
} else if(in.ifNext("/>")) {
|
||||
in.pop();
|
||||
return true;
|
||||
} else if(in.ifNext(">")) {
|
||||
in.pop();
|
||||
return true;
|
||||
}
|
||||
in.pop();
|
||||
}
|
||||
in.pop();
|
||||
return false;
|
||||
}
|
||||
|
||||
bool Tag::ifEndTagName(coreutils::ZString &in) {
|
||||
in.push();
|
||||
if(in.ifNext("</"))
|
||||
if(in.getTokenInclude("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_").equals(name)) {
|
||||
if(in.ifNext(">"))
|
||||
return true;
|
||||
}
|
||||
in.pop();
|
||||
return false;
|
||||
}
|
||||
|
||||
int Tag::skipBlankLine(coreutils::ZString in) {
|
||||
ZString temp = in.getTokenInclude(" \t");
|
||||
if(ifNext("\n"))
|
||||
return temp.getLength() + 1;
|
||||
return 0;
|
||||
}
|
||||
|
||||
void Tag::copyContainer(coreutils::ZString &in, coreutils::MString &out) {
|
||||
while(!in.eod()) {
|
||||
if(filterBlankLines) {
|
||||
in.push();
|
||||
if(!in.eod()) {
|
||||
in.getTokenInclude(" \t");
|
||||
if(!in.ifNext("\n")) {
|
||||
in.pop();
|
||||
// TODO: shouod be safe to output line here.
|
||||
}
|
||||
}
|
||||
}
|
||||
else {
|
||||
out.write(in.charAt(0));
|
||||
in.nextChar();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
bool Tag::keywordExists(coreutils::ZString keyword) {
|
||||
return keywords.find(keyword) != keywords.end();
|
||||
}
|
||||
|
||||
bool Tag::ifNested(coreutils::ZString &in) {
|
||||
bool hasContainer = false;
|
||||
if(ifTagName(in)) {
|
||||
while(!in.eod()) {
|
||||
in.skipWhitespace();
|
||||
if(in.ifNext(">")) {
|
||||
hasContainer = true;
|
||||
break;
|
||||
} else if(in.ifNext("/>")) {
|
||||
hasContainer = false;
|
||||
return true;
|
||||
} else if(in.getTokenExclude("=").getLength() != 0) {
|
||||
if(in.ifNext("=\"")) {
|
||||
while(1) {
|
||||
if(in.ifNext("\"")) {
|
||||
break;
|
||||
}
|
||||
in.nextChar();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if(hasContainer)
|
||||
scanContainer(in);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
46
Tag.h
Normal file
46
Tag.h
Normal file
@ -0,0 +1,46 @@
|
||||
#ifndef __Tag_h__
|
||||
#define __Tag_h__
|
||||
|
||||
#include "ZString.h"
|
||||
#include "MString.h"
|
||||
#include <map>
|
||||
|
||||
namespace jet {
|
||||
|
||||
class Tag : public coreutils::ZString {
|
||||
|
||||
public:
|
||||
Tag(coreutils::ZString &in, coreutils::MString &parent);
|
||||
~Tag();
|
||||
coreutils::ZString name;
|
||||
coreutils::ZString container;
|
||||
|
||||
protected:
|
||||
bool hasContainer;
|
||||
std::map<coreutils::ZString, coreutils::ZString> keywords;
|
||||
bool keywordExists(coreutils::ZString keyword);
|
||||
void parseContainer(coreutils::ZString &in);
|
||||
void copyContainer(coreutils::ZString &in, coreutils::MString &out);
|
||||
|
||||
private:
|
||||
coreutils::MString &parent;
|
||||
coreutils::MString out;
|
||||
|
||||
bool evaluate = true;
|
||||
bool filterBlankLines = false;
|
||||
bool trim = false;
|
||||
bool cleanWhitespace = false;
|
||||
|
||||
int skipBlankLine(coreutils::ZString in);
|
||||
|
||||
void scanContainer(coreutils::ZString &in);
|
||||
bool ifNested(coreutils::ZString &in);
|
||||
bool ifTagName(coreutils::ZString &in, const char *tag);
|
||||
bool ifTagName(coreutils::ZString &in);
|
||||
bool ifEndTagName(coreutils::ZString &in);
|
||||
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#endif
|
19
__for.cpp
Normal file
19
__for.cpp
Normal file
@ -0,0 +1,19 @@
|
||||
#include "__for.h"
|
||||
#include "Exception.h"
|
||||
#include <iostream>
|
||||
|
||||
namespace jet {
|
||||
|
||||
__for::__for(coreutils::ZString &in, coreutils::MString &out) : Tag(in, out) {
|
||||
if(!keywordExists(coreutils::ZString("begin")))
|
||||
throw coreutils::Exception("begin keyword must be specified.");
|
||||
if(!keywordExists(coreutils::ZString("end")))
|
||||
throw coreutils::Exception("end keyword must be specified.");
|
||||
|
||||
for(;;) {
|
||||
parseContainer(container);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
18
__for.h
Normal file
18
__for.h
Normal file
@ -0,0 +1,18 @@
|
||||
#ifndef ____for_h__
|
||||
#define ____for_h__
|
||||
|
||||
#include "Tag.h"
|
||||
#include <sstream>
|
||||
|
||||
namespace jet {
|
||||
|
||||
class __for : public Tag {
|
||||
|
||||
public:
|
||||
__for(coreutils::ZString &in, coreutils::MString &out);
|
||||
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#endif
|
33
__if.cpp
Normal file
33
__if.cpp
Normal file
@ -0,0 +1,33 @@
|
||||
#include "__if.h"
|
||||
#include "Exception.h"
|
||||
#include <iostream>
|
||||
|
||||
namespace jet {
|
||||
|
||||
__if::__if(coreutils::ZString &in, coreutils::MString &out) : Tag(in, out) {
|
||||
|
||||
if(keywordExists(coreutils::ZString("value1"))) {
|
||||
if(keywordExists(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"))) {
|
||||
// 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")))
|
||||
throw coreutils::Exception("value2 should not be specified with expr.");
|
||||
if(keywordExists(coreutils::ZString("type")))
|
||||
throw coreutils::Exception("type should not be specified with expr.");
|
||||
// process here
|
||||
}
|
||||
|
||||
if(true) {
|
||||
parseContainer(container);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
20
__if.h
Normal file
20
__if.h
Normal file
@ -0,0 +1,20 @@
|
||||
#ifndef __if_h__
|
||||
#define __if_h__
|
||||
|
||||
#include "Tag.h"
|
||||
#include "ZString.h"
|
||||
#include "MString.h"
|
||||
#include <sstream>
|
||||
|
||||
namespace jet {
|
||||
|
||||
class __if : public Tag {
|
||||
|
||||
public:
|
||||
__if(coreutils::ZString &in, coreutils::MString &out);
|
||||
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#endif
|
10
__jet.cpp
Normal file
10
__jet.cpp
Normal file
@ -0,0 +1,10 @@
|
||||
#include "__jet.h"
|
||||
#include <iostream>
|
||||
|
||||
namespace jet {
|
||||
|
||||
__jet::__jet(coreutils::ZString &in, coreutils::MString &out) : Tag(in, out) {
|
||||
parseContainer(container);
|
||||
}
|
||||
|
||||
}
|
19
__jet.h
Normal file
19
__jet.h
Normal file
@ -0,0 +1,19 @@
|
||||
#ifndef ____jet_h__
|
||||
#define ____jet_h__
|
||||
|
||||
#include "Tag.h"
|
||||
#include "ZString.h"
|
||||
#include <sstream>
|
||||
|
||||
namespace jet {
|
||||
|
||||
class __jet : public Tag {
|
||||
|
||||
public:
|
||||
__jet(coreutils::ZString &in, coreutils::MString &out);
|
||||
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#endif
|
10
__mysql.cpp
Normal file
10
__mysql.cpp
Normal file
@ -0,0 +1,10 @@
|
||||
#include "__mysql.h"
|
||||
#include <iostream>
|
||||
|
||||
namespace jet {
|
||||
|
||||
__mysql::__mysql(coreutils::ZString &in, coreutils::MString &out) : Tag(in, out) {
|
||||
parseContainer(container);
|
||||
}
|
||||
|
||||
}
|
20
__mysql.h
Normal file
20
__mysql.h
Normal file
@ -0,0 +1,20 @@
|
||||
#ifndef __mysql_h__
|
||||
#define __mysql_h__
|
||||
|
||||
#include "Tag.h"
|
||||
#include "ZString.h"
|
||||
#include "MString.h"
|
||||
#include <sstream>
|
||||
|
||||
namespace jet {
|
||||
|
||||
class __mysql : public Tag {
|
||||
|
||||
public:
|
||||
__mysql(coreutils::ZString &in, coreutils::MString &out);
|
||||
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#endif
|
17
__read.cpp
Normal file
17
__read.cpp
Normal file
@ -0,0 +1,17 @@
|
||||
#include "__read.h"
|
||||
#include "Exception.h"
|
||||
|
||||
namespace jet {
|
||||
|
||||
__read::__read(coreutils::ZString &in, coreutils::MString &out) : Tag(in, out) {
|
||||
if(!keywordExists(coreutils::ZString("file")))
|
||||
throw coreutils::Exception("file keyword must be specified.");
|
||||
|
||||
if(hasContainer)
|
||||
throw coreutils::Exception("missing / at end of tag definition.");
|
||||
|
||||
// process file request here.
|
||||
|
||||
}
|
||||
|
||||
}
|
17
__read.h
Normal file
17
__read.h
Normal file
@ -0,0 +1,17 @@
|
||||
#ifndef ____read_h__
|
||||
#define ____read_h__
|
||||
|
||||
#include "Tag.h"
|
||||
|
||||
namespace jet {
|
||||
|
||||
class __read : public Tag {
|
||||
|
||||
public:
|
||||
__read(coreutils::ZString &in, coreutils::MString &out);
|
||||
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#endif
|
11
__set.cpp
Normal file
11
__set.cpp
Normal file
@ -0,0 +1,11 @@
|
||||
#include "__set.h"
|
||||
#include "Exception.h"
|
||||
#include <iostream>
|
||||
|
||||
namespace jet {
|
||||
|
||||
__set::__set(coreutils::ZString &in, coreutils::MString &out) : Tag(in, out) {
|
||||
|
||||
}
|
||||
|
||||
}
|
20
__set.h
Normal file
20
__set.h
Normal file
@ -0,0 +1,20 @@
|
||||
#ifndef __set_h__
|
||||
#define __set_h__
|
||||
|
||||
#include "Tag.h"
|
||||
#include "ZString.h"
|
||||
#include "MString.h"
|
||||
#include <sstream>
|
||||
|
||||
namespace jet {
|
||||
|
||||
class __set : public Tag {
|
||||
|
||||
public:
|
||||
__set(coreutils::ZString &in, coreutils::MString &out);
|
||||
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#endif
|
33
__while.cpp
Normal file
33
__while.cpp
Normal file
@ -0,0 +1,33 @@
|
||||
#include "__while.h"
|
||||
#include "Exception.h"
|
||||
#include <iostream>
|
||||
|
||||
namespace jet {
|
||||
|
||||
__while::__while(coreutils::ZString &in, coreutils::MString &out) : Tag(in, out) {
|
||||
|
||||
if(keywordExists(coreutils::ZString("value1"))) {
|
||||
if(keywordExists(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"))) {
|
||||
// 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")))
|
||||
throw coreutils::Exception("value2 should not be specified with expr.");
|
||||
if(keywordExists(coreutils::ZString("type")))
|
||||
throw coreutils::Exception("type should not be specified with expr.");
|
||||
// process here
|
||||
}
|
||||
|
||||
while(true) {
|
||||
parseContainer(container);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
18
__while.h
Normal file
18
__while.h
Normal file
@ -0,0 +1,18 @@
|
||||
#ifndef ____while_h__
|
||||
#define ____while_h__
|
||||
|
||||
#include "Tag.h"
|
||||
#include <sstream>
|
||||
|
||||
namespace jet {
|
||||
|
||||
class __while : public Tag {
|
||||
|
||||
public:
|
||||
__while(coreutils::ZString &in, coreutils::MString &out);
|
||||
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#endif
|
33
compile
Executable file
33
compile
Executable file
@ -0,0 +1,33 @@
|
||||
#!/bin/bash
|
||||
|
||||
for file in *.cpp
|
||||
do
|
||||
filename="${file%.*}"
|
||||
list="$list $filename.o"
|
||||
echo -n "Compiling $filename..."
|
||||
g++ -g -c -std=c++17 -I../CoreUtils $file &
|
||||
if [ $? = '0' ]
|
||||
then
|
||||
echo "OK"
|
||||
else
|
||||
echo "ERROR"
|
||||
exit -1
|
||||
fi
|
||||
|
||||
done
|
||||
|
||||
wait
|
||||
echo -n "Building executable testjet..."
|
||||
g++ -g -o testjet $list -std=c++17 -L../CoreUtils -lCoreUtils
|
||||
if [ $? = '0' ]
|
||||
then
|
||||
echo "OK"
|
||||
else
|
||||
echo "ERROR"
|
||||
exit -1
|
||||
fi
|
||||
|
||||
rm *.o
|
||||
rm *~
|
||||
|
||||
|
29
testjet.cpp
Normal file
29
testjet.cpp
Normal file
@ -0,0 +1,29 @@
|
||||
#include <iostream>
|
||||
#include <sstream>
|
||||
#include "__jet.h"
|
||||
|
||||
int main(int argc, char **argv) {
|
||||
|
||||
coreutils::ZString data("<jet>\n"
|
||||
" <set name=\"varname\" value=\"vardata\" scope=\"local\"/>\n"
|
||||
" <set name=\"thename\" scope=\"global\">this is the value</set>\n"
|
||||
" <mysql key=\"uu\">\n"
|
||||
" <if value1=\"X\" value2=\"Y\" type=\"eq\">\n"
|
||||
" 789\n"
|
||||
" <if expr=\"true\">\n"
|
||||
" 123\n"
|
||||
" </if>\n"
|
||||
" </if>\n"
|
||||
" </mysql>\n"
|
||||
"</jet>\n");
|
||||
|
||||
// coreutils::ZString data("<jet>ABC<jet>HIJ</jet>XYZ</jet>\n");
|
||||
|
||||
std::cout << "---------\n" << data << "----------\n" << std::endl;
|
||||
|
||||
coreutils::MString out;
|
||||
jet::__jet *jet = new jet::__jet(data, out);
|
||||
delete jet;
|
||||
std::cout << ">>-------" << std::endl << out << std::endl << "<<------";
|
||||
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user