From ed8c8df73855edffd7676292dd69e9d4d6b6a358 Mon Sep 17 00:00:00 2001 From: Mickey Rose Date: Sat, 6 Feb 2016 18:39:56 +0100 Subject: [PATCH] expression_grammar: use one symbol table for all constants --- include/mapnik/expression_grammar.hpp | 41 +--------------------- include/mapnik/expression_grammar_impl.hpp | 24 +++++++++---- 2 files changed, 19 insertions(+), 46 deletions(-) diff --git a/include/mapnik/expression_grammar.hpp b/include/mapnik/expression_grammar.hpp index ff9423ea3..ea65425a0 100644 --- a/include/mapnik/expression_grammar.hpp +++ b/include/mapnik/expression_grammar.hpp @@ -107,43 +107,6 @@ struct regex_replace_impl mapnik::transcoder const& tr_; }; -struct geometry_types : qi::symbols -{ - geometry_types() - { - add - ("point", 1) - ("linestring", 2) - ("polygon",3) - ("collection",4) - ; - } -}; - -struct boolean_constants : qi::symbols -{ - boolean_constants() - { - add - ("true", true) - ("false", false) - ; - } -}; - -struct floating_point_constants : qi::symbols -{ - floating_point_constants() - { - add - ("pi", 3.1415926535897932384626433832795) - ("deg_to_rad",0.017453292519943295769236907684886) - ("rad_to_deg",57.295779513082320876798154814105) - ; - } -}; - - template struct integer_parser { @@ -200,9 +163,7 @@ struct expression_grammar : qi::grammar qi::symbols unesc_char; qi::rule quote_char; - geometry_types geom_type; - boolean_constants bool_const; - floating_point_constants float_const; + qi::symbols constant; unary_function_types unary_func_type; binary_function_types binary_func_type; diff --git a/include/mapnik/expression_grammar_impl.hpp b/include/mapnik/expression_grammar_impl.hpp index 9c82cb8c5..c2c23e050 100644 --- a/include/mapnik/expression_grammar_impl.hpp +++ b/include/mapnik/expression_grammar_impl.hpp @@ -103,6 +103,20 @@ expression_grammar::expression_grammar(std::string const& encoding) standard_wide::char_type char_; standard_wide::no_case_type no_case; using boost::phoenix::construct; + using boost::phoenix::if_else; + + constant.add + ("null", mapnik::value_null()) + ("false", mapnik::value_bool(false)) + ("true", mapnik::value_bool(true)) + ("point", mapnik::value_integer(1)) + ("linestring", mapnik::value_integer(2)) + ("polygon", mapnik::value_integer(3)) + ("collection", mapnik::value_integer(4)) + ("pi", mapnik::value_double(3.1415926535897932384626433832795)) + ("deg_to_rad", mapnik::value_double(0.017453292519943295769236907684886)) + ("rad_to_deg", mapnik::value_double(57.295779513082320876798154814105)) + ; expr = logical_expr.alias(); @@ -180,13 +194,11 @@ expression_grammar::expression_grammar(std::string const& encoding) primary_expr = strict_double [_val = _1] | int__[_val = _1] - | no_case[bool_const][_val = _1] - | no_case[lit("null")] [_val = value_null() ] - | no_case[geom_type][_val = _1 ] - | no_case[float_const] [_val = _1 ] + | no_case[constant] [_val = _1] | quoted_ustring [_val = unicode_(_1)] - | lit("[mapnik::geometry_type]")[_val = construct()] - | attr [_val = construct( _1 ) ] + | attr [if_else(_1 == "mapnik::geometry_type", + _val = construct(), + _val = construct(_1))] | global_attr [_val = construct( _1 )] | lit("not") >> expr [_val = !_1] | unary_function_expr [_val = _1]