You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

101 lines
5.0 KiB

  1. #pragma once
  2. #include "storm/storage/jani/Constant.h"
  3. #include "storm/logic/Formula.h"
  4. #include "storm/logic/Bound.h"
  5. #include "storm/exceptions/FileIoException.h"
  6. #include "storm/storage/expressions/ExpressionManager.h"
  7. // JSON parser
  8. #include "json.hpp"
  9. using json = nlohmann::json;
  10. namespace storm {
  11. namespace jani {
  12. class Model;
  13. class Automaton;
  14. class Variable;
  15. class Composition;
  16. class Property;
  17. class PropertyInterval;
  18. }
  19. namespace logic {
  20. enum class FormulaContext;
  21. }
  22. namespace parser {
  23. /*
  24. * The JANI format parser.
  25. * Parses Models and Properties
  26. *
  27. * TODO some parts are copy-heavy, a bit of cleaning is good as soon as the format is stable.
  28. */
  29. class JaniParser {
  30. public:
  31. typedef std::vector<storm::jani::Property> PropertyVector;
  32. JaniParser() : expressionManager(new storm::expressions::ExpressionManager()) {}
  33. JaniParser(std::string const& jsonstring);
  34. static std::pair<storm::jani::Model, std::map<std::string, storm::jani::Property>> parse(std::string const& path);
  35. protected:
  36. void readFile(std::string const& path);
  37. std::pair<storm::jani::Model, std::map<std::string, storm::jani::Property>> parseModel(bool parseProperties = true);
  38. storm::jani::Property parseProperty(json const& propertyStructure);
  39. storm::jani::Automaton parseAutomaton(json const& automatonStructure, storm::jani::Model const& parentModel);
  40. std::shared_ptr<storm::jani::Variable> parseVariable(json const& variableStructure, std::string const& scopeDescription, bool prefWithScope = false);
  41. storm::expressions::Expression parseExpression(json const& expressionStructure, std::string const& scopeDescription, std::unordered_map<std::string, std::shared_ptr<storm::jani::Variable>> const& localVars = std::unordered_map<std::string, std::shared_ptr<storm::jani::Variable>>(), bool returnNoneOnUnknownOpString = false);
  42. private:
  43. std::shared_ptr<storm::jani::Constant> parseConstant(json const& constantStructure, std::string const& scopeDescription = "global");
  44. /**
  45. * Helper for parsing the actions of a model.
  46. */
  47. void parseActions(json const& actionStructure, storm::jani::Model& parentModel);
  48. std::shared_ptr<storm::logic::Formula const> parseFormula(json const& propertyStructure, storm::logic::FormulaContext formulaContext, std::string const& context, boost::optional<storm::logic::Bound<storm::RationalNumber>> bound = boost::none);
  49. std::vector<storm::expressions::Expression> parseUnaryExpressionArguments(json const& expressionStructure, std::string const& opstring, std::string const& scopeDescription, std::unordered_map<std::string, std::shared_ptr<storm::jani::Variable>> const& localVars = {}, bool returnNoneOnUnknownOpString = false);
  50. std::vector<storm::expressions::Expression> parseBinaryExpressionArguments(json const& expressionStructure, std::string const& opstring, std::string const& scopeDescription, std::unordered_map<std::string, std::shared_ptr<storm::jani::Variable>> const& localVars = {}, bool returnNoneOnUnknownOpString = false);
  51. std::vector<std::shared_ptr<storm::logic::Formula const>> parseUnaryFormulaArgument(json const& propertyStructure, storm::logic::FormulaContext formulaContext, std::string const& opstring, std::string const& context);
  52. std::vector<std::shared_ptr<storm::logic::Formula const>> parseBinaryFormulaArguments(json const& propertyStructure, storm::logic::FormulaContext formulaContext, std::string const& opstring, std::string const& context);
  53. storm::jani::PropertyInterval parsePropertyInterval(json const& piStructure);
  54. std::shared_ptr<storm::jani::Composition> parseComposition(json const& compositionStructure);
  55. storm::expressions::Variable getVariableOrConstantExpression(std::string const& ident, std::string const& scopeDescription, std::unordered_map<std::string, std::shared_ptr<storm::jani::Variable>> const& localVars = {});
  56. /**
  57. * The overall structure currently under inspection.
  58. */
  59. json parsedStructure;
  60. /**
  61. * The expression manager to be used.
  62. */
  63. std::shared_ptr<storm::expressions::ExpressionManager> expressionManager;
  64. std::set<std::string> labels = {};
  65. bool allowRecursion = true;
  66. //////////
  67. // Default values -- assumptions from JANI.
  68. //////////
  69. static const bool defaultVariableTransient;
  70. static const bool defaultBooleanInitialValue;
  71. static const double defaultRationalInitialValue;
  72. static const int64_t defaultIntegerInitialValue;
  73. static const std::set<std::string> unsupportedOpstrings;
  74. };
  75. }
  76. }