From db4fdd473c2c04ddfc719e5042315aed59e26dd0 Mon Sep 17 00:00:00 2001 From: sjunges Date: Mon, 23 May 2016 14:28:12 +0200 Subject: [PATCH] JaniParser: parse automaton name and locations Former-commit-id: bd4abc86c8e28e86970c417f7b445b47a4180bef --- src/parser/JaniParser.cpp | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/src/parser/JaniParser.cpp b/src/parser/JaniParser.cpp index bf03db99d..474e43a58 100644 --- a/src/parser/JaniParser.cpp +++ b/src/parser/JaniParser.cpp @@ -10,6 +10,13 @@ namespace storm { namespace parser { + + std::string getString(json const& structure, std::string const& errorInfo) { + STORM_LOG_THROW(structure.is_string(), storm::exceptions::InvalidJaniException, "Expected a string in " << errorInfo << ", got '" << structure.dump() << "'"); + return structure.front(); + } + + storm::jani::Model JaniParser::parse(std::string const& path) { JaniParser parser; parser.readFile(path); @@ -52,7 +59,20 @@ namespace storm { } storm::jani::Automaton JaniParser::parseAutomaton(json const &automatonStructure) { + STORM_LOG_THROW(automatonStructure.count("name") == 1, storm::exceptions::InvalidJaniException, "Each automaton must have a name"); + std::string name = getString(parsedStructure.at("name"), " the name field for automaton"); + storm::jani::Automaton automaton(name); + STORM_LOG_THROW(automatonStructure.count("locations") > 0, storm::exceptions::InvalidJaniException, "Automaton " << name << " does not have locations."); + std::unordered_map locIds; + for(auto const& locEntry : parsedStructure.at("locations")) { + std::string locName = getString(locEntry, "location of automaton " + name); + STORM_LOG_THROW(locIds.count(locName) == 0, storm::exceptions::InvalidJaniException, "Location with name '" + locName + "' already exists in automaton '" + name + "'"); + uint64_t id = automaton.addLocation(storm::jani::Location(locName)); + locIds.emplace(locName, id); + } + + return automaton; } std::shared_ptr JaniParser::parseComposition(json const &compositionStructure) {