handle boost::spirit::qi::expectation_failure

This commit is contained in:
Dane Springmeyer 2014-10-24 19:28:51 -07:00
parent f80d1f9c00
commit ecb529cba2
2 changed files with 16 additions and 5 deletions

View file

@ -40,12 +40,18 @@ expression_ptr parse_expression(std::string const& str)
auto node = std::make_shared<expr_node>();
std::string::const_iterator itr = str.begin();
std::string::const_iterator end = str.end();
bool r = boost::spirit::qi::phrase_parse(itr, end, g, space, *node);
if (r && itr == end)
{
return node;
try {
bool r = boost::spirit::qi::phrase_parse(itr, end, g, space, *node);
if (r && itr == end)
{
return node;
}
else
{
throw config_error("Failed to parse expression: \"" + str + "\"");
}
}
else
catch (std::exception const&) // boost::spirit::qi::expectation_failure
{
throw config_error("Failed to parse expression: \"" + str + "\"");
}

View file

@ -441,5 +441,10 @@ def test_division_by_zero():
f['b'] = 0
eq_(expr.evaluate(f),None)
@raises(RuntimeError)
def test_invalid_syntax1():
expr = mapnik.Expression('abs()')
if __name__ == "__main__":
exit(run_all(eval(x) for x in dir() if x.startswith("test_")))