From 32b958518412ca0a8d295343e82717c86fd46e87 Mon Sep 17 00:00:00 2001 From: Matthias Volk Date: Wed, 14 Feb 2018 23:11:38 +0100 Subject: [PATCH] Method for parsing node name --- src/storm-dft/parser/DFTGalileoParser.cpp | 25 ++++++++++------------- src/storm-dft/parser/DFTGalileoParser.h | 4 +--- 2 files changed, 12 insertions(+), 17 deletions(-) diff --git a/src/storm-dft/parser/DFTGalileoParser.cpp b/src/storm-dft/parser/DFTGalileoParser.cpp index c5d1b9c36..ac9687da2 100644 --- a/src/storm-dft/parser/DFTGalileoParser.cpp +++ b/src/storm-dft/parser/DFTGalileoParser.cpp @@ -19,21 +19,18 @@ namespace storm { namespace parser { template - std::string DFTGalileoParser::stripQuotsFromName(std::string const& name) { + std::string DFTGalileoParser::parseName(std::string const& name) { size_t firstQuots = name.find("\""); size_t secondQuots = name.find("\"", firstQuots+1); + std::string parsedName; - if(firstQuots == std::string::npos) { - return name; + if (firstQuots == std::string::npos) { + parsedName = name; } else { - STORM_LOG_THROW(secondQuots != std::string::npos, storm::exceptions::FileIoException, "No ending quotation mark found in " << name); - return name.substr(firstQuots+1,secondQuots-1); + STORM_LOG_THROW(secondQuots != std::string::npos, storm::exceptions::WrongFormatException, "No ending quotation mark found in " << name); + parsedName = name.substr(firstQuots+1,secondQuots-1); } - } - - template - std::string DFTGalileoParser::parseNodeIdentifier(std::string const& name) { - return boost::replace_all_copy(name, "'", "__prime__"); + return boost::replace_all_copy(parsedName, "'", "__prime__"); } template @@ -95,19 +92,19 @@ namespace storm { // Top level indicator STORM_LOG_THROW(toplevelId == "", storm::exceptions::WrongFormatException, "Toplevel element already defined."); STORM_LOG_THROW(tokens.size() == 2, storm::exceptions::WrongFormatException, "Expected element id after 'toplevel' in line " << lineNo << "."); - toplevelId = stripQuotsFromName(tokens[1]); + toplevelId = parseName(tokens[1]); } else if (tokens[0] == "param") { // Parameters STORM_LOG_THROW(tokens.size() == 2, storm::exceptions::WrongFormatException, "Expected parameter name after 'param' in line " << lineNo << "."); STORM_LOG_THROW((std::is_same::value), storm::exceptions::NotSupportedException, "Parameters only allowed when using rational functions."); - valueParser.addParameter(stripQuotsFromName(tokens[1])); + valueParser.addParameter(parseName(tokens[1])); } else { // DFT element - std::string name = parseNodeIdentifier(stripQuotsFromName(tokens[0])); + std::string name = parseName(tokens[0]); std::vector childNames; for(unsigned i = 2; i < tokens.size(); ++i) { - childNames.push_back(parseNodeIdentifier(stripQuotsFromName(tokens[i]))); + childNames.push_back(parseName(tokens[i])); } bool success = true; diff --git a/src/storm-dft/parser/DFTGalileoParser.h b/src/storm-dft/parser/DFTGalileoParser.h index f12e0d2fb..6402c1969 100644 --- a/src/storm-dft/parser/DFTGalileoParser.h +++ b/src/storm-dft/parser/DFTGalileoParser.h @@ -32,9 +32,7 @@ namespace storm { static storm::storage::DFT parseDFT(std::string const& filename, bool defaultInclusive = true, bool binaryDependencies = true); private: - static std::string stripQuotsFromName(std::string const& name); - - static std::string parseNodeIdentifier(std::string const& name); + static std::string parseName(std::string const& name); }; } }