Fixed some more DOT generation stuff.
This commit is contained in:
@@ -225,10 +225,10 @@ template<class T>
|
|||||||
std::string NodeTree<T>::getDOTName() {
|
std::string NodeTree<T>::getDOTName() {
|
||||||
std::string DOTName = "";
|
std::string DOTName = "";
|
||||||
if (data != NULL)
|
if (data != NULL)
|
||||||
DOTName = "\"" + name + "-" + data->toString() + "_" + intToString(id) + "\""; //Note that terminals already have a quote in the front of their name, so we don't need to add one
|
DOTName = "\"" + replaceExEscape(name + "-" + data->toString(), "\"", "\\\"") + "_" + intToString(id) + "\""; //Note that terminals already have a quote in the front of their name, so we don't need to add one
|
||||||
else
|
else
|
||||||
DOTName = "\"" + name + "_" + intToString(id) + "\"";
|
DOTName = "\"" + replaceExEscape(name, "\"", " \\\"") + "_" + intToString(id) + "\"";
|
||||||
return(replace(DOTName, "\n", "\\n"));
|
return(replaceExEscape(DOTName, "\n", "\\n"));
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
@@ -5,13 +5,13 @@
|
|||||||
#define NULL 0
|
#define NULL 0
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
//#include <iostream>
|
#include <iostream>
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <sstream>
|
#include <sstream>
|
||||||
|
|
||||||
std::string intToString(int theInt);
|
std::string intToString(int theInt);
|
||||||
std::string truncateEnd(std::string to_truncate);
|
std::string truncateEnd(std::string to_truncate);
|
||||||
std::string removeBeginning(std::string to_remove);
|
std::string removeBeginning(std::string to_remove);
|
||||||
std::string replace(std::string first, std::string search, std::string replace);
|
std::string replaceExEscape(std::string first, std::string search, std::string replace);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
@@ -83,8 +83,6 @@ NodeTree<Symbol*>* RNGLRParser::parseInput(std::string inputString) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
//Clear the vector of SPPF nodes created every step
|
//Clear the vector of SPPF nodes created every step
|
||||||
// for (std::vector<NodeTree<Symbol*>*>::size_type j = 0; j < SPPFStepNodes.size(); j++)
|
|
||||||
// SPPFStepNodes[j] = NULL;
|
|
||||||
SPPFStepNodes.clear();
|
SPPFStepNodes.clear();
|
||||||
|
|
||||||
while (toReduce.size() != 0) {
|
while (toReduce.size() != 0) {
|
||||||
@@ -244,14 +242,14 @@ void RNGLRParser::addChildren(NodeTree<Symbol*>* parent, std::vector<NodeTree<Sy
|
|||||||
parent->addChildren(children);
|
parent->addChildren(children);
|
||||||
} else {
|
} else {
|
||||||
if (!arePacked(parent->getChildren())) {
|
if (!arePacked(parent->getChildren())) {
|
||||||
NodeTree<Symbol*>* subParent = new NodeTree<Symbol*>();
|
NodeTree<Symbol*>* subParent = new NodeTree<Symbol*>("AmbiguityPackInner", NULL);
|
||||||
setPacked(subParent, true);
|
setPacked(subParent, true);
|
||||||
std::vector<NodeTree<Symbol*>*> tmp = parent->getChildren();
|
std::vector<NodeTree<Symbol*>*> tmp = parent->getChildren();
|
||||||
subParent->addChildren(&tmp);
|
subParent->addChildren(&tmp);
|
||||||
parent->clearChildren();
|
parent->clearChildren();
|
||||||
parent->addChild(subParent);
|
parent->addChild(subParent);
|
||||||
}
|
}
|
||||||
NodeTree<Symbol*>* t = new NodeTree<Symbol*>();
|
NodeTree<Symbol*>* t = new NodeTree<Symbol*>("AmbiguityPackOuter", NULL);
|
||||||
setPacked(t, true);
|
setPacked(t, true);
|
||||||
parent->addChild(t);
|
parent->addChild(t);
|
||||||
t->addChildren(children);
|
t->addChildren(children);
|
||||||
|
|||||||
17
src/util.cpp
17
src/util.cpp
@@ -21,15 +21,28 @@ std::string removeBeginning(std::string to_remove)
|
|||||||
return to_return;
|
return to_return;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string replace(std::string first, std::string search, std::string replace) {
|
std::string replaceExEscape(std::string first, std::string search, std::string replace) {
|
||||||
size_t pos = 0;
|
size_t pos = 0;
|
||||||
while (pos < first.size()-search.size()) {
|
while (pos < first.size()-search.size()) {
|
||||||
pos = first.find(search, pos);
|
pos = first.find(search, pos);
|
||||||
if (pos == std::string::npos)
|
if (pos == std::string::npos)
|
||||||
break;
|
break;
|
||||||
//std::cout << "Position is " << pos << " size of first is " << first.size() << " size of replace is " << replace.size() << std::endl;
|
//std::cout << "Position is " << pos << " size of first is " << first.size() << " size of replace is " << replace.size() << std::endl;
|
||||||
|
//If excaped, don't worry about it.
|
||||||
|
if (pos > 0) {
|
||||||
|
int numBackslashes = 0;
|
||||||
|
int countBack = 1;
|
||||||
|
while (pos-countBack >= 0 && first[pos-countBack] == '\\') {
|
||||||
|
numBackslashes++;
|
||||||
|
countBack++;
|
||||||
|
}
|
||||||
|
if (numBackslashes % 2 == 1) {
|
||||||
|
pos++;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
}
|
||||||
first = first.replace(pos, search.size(), replace);
|
first = first.replace(pos, search.size(), replace);
|
||||||
pos++;
|
pos += replace.size();
|
||||||
}
|
}
|
||||||
return first;
|
return first;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user