handle boost::spirit::qi::expectation_failure
This commit is contained in:
parent
f80d1f9c00
commit
ecb529cba2
2 changed files with 16 additions and 5 deletions
|
@ -40,6 +40,7 @@ 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();
|
||||
try {
|
||||
bool r = boost::spirit::qi::phrase_parse(itr, end, g, space, *node);
|
||||
if (r && itr == end)
|
||||
{
|
||||
|
@ -49,6 +50,11 @@ expression_ptr parse_expression(std::string const& str)
|
|||
{
|
||||
throw config_error("Failed to parse expression: \"" + str + "\"");
|
||||
}
|
||||
}
|
||||
catch (std::exception const&) // boost::spirit::qi::expectation_failure
|
||||
{
|
||||
throw config_error("Failed to parse expression: \"" + str + "\"");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -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_")))
|
||||
|
|
Loading…
Reference in a new issue