Merge branch 'lightmare-expr-no-barewords'

This commit is contained in:
artemp 2016-02-09 14:15:35 +01:00
commit 87c3032e63
2 changed files with 24 additions and 6 deletions

View file

@ -118,7 +118,9 @@ expression_grammar<Iterator>::expression_grammar(std::string const& encoding)
("rad_to_deg", mapnik::value_double(57.295779513082320876798154814105)) ("rad_to_deg", mapnik::value_double(57.295779513082320876798154814105))
; ;
expr = logical_expr.alias(); expr = logical_expr [_val = _1]
| ustring [_val = unicode_(_1)]
;
logical_expr = not_expr [_val = _1] logical_expr = not_expr [_val = _1]
>> >>
@ -181,10 +183,11 @@ expression_grammar<Iterator>::expression_grammar(std::string const& encoding)
) )
; ;
unary_function_expr = unary_func_type > lit('(') > expr > lit(')') unary_function_expr = unary_func_type >> '(' > logical_expr > ')'
; ;
binary_function_expr = binary_func_type > lit('(') > expr > lit(',') > expr > lit(')') binary_function_expr = binary_func_type >> '(' > logical_expr > ','
> logical_expr > ')'
; ;
unary_expr = primary_expr [_val = _1] unary_expr = primary_expr [_val = _1]
@ -200,11 +203,9 @@ expression_grammar<Iterator>::expression_grammar(std::string const& encoding)
_val = construct<mapnik::geometry_type_attribute>(), _val = construct<mapnik::geometry_type_attribute>(),
_val = construct<mapnik::attribute>(_1))] _val = construct<mapnik::attribute>(_1))]
| global_attr [_val = construct<mapnik::global_attribute>( _1 )] | global_attr [_val = construct<mapnik::global_attribute>( _1 )]
| lit("not") >> expr [_val = !_1]
| unary_function_expr [_val = _1] | unary_function_expr [_val = _1]
| binary_function_expr [_val = _1] | binary_function_expr [_val = _1]
| '(' >> expr [_val = _1 ] >> ')' | '(' > logical_expr [_val = _1 ] > ')'
| ustring[_val = unicode_(_1)] // if we get here then try parsing as unquoted string
; ;
unesc_char.add("\\a", '\a')("\\b", '\b')("\\f", '\f')("\\n", '\n') unesc_char.add("\\a", '\a')("\\b", '\b')("\\f", '\f')("\\n", '\n')

View file

@ -62,6 +62,9 @@ TEST_CASE("expressions")
properties_type prop = {{ "foo" , tr.transcode("bar") }, properties_type prop = {{ "foo" , tr.transcode("bar") },
{ "name" , tr.transcode("Québec")}, { "name" , tr.transcode("Québec")},
{ "grass" , tr.transcode("grow")},
{ "wind" , tr.transcode("blow")},
{ "sky" , tr.transcode("is blue")},
{ "double", mapnik::value_double(1.23456)}, { "double", mapnik::value_double(1.23456)},
{ "int" , mapnik::value_integer(123)}, { "int" , mapnik::value_integer(123)},
{ "bool" , mapnik::value_bool(true)}, { "bool" , mapnik::value_bool(true)},
@ -134,6 +137,20 @@ TEST_CASE("expressions")
// logical // logical
TRY_CHECK(eval(" [int] = 123 and [double] = 1.23456 && [bool] = true and [null] = null && [foo] = 'bar' ") == true); TRY_CHECK(eval(" [int] = 123 and [double] = 1.23456 && [bool] = true and [null] = null && [foo] = 'bar' ") == true);
TRY_CHECK(eval(" [int] = 456 or [foo].match('foo') || length([foo]) = 3 ") == true); TRY_CHECK(eval(" [int] = 456 or [foo].match('foo') || length([foo]) = 3 ") == true);
TRY_CHECK(eval(" not true and not true ") == eval(" (not true ) and (not true ) "));
TRY_CHECK(eval(" not true or not true ") == eval(" (not true ) or (not true ) "));
TRY_CHECK(eval(" not false and not false ") == eval(" (not false) and (not false) "));
TRY_CHECK(eval(" not false or not false ") == eval(" (not false) or (not false) "));
// test not/and/or precedence using combinations of "not EQ1 OP1 not EQ2 OP2 not EQ3"
TRY_CHECK(eval(" not [grass] = 'grow' and not [wind] = 'blow' and not [sky] = 'is blue' ") == false);
TRY_CHECK(eval(" not [grass] = 'grow' and not [wind] = 'blow' or not [sky] = 'is blue' ") == false);
TRY_CHECK(eval(" not [grass] = 'grow' or not [wind] = 'blow' and not [sky] = 'is blue' ") == false);
TRY_CHECK(eval(" not [grass] = 'grow' or not [wind] = 'blow' or not [sky] = 'is blue' ") == false);
TRY_CHECK(eval(" not [grass] = 'grew' and not [wind] = 'blew' and not [sky] = 'was blue' ") == true);
TRY_CHECK(eval(" not [grass] = 'grew' and not [wind] = 'blew' or not [sky] = 'was blue' ") == true);
TRY_CHECK(eval(" not [grass] = 'grew' or not [wind] = 'blew' and not [sky] = 'was blue' ") == true);
TRY_CHECK(eval(" not [grass] = 'grew' or not [wind] = 'blew' or not [sky] = 'was blue' ") == true);
// relational // relational
TRY_CHECK(eval(" [int] > 100 and [int] gt 100.0 and [double] < 2 and [double] lt 2.0 ") == true); TRY_CHECK(eval(" [int] > 100 and [int] gt 100.0 and [double] < 2 and [double] lt 2.0 ") == true);