avoid parsing synthesised std::tuple<> + more fine-grained rules

This commit is contained in:
artemp 2016-12-19 17:52:01 +01:00
parent 47cdd22fad
commit f1ccc66162
2 changed files with 19 additions and 14 deletions

View file

@ -255,13 +255,23 @@ auto assign_properties = [] (auto const& ctx)
std::get<3>(_val(ctx)) = std::move(_attr(ctx));
};
auto assign_prop_name = [] (auto const& ctx)
{
std::get<0>(_val(ctx)) = std::move(_attr(ctx));
};
auto assign_prop_value = [] (auto const& ctx)
{
std::get<1>(_val(ctx)) = std::move(_attr(ctx));
};
namespace x3 = boost::spirit::x3;
using x3::lit;
using x3::double_;
using x3::int_;
using x3::omit;
using x3::char_;
namespace
{
// import unicode string rule
@ -296,6 +306,7 @@ topojson_grammar_type const topology = "Topology";
x3::rule<class transform_tag, mapnik::topojson::transform> transform = "Transform";
x3::rule<class bbox_tag, mapnik::topojson::bounding_box> bbox = "Bounding Box";
x3::rule<class objects_tag, std::vector<mapnik::topojson::geometry>> objects= "Objects";
x3::rule<class property_tag, mapnik::topojson::property> property = "Property";
x3::rule<class properties_tag, mapnik::topojson::properties> properties = "Properties";
x3::rule<class geometry_tag, mapnik::topojson::geometry> geometry = "Geometry";
x3::rule<class geometry_collection_tag, std::vector<mapnik::topojson::geometry>> geometry_collection = "Geometry Collection";
@ -346,7 +357,7 @@ auto const bbox_def = lit("\"bbox\"") > lit(':')
auto const objects_def = lit("\"objects\"") > lit(':')
> lit('{')
> ((omit[json_string] > lit(':') > ((geometry_collection[push_collection] | geometry[push_geometry]))) % lit(','))
> ((omit[*~char_(':')] > lit(':') > ((geometry_collection[push_collection] | geometry[push_geometry]))) % lit(','))
> lit('}')
;
@ -359,7 +370,7 @@ auto const geometry_tuple_def =
|
properties[assign_properties]
|
omit[json_string >> lit(':') >> json_value]) % lit(',')
omit[json_string] > lit(':') > omit[json_value]) % lit(',')
;
auto const geometry_def = lit("{") > geometry_tuple[create_geometry] > lit("}");
@ -384,9 +395,12 @@ auto const rings_array_def = (lit('[') >> (rings % lit(',')) >> lit(']'))
ring
;
auto const property_def = json_string[assign_prop_name] > lit(':') > json_value[assign_prop_value]
;
auto const properties_def = lit("\"properties\"")
> lit(':')
> lit('{') > (json_string > lit(':') > json_value) % lit(',') > lit('}')
> lit('{') > (property % lit(',')) > lit('}')
;
auto const arcs_def = lit("\"arcs\"") >> lit(':') >> lit('[') >> -( arc % lit(',')) >> lit(']') ;
@ -408,6 +422,7 @@ BOOST_SPIRIT_DEFINE(
ring,
rings,
rings_array,
property,
properties,
arcs,
arc,

View file

@ -23,11 +23,6 @@
#include <mapnik/json/unicode_string_grammar_x3_def.hpp>
#include <mapnik/json/json_grammar_config.hpp>
#include <mapnik/json/extract_bounding_boxes_x3_config.hpp>
#include <mapnik/json/json_value.hpp>
#pragma GCC diagnostic push
#include <mapnik/warning_ignore.hpp>
#include <boost/fusion/adapted/std_tuple.hpp>
#pragma GCC diagnostic pop
namespace mapnik { namespace json { namespace grammar {
@ -48,9 +43,4 @@ BOOST_SPIRIT_INSTANTIATE_UNUSED(unicode_string_grammar_type, iterator_type, extr
BOOST_SPIRIT_INSTANTIATE_UNUSED(unicode_string_grammar_type, iterator_type, extract_bounding_boxes_context_type_f);
BOOST_SPIRIT_INSTANTIATE_UNUSED(unicode_string_grammar_type, iterator_type, extract_bounding_boxes_reverse_context_type_f);
using attribute_type = boost::fusion::iterator_range<boost::fusion::std_tuple_iterator<std::tuple<std::string, mapnik::json::json_value>, 0>, boost::fusion::std_tuple_iterator<std::tuple<std::string, mapnik::json::json_value>, 1>>;
template bool mapnik::json::grammar::parse_rule<iterator_type, phrase_parse_context_type, attribute_type> (
unicode_string_grammar_type, iterator_type&, iterator_type const&, phrase_parse_context_type const&, attribute_type &);
}}}