49 lines
1.1 KiB
C++
49 lines
1.1 KiB
C++
#include <script_parser.h>
|
|
|
|
#include <boost/test/unit_test.hpp>
|
|
#include <fstream>
|
|
#include <iostream>
|
|
#include <regex>
|
|
#include <sstream>
|
|
|
|
using namespace std;
|
|
using namespace boost::unit_test;
|
|
|
|
int parseScript(const char* path) {
|
|
ifstream script(path, ios::in);
|
|
BOOST_TEST_REQUIRE(script.is_open(), "open script file failed!");
|
|
|
|
string line;
|
|
while (getline(script, line, '\n')) {
|
|
regex comment_pattern(" *#.*");
|
|
if (regex_match(line, comment_pattern)) {
|
|
cout << line << endl;
|
|
continue;
|
|
}
|
|
smatch base_match;
|
|
regex keyword_pattern(" *([a-z]+) *.*");
|
|
regex_match(line, base_match, keyword_pattern);
|
|
if (base_match.size() >= 2) {
|
|
ssub_match match = base_match[1];
|
|
cout << match.str() << endl;
|
|
}
|
|
// switch()
|
|
|
|
string word;
|
|
istringstream iss(line);
|
|
while (getline(iss, word, ' ')) {
|
|
cout << word << "+";
|
|
}
|
|
cout << endl;
|
|
}
|
|
script.close();
|
|
BOOST_TEST(true);
|
|
|
|
return 0;
|
|
}
|
|
|
|
#ifdef TEST
|
|
int main(int argc, char** argv) {
|
|
parseScript(argv[1]);
|
|
}
|
|
#endif |