Browse Source

Method for parsing node name

main
Matthias Volk 7 years ago
parent
commit
32b9585184
  1. 25
      src/storm-dft/parser/DFTGalileoParser.cpp
  2. 4
      src/storm-dft/parser/DFTGalileoParser.h

25
src/storm-dft/parser/DFTGalileoParser.cpp

@ -19,21 +19,18 @@ namespace storm {
namespace parser { namespace parser {
template<typename ValueType> template<typename ValueType>
std::string DFTGalileoParser<ValueType>::stripQuotsFromName(std::string const& name) {
std::string DFTGalileoParser<ValueType>::parseName(std::string const& name) {
size_t firstQuots = name.find("\""); size_t firstQuots = name.find("\"");
size_t secondQuots = name.find("\"", firstQuots+1); 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 { } 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<typename ValueType>
std::string DFTGalileoParser<ValueType>::parseNodeIdentifier(std::string const& name) {
return boost::replace_all_copy(name, "'", "__prime__");
return boost::replace_all_copy(parsedName, "'", "__prime__");
} }
template<typename ValueType> template<typename ValueType>
@ -95,19 +92,19 @@ namespace storm {
// Top level indicator // Top level indicator
STORM_LOG_THROW(toplevelId == "", storm::exceptions::WrongFormatException, "Toplevel element already defined."); 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 << "."); 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") { } else if (tokens[0] == "param") {
// Parameters // Parameters
STORM_LOG_THROW(tokens.size() == 2, storm::exceptions::WrongFormatException, "Expected parameter name after 'param' in line " << lineNo << "."); STORM_LOG_THROW(tokens.size() == 2, storm::exceptions::WrongFormatException, "Expected parameter name after 'param' in line " << lineNo << ".");
STORM_LOG_THROW((std::is_same<ValueType, storm::RationalFunction>::value), storm::exceptions::NotSupportedException, "Parameters only allowed when using rational functions."); STORM_LOG_THROW((std::is_same<ValueType, storm::RationalFunction>::value), storm::exceptions::NotSupportedException, "Parameters only allowed when using rational functions.");
valueParser.addParameter(stripQuotsFromName(tokens[1]));
valueParser.addParameter(parseName(tokens[1]));
} else { } else {
// DFT element // DFT element
std::string name = parseNodeIdentifier(stripQuotsFromName(tokens[0]));
std::string name = parseName(tokens[0]);
std::vector<std::string> childNames; std::vector<std::string> childNames;
for(unsigned i = 2; i < tokens.size(); ++i) { for(unsigned i = 2; i < tokens.size(); ++i) {
childNames.push_back(parseNodeIdentifier(stripQuotsFromName(tokens[i])));
childNames.push_back(parseName(tokens[i]));
} }
bool success = true; bool success = true;

4
src/storm-dft/parser/DFTGalileoParser.h

@ -32,9 +32,7 @@ namespace storm {
static storm::storage::DFT<ValueType> parseDFT(std::string const& filename, bool defaultInclusive = true, bool binaryDependencies = true); static storm::storage::DFT<ValueType> parseDFT(std::string const& filename, bool defaultInclusive = true, bool binaryDependencies = true);
private: 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);
}; };
} }
} }
Loading…
Cancel
Save