Perens now work fully! The RegEx part of Kraken should now be fully legitimate. The only problem is not gracefully letting the user know about faulty input, but that goes for all of Kraken.

This commit is contained in:
Nathan Braswell
2013-07-07 02:13:05 -04:00
parent 502929963c
commit 4c2fd967f0
4 changed files with 190 additions and 12 deletions

View File

@@ -35,6 +35,14 @@ std::vector<RegExState*>* RegExState::advance(char advanceCharacter) {
return advanceStates;
}
RegExState* RegExState::getInner() {
return inner;
}
std::vector<RegExState*>* RegExState::getNextStates() {
return &nextStates;
}
bool RegExState::isGoal() {
//return inner == NULL && nextStates.size() == 0;
for (std::vector<RegExState*>::size_type i = 0; i < nextStates.size(); i++)
@@ -44,17 +52,48 @@ bool RegExState::isGoal() {
}
std::string RegExState::toString() {
std::vector<RegExState*> avoidList;
return toString(&avoidList);
}
std::string RegExState::toString(RegExState* avoid) {
std::vector<RegExState*> avoidList;
avoidList.push_back(avoid);
return toString(&avoidList);
}
std::string RegExState::toString(std::vector<RegExState*>* avoid) {
avoid->push_back(this);
std::string string = "";
string += std::string("\"") + character + "\"";
for (std::vector<RegExState*>::size_type i = 0; i < nextStates.size(); i++)
if (inner != NULL) {
string += "inner: ";
string += inner->toString(avoid);
string += " end inner ";
}
for (std::vector<RegExState*>::size_type i = 0; i < nextStates.size(); i++) {
bool inAvoid = false;
for (std::vector<RegExState*>::size_type j = 0; j < avoid->size(); j++) {
if (nextStates[i] == (*avoid)[j]) {
inAvoid = true;
}
}
if (inAvoid) {
string += "->LoopDetected";
continue;
}
if (nextStates[i] != this && nextStates[i] != NULL)
string += "->" + nextStates[i]->toString() + " EC ";
string += "->" + nextStates[i]->toString(avoid) + " EC ";
else if (nextStates[i] == NULL)
string += "-> GOAL ";
else
string += "->this";
}
//std::cout << "inner = " << inner << " nextStates size = " << nextStates.size() <<std::endl;
return string;
}
char RegExState::getCharacter() {
return character;
}