boosttest/src/script_parser.cpp

49 lines
1.1 KiB
C++
Raw Normal View History

2022-01-14 18:40:48 +08:00
#include <script_parser.h>
2022-01-13 19:04:38 +08:00
#include <boost/test/unit_test.hpp>
#include <fstream>
2022-01-14 18:40:48 +08:00
#include <iostream>
#include <regex>
#include <sstream>
2022-01-13 19:04:38 +08:00
using namespace std;
2022-01-14 16:48:43 +08:00
using namespace boost::unit_test;
2022-01-13 19:04:38 +08:00
int parseScript(const char* path) {
ifstream script(path, ios::in);
2022-01-14 16:48:43 +08:00
BOOST_TEST_REQUIRE(script.is_open(), "open script file failed!");
string line;
2022-01-14 18:40:48 +08:00
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()
2022-01-14 16:48:43 +08:00
string word;
istringstream iss(line);
2022-01-14 18:40:48 +08:00
while (getline(iss, word, ' ')) {
2022-01-14 16:48:43 +08:00
cout << word << "+";
2022-01-14 14:40:45 +08:00
}
2022-01-14 16:48:43 +08:00
cout << endl;
2022-01-13 19:04:38 +08:00
}
2022-01-14 16:48:43 +08:00
script.close();
BOOST_TEST(true);
2022-01-13 19:04:38 +08:00
return 0;
}
#ifdef TEST
int main(int argc, char** argv) {
parseScript(argv[1]);
}
#endif