Commit 65553d62 authored by aggsol's avatar aggsol 🙉

improved parser and graph

parent b6cb871d
......@@ -17,10 +17,51 @@
*/
#include "Graph.hpp"
#include <array>
#include <iostream>
#include <fstream>
#include <sstream>
namespace
{
std::array<std::string, 2> s_skipLabels = {
"fixed",
"TODO"
};
bool isSkipLabel(const std::string& l)
{
for(unsigned i=0; i<s_skipLabels.size(); ++i)
{
if(s_skipLabels[i] == l)
{
return true;
}
}
return false;
}
std::array<std::string, 2> s_suffixes = {
"add-item-",
"add-weapon-"
};
std::string trimLabel(const std::string& l)
{
std::string result = l;
for(unsigned i=0; i<s_suffixes.size(); ++i)
{
auto pos = result.find(s_suffixes[i]);
if(pos != std::string::npos)
{
result.erase(pos, s_suffixes[i].size());
}
}
return result;
}
}
namespace bodhi
{
void Graph::createDotFile(const std::map<int, Section>& sections)
......@@ -32,21 +73,38 @@ void Graph::createDotFile(const std::map<int, Section>& sections)
}
dotfile << "digraph G {\n"
<< "forcelabels=true;"
<< " node [style=filled fillcolor=white];\n";
<< " node [style=filled fillcolor=white labelfontname=Arial labelfontsize=10];\n";
for(auto& s: sections)
{
int sectionNum = s.second.m_number;
std::ostringstream label;
label << " " << sectionNum << " [xlabel=\"";
unsigned counter = 0;
for(auto& attr: s.second.m_classes)
{
if(attr == "TODO")
{
dotfile << " " << sectionNum << "[fillcolor=red];\n";
continue;
}
if(attr == "fixed")
{
dotfile << " " << sectionNum << "[shape=box];\n";
continue;
}
if(isSkipLabel(attr))
{
continue;
}
if(counter > 0)
{
label << ", ";
}
label << attr;
label << trimLabel(attr);
counter++;
}
label << "\"];\n";
......
......@@ -135,13 +135,20 @@ void Parser::parseLine(const std::string& line, std::map<int, Section>& sections
case State::ReferenceSection:
if(c == '>')
{
int section = std::stoi(value);
sections[m_currSection].m_children.insert(section);
if(peek != '>')
{
throw std::runtime_error("Expected '>' closing reference");
}
state = State::Start;
try
{
int section = std::stoi(value);
sections[m_currSection].m_children.insert(section);
state = State::Start;
}
catch(const std::exception& ex)
{
throw std::runtime_error("Invalid section number");
}
}
else if(std::isdigit(c))
{
......@@ -160,8 +167,11 @@ void Parser::parseLine(const std::string& line, std::map<int, Section>& sections
}
else if(c == ']')
{
sections[m_currSection].m_classes.insert(value);
state = State::Done;
if(peek != '#') // skip inline span styles
{
sections[m_currSection].m_classes.insert(value);
}
state = State::Start;
}
else if(c == '.')
{
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment