#pragma once #include "storm/storage/jani/Constant.h" #include "storm/logic/Formula.h" #include "storm/logic/Bound.h" #include "storm/exceptions/FileIoException.h" #include "storm/storage/expressions/ExpressionManager.h" // JSON parser #include "json.hpp" using json = nlohmann::json; namespace storm { namespace jani { class Model; class Automaton; class Variable; class Composition; class Property; class PropertyInterval; } namespace logic { enum class FormulaContext; } namespace parser { /* * The JANI format parser. * Parses Models and Properties * * TODO some parts are copy-heavy, a bit of cleaning is good as soon as the format is stable. */ class JaniParser { public: typedef std::vector PropertyVector; JaniParser() : expressionManager(new storm::expressions::ExpressionManager()) {} JaniParser(std::string const& jsonstring); static std::pair> parse(std::string const& path); protected: void readFile(std::string const& path); std::pair> parseModel(bool parseProperties = true); storm::jani::Property parseProperty(json const& propertyStructure); storm::jani::Automaton parseAutomaton(json const& automatonStructure, storm::jani::Model const& parentModel); std::shared_ptr parseVariable(json const& variableStructure, std::string const& scopeDescription, bool prefWithScope = false); storm::expressions::Expression parseExpression(json const& expressionStructure, std::string const& scopeDescription, std::unordered_map> const& localVars = std::unordered_map>(), bool returnNoneOnUnknownOpString = false); private: std::shared_ptr parseConstant(json const& constantStructure, std::string const& scopeDescription = "global"); /** * Helper for parsing the actions of a model. */ void parseActions(json const& actionStructure, storm::jani::Model& parentModel); std::shared_ptr parseFormula(json const& propertyStructure, storm::logic::FormulaContext formulaContext, std::string const& context, boost::optional> bound = boost::none); std::vector parseUnaryExpressionArguments(json const& expressionStructure, std::string const& opstring, std::string const& scopeDescription, std::unordered_map> const& localVars = {}, bool returnNoneOnUnknownOpString = false); std::vector parseBinaryExpressionArguments(json const& expressionStructure, std::string const& opstring, std::string const& scopeDescription, std::unordered_map> const& localVars = {}, bool returnNoneOnUnknownOpString = false); std::vector> parseUnaryFormulaArgument(json const& propertyStructure, storm::logic::FormulaContext formulaContext, std::string const& opstring, std::string const& context); std::vector> parseBinaryFormulaArguments(json const& propertyStructure, storm::logic::FormulaContext formulaContext, std::string const& opstring, std::string const& context); storm::jani::PropertyInterval parsePropertyInterval(json const& piStructure); std::shared_ptr parseComposition(json const& compositionStructure); storm::expressions::Variable getVariableOrConstantExpression(std::string const& ident, std::string const& scopeDescription, std::unordered_map> const& localVars = {}); /** * The overall structure currently under inspection. */ json parsedStructure; /** * The expression manager to be used. */ std::shared_ptr expressionManager; std::set labels = {}; bool allowRecursion = true; ////////// // Default values -- assumptions from JANI. ////////// static const bool defaultVariableTransient; static const bool defaultBooleanInitialValue; static const double defaultRationalInitialValue; static const int64_t defaultIntegerInitialValue; static const std::set unsupportedOpstrings; }; } }