Browse Source

ExpressionParser

refactoring
Sebastian Junges 7 years ago
parent
commit
f98575d82c
  1. 7
      src/storage/expressions.cpp
  2. 8
      tests/storage/test_expressions.py

7
src/storage/expressions.cpp

@ -36,12 +36,15 @@ void define_expressions(py::module& m) {
.def("has_boolean_type", &storm::expressions::Expression::hasBooleanType, "Check if the expression is a boolean")
.def("has_integer_type", &storm::expressions::Expression::hasIntegerType, "Check if the expression is an integer")
.def("has_rational_type", &storm::expressions::Expression::hasRationalType, "Check if the expression is a rational")
.def("__str__", &streamToString<storm::expressions::Expression>)
.def_property_readonly("type", &storm::expressions::Expression::getType, "Get the Type")
.def("__str__", &storm::expressions::Expression::toString, "To string")
;
py::class_<storm::parser::ExpressionParser>(m, "ExpressionParser", "Parser for storm-expressions")
.def(py::init<storm::expressions::ExpressionManager const&>(), "Expression Manager to use", py::arg("expression_manager"))
.def("parse", &storm::parser::ExpressionParser::parseFromString, "parse");
.def("set_identifier_mapping", [](storm::parser::ExpressionParser& p, std::unordered_map<std::string, storm::expressions::Expression> const& identifierMapping) {p.setIdentifierMapping(identifierMapping);}, "sets identifiers")
.def("parse", &storm::parser::ExpressionParser::parseFromString, "parse")
;
py::class_<storm::expressions::Type>(m, "ExpressionType", "The type of an expression")
.def_property_readonly("is_boolean", &storm::expressions::Type::isBooleanType)

8
tests/storage/test_expressions.py

@ -31,3 +31,11 @@ class TestExpressions:
assert not expression.has_boolean_type()
assert not expression.has_integer_type()
assert expression.has_rational_type()
def test_expression_parser(self):
manager = stormpy.ExpressionManager()
ep = stormpy.ExpressionParser(manager)
ep.set_identifier_mapping(dict())
print(ep.parse("true"))
print(ep.parse("1.0"))
assert ep.parse("1.0").has_rational_type()
Loading…
Cancel
Save