Make inputparser more robust + add minimize
This commit is contained in:
parent
a4dbf3d195
commit
81f3c022c8
|
@ -12,24 +12,51 @@ namespace lxs {
|
|||
auto enfavect = parseLines(is);
|
||||
auto enfas = linesToEnfa(enfavect);
|
||||
auto enfa = merge(enfas);
|
||||
auto dfa = mssc(enfa);
|
||||
auto dfa = minimize(mssc(enfa));
|
||||
return dfa;
|
||||
}
|
||||
|
||||
std::vector<std::pair<std::string,std::string> > InputParser::parseLines(std::istream &is) {
|
||||
std::string line;
|
||||
std::vector<std::pair<std::string,std::string> > result;
|
||||
unsigned int i=0;
|
||||
while(std::getline(is,line)) {
|
||||
int loc = line.find_first_of('=');
|
||||
int start = line.find_first_not_of(" \t\v\f\r");
|
||||
if(line.length() == 0) continue;
|
||||
i++;
|
||||
std::size_t loc = line.find_first_of('=');
|
||||
if(loc == std::string::npos) {
|
||||
std::cerr << "Invalid syntax on line " << i << ": no '=' found!" << std::endl;
|
||||
exit(1);
|
||||
}
|
||||
size_t start = line.find_first_not_of(" \t\v\f\r");
|
||||
if(start == loc) {
|
||||
std::cerr << "Invalid syntax on line " << i << ": no valid tokenname specified!" << std::endl;
|
||||
exit(1);
|
||||
}
|
||||
std::string tokenname = line.substr(start, loc);
|
||||
int end = tokenname.find_last_not_of(" \t\v\f\r");
|
||||
if(tokenname.length() == 0) {
|
||||
std::cerr << "Invalid syntax on line " << i << ": no valid tokenname specified!" << std::endl;
|
||||
exit(1);
|
||||
}
|
||||
std::size_t end = tokenname.find_last_not_of(" \t\v\f\r");
|
||||
tokenname = tokenname.substr(0,end + 1);
|
||||
std::string regex = line.substr(loc+1);
|
||||
start = regex.find_first_not_of(" ");
|
||||
if(regex.length() == 0) {
|
||||
std::cerr << "Invalid syntax on line " << i << ": no valid regex specified!" << std::endl;
|
||||
exit(1);
|
||||
}
|
||||
start = regex.find_first_not_of(" \t\v\f\r");
|
||||
if(start == std::string::npos) {
|
||||
std::cerr << "Invalid syntax on line " << i << ": no valid regex specified!" << std::endl;
|
||||
exit(1);
|
||||
}
|
||||
regex = regex.substr(start);
|
||||
result.push_back(std::make_pair(tokenname,regex));
|
||||
}
|
||||
if(result.size() == 0) {
|
||||
std::cerr << "No valid rules found in the input file!" << std::endl;
|
||||
exit(1);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue