diff --git a/src/storage/expressions.cpp b/src/storage/expressions.cpp index 1a4db7b..87613f4 100644 --- a/src/storage/expressions.cpp +++ b/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) + .def_property_readonly("type", &storm::expressions::Expression::getType, "Get the Type") + .def("__str__", &storm::expressions::Expression::toString, "To string") ; py::class_(m, "ExpressionParser", "Parser for storm-expressions") .def(py::init(), "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 const& identifierMapping) {p.setIdentifierMapping(identifierMapping);}, "sets identifiers") + .def("parse", &storm::parser::ExpressionParser::parseFromString, "parse") + ; py::class_(m, "ExpressionType", "The type of an expression") .def_property_readonly("is_boolean", &storm::expressions::Type::isBooleanType) diff --git a/tests/storage/test_expressions.py b/tests/storage/test_expressions.py index c78421c..0e82122 100644 --- a/tests/storage/test_expressions.py +++ b/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()