From ea42cb5bc76e543ab0adcadd50a977089a3ac589 Mon Sep 17 00:00:00 2001 From: Nathan Braswell Date: Sun, 11 Aug 2013 00:37:12 -0400 Subject: [PATCH] The out of orderness was actually the fault of the dot graphing program, not Kraken, so that's good news. DOT generation has also been modified so that it properly inserts \n's (actually \n's) where line returns are so that dot can parse the \n and not the line return. --- include/NodeTree.h | 13 ++++++------- include/util.h | 2 ++ src/RNGLRParser.cpp | 2 +- src/util.cpp | 15 ++++++++++++++- 4 files changed, 23 insertions(+), 9 deletions(-) diff --git a/include/NodeTree.h b/include/NodeTree.h index a57e9f6..f11fd16 100644 --- a/include/NodeTree.h +++ b/include/NodeTree.h @@ -5,15 +5,11 @@ #define NULL 0 #endif -#include -//#include - #include #include #include -//Circular references -//class Symbol; +#include "util.h" template class NodeTree { @@ -227,9 +223,12 @@ std::string NodeTree::DOTGraphStringHelper() { template std::string NodeTree::getDOTName() { + std::string DOTName = ""; if (data != NULL) - return "\"" + 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 - return "\"" + name + "_" + intToString(id) + "\""; + 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 + else + DOTName = "\"" + name + "_" + intToString(id) + "\""; + return(replace(DOTName, "\n", "\\n")); } #endif \ No newline at end of file diff --git a/include/util.h b/include/util.h index 75fe1c4..80ab9de 100644 --- a/include/util.h +++ b/include/util.h @@ -5,11 +5,13 @@ #define NULL 0 #endif +//#include #include #include std::string intToString(int theInt); std::string truncateEnd(std::string to_truncate); std::string removeBeginning(std::string to_remove); +std::string replace(std::string first, std::string search, std::string replace); #endif \ No newline at end of file diff --git a/src/RNGLRParser.cpp b/src/RNGLRParser.cpp index a0c24aa..0f3270f 100644 --- a/src/RNGLRParser.cpp +++ b/src/RNGLRParser.cpp @@ -78,7 +78,7 @@ NodeTree* RNGLRParser::parseInput(std::string inputString) { std::cout << "Checking if frontier " << i << " is empty" << std::endl; if (gss.frontierIsEmpty(i)) { std::cout << "Frontier " << i << " is empty." << std::endl; - std::cout << "Failed on " << input[i]->toString() << " next: " << input[i+1]->toString() << std::endl; + std::cout << "Failed on " << input[i]->toString() << std::endl; break; } diff --git a/src/util.cpp b/src/util.cpp index c8e2d0b..3553868 100644 --- a/src/util.cpp +++ b/src/util.cpp @@ -19,4 +19,17 @@ std::string removeBeginning(std::string to_remove) for (unsigned int i = 1; i < to_remove.length(); i++) to_return = to_return + to_remove[i]; return to_return; -} \ No newline at end of file +} + +std::string replace(std::string first, std::string search, std::string replace) { + size_t pos = 0; + while (pos < first.size()-search.size()) { + pos = first.find(search, pos); + if (pos == std::string::npos) + break; + //std::cout << "Position is " << pos << " size of first is " << first.size() << " size of replace is " << replace.size() << std::endl; + first = first.replace(pos, search.size(), replace); + pos++; + } + return first; +}