expression_grammar: use one symbol table for all constants

This commit is contained in:
Mickey Rose 2016-02-06 18:39:56 +01:00
parent b24f520439
commit ed8c8df738
2 changed files with 19 additions and 46 deletions

View file

@ -107,43 +107,6 @@ struct regex_replace_impl
mapnik::transcoder const& tr_; mapnik::transcoder const& tr_;
}; };
struct geometry_types : qi::symbols<char, mapnik::value_integer>
{
geometry_types()
{
add
("point", 1)
("linestring", 2)
("polygon",3)
("collection",4)
;
}
};
struct boolean_constants : qi::symbols<char,mapnik::value_bool>
{
boolean_constants()
{
add
("true", true)
("false", false)
;
}
};
struct floating_point_constants : qi::symbols<char,mapnik::value_double>
{
floating_point_constants()
{
add
("pi", 3.1415926535897932384626433832795)
("deg_to_rad",0.017453292519943295769236907684886)
("rad_to_deg",57.295779513082320876798154814105)
;
}
};
template <typename T> template <typename T>
struct integer_parser struct integer_parser
{ {
@ -200,9 +163,7 @@ struct expression_grammar : qi::grammar<Iterator, expr_node(), space_type>
qi::symbols<char const, char const> unesc_char; qi::symbols<char const, char const> unesc_char;
qi::rule<Iterator, char() > quote_char; qi::rule<Iterator, char() > quote_char;
geometry_types geom_type; qi::symbols<char, expr_node> constant;
boolean_constants bool_const;
floating_point_constants float_const;
unary_function_types unary_func_type; unary_function_types unary_func_type;
binary_function_types binary_func_type; binary_function_types binary_func_type;

View file

@ -103,6 +103,20 @@ expression_grammar<Iterator>::expression_grammar(std::string const& encoding)
standard_wide::char_type char_; standard_wide::char_type char_;
standard_wide::no_case_type no_case; standard_wide::no_case_type no_case;
using boost::phoenix::construct; 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(); expr = logical_expr.alias();
@ -180,13 +194,11 @@ expression_grammar<Iterator>::expression_grammar(std::string const& encoding)
primary_expr = strict_double [_val = _1] primary_expr = strict_double [_val = _1]
| int__[_val = _1] | int__[_val = _1]
| no_case[bool_const][_val = _1] | no_case[constant] [_val = _1]
| no_case[lit("null")] [_val = value_null() ]
| no_case[geom_type][_val = _1 ]
| no_case[float_const] [_val = _1 ]
| quoted_ustring [_val = unicode_(_1)] | quoted_ustring [_val = unicode_(_1)]
| lit("[mapnik::geometry_type]")[_val = construct<mapnik::geometry_type_attribute>()] | attr [if_else(_1 == "mapnik::geometry_type",
| attr [_val = construct<mapnik::attribute>( _1 ) ] _val = construct<mapnik::geometry_type_attribute>(),
_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] | lit("not") >> expr [_val = !_1]
| unary_function_expr [_val = _1] | unary_function_expr [_val = _1]