import regex to parse keywords.
This commit is contained in:
parent
747574948a
commit
2341abc93f
@ -1,9 +1,11 @@
|
|||||||
#include <boost/test/unit_test.hpp>
|
|
||||||
#include <iostream>
|
|
||||||
#include <fstream>
|
|
||||||
#include <sstream>
|
|
||||||
#include <script_parser.h>
|
#include <script_parser.h>
|
||||||
|
|
||||||
|
#include <boost/test/unit_test.hpp>
|
||||||
|
#include <fstream>
|
||||||
|
#include <iostream>
|
||||||
|
#include <regex>
|
||||||
|
#include <sstream>
|
||||||
|
|
||||||
using namespace std;
|
using namespace std;
|
||||||
using namespace boost::unit_test;
|
using namespace boost::unit_test;
|
||||||
|
|
||||||
@ -12,11 +14,24 @@ int parseScript(const char* path) {
|
|||||||
BOOST_TEST_REQUIRE(script.is_open(), "open script file failed!");
|
BOOST_TEST_REQUIRE(script.is_open(), "open script file failed!");
|
||||||
|
|
||||||
string line;
|
string line;
|
||||||
while(getline(script, line, '\n')) {
|
while (getline(script, line, '\n')) {
|
||||||
// cout << line <<endl;
|
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;
|
string word;
|
||||||
istringstream iss(line);
|
istringstream iss(line);
|
||||||
while(getline(iss, word, ' ')) {
|
while (getline(iss, word, ' ')) {
|
||||||
cout << word << "+";
|
cout << word << "+";
|
||||||
}
|
}
|
||||||
cout << endl;
|
cout << endl;
|
||||||
|
Loading…
Reference in New Issue
Block a user