first attempt to re-use generic JSON rules in geojson/topojson parsers
This commit is contained in:
parent
2eaf6a1ead
commit
c7a989ae83
2 changed files with 31 additions and 25 deletions
|
@ -126,15 +126,9 @@ struct extract_geometry
|
||||||
};
|
};
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
template <typename Iterator, typename FeatureType>
|
template <typename Iterator>
|
||||||
struct feature_grammar :
|
struct generic_json
|
||||||
qi::grammar<Iterator, void(FeatureType&),
|
|
||||||
space_type>
|
|
||||||
{
|
{
|
||||||
feature_grammar(mapnik::transcoder const& tr);
|
|
||||||
|
|
||||||
// start
|
|
||||||
// generic JSON
|
|
||||||
qi::rule<Iterator,space_type> value;
|
qi::rule<Iterator,space_type> value;
|
||||||
qi::symbols<char const, char const> unesc_char;
|
qi::symbols<char const, char const> unesc_char;
|
||||||
qi::uint_parser< unsigned, 16, 4, 4 > hex4 ;
|
qi::uint_parser< unsigned, 16, 4, 4 > hex4 ;
|
||||||
|
@ -147,6 +141,18 @@ struct feature_grammar :
|
||||||
qi::rule<Iterator,space_type> array;
|
qi::rule<Iterator,space_type> array;
|
||||||
qi::rule<Iterator,space_type> pairs;
|
qi::rule<Iterator,space_type> pairs;
|
||||||
qi::real_parser<double, qi::strict_real_policies<double> > strict_double;
|
qi::real_parser<double, qi::strict_real_policies<double> > strict_double;
|
||||||
|
};
|
||||||
|
|
||||||
|
template <typename Iterator, typename FeatureType>
|
||||||
|
struct feature_grammar :
|
||||||
|
qi::grammar<Iterator, void(FeatureType&),
|
||||||
|
space_type>
|
||||||
|
{
|
||||||
|
feature_grammar(mapnik::transcoder const& tr);
|
||||||
|
|
||||||
|
// start
|
||||||
|
// generic JSON
|
||||||
|
generic_json<Iterator> json;
|
||||||
|
|
||||||
// geoJSON
|
// geoJSON
|
||||||
qi::rule<Iterator,void(FeatureType&),space_type> feature; // START
|
qi::rule<Iterator,void(FeatureType&),space_type> feature; // START
|
||||||
|
|
|
@ -66,37 +66,37 @@ feature_grammar<Iterator,FeatureType>::feature_grammar(mapnik::transcoder const&
|
||||||
using phoenix::construct;
|
using phoenix::construct;
|
||||||
|
|
||||||
// generic json types
|
// generic json types
|
||||||
value = object | array | string_
|
json.value = json.object | json.array | json.string_
|
||||||
| number
|
| json.number
|
||||||
;
|
;
|
||||||
|
|
||||||
pairs = key_value % lit(',')
|
json.pairs = json.key_value % lit(',')
|
||||||
;
|
;
|
||||||
|
|
||||||
key_value = (string_ >> lit(':') >> value)
|
json.key_value = (json.string_ >> lit(':') >> json.value)
|
||||||
;
|
;
|
||||||
|
|
||||||
object = lit('{')
|
json.object = lit('{')
|
||||||
>> *pairs
|
>> *json.pairs
|
||||||
>> lit('}')
|
>> lit('}')
|
||||||
;
|
;
|
||||||
array = lit('[')
|
json.array = lit('[')
|
||||||
>> value >> *(lit(',') >> value)
|
>> json.value >> *(lit(',') >> json.value)
|
||||||
>> lit(']')
|
>> lit(']')
|
||||||
;
|
;
|
||||||
// https://github.com/mapnik/mapnik/issues/1342
|
// https://github.com/mapnik/mapnik/issues/1342
|
||||||
#if BOOST_VERSION >= 104700
|
#if BOOST_VERSION >= 104700
|
||||||
number %= strict_double
|
json.number %= json.strict_double
|
||||||
#else
|
#else
|
||||||
number = strict_double
|
json.number = json.strict_double
|
||||||
#endif
|
#endif
|
||||||
| int__
|
| json.int__
|
||||||
| lit("true") [_val = true]
|
| lit("true") [_val = true]
|
||||||
| lit ("false") [_val = false]
|
| lit ("false") [_val = false]
|
||||||
| lit("null")[_val = construct<value_null>()]
|
| lit("null")[_val = construct<value_null>()]
|
||||||
;
|
;
|
||||||
|
|
||||||
unesc_char.add
|
json.unesc_char.add
|
||||||
("\\\"", '\"') // quotation mark
|
("\\\"", '\"') // quotation mark
|
||||||
("\\\\", '\\') // reverse solidus
|
("\\\\", '\\') // reverse solidus
|
||||||
("\\/", '/') // solidus
|
("\\/", '/') // solidus
|
||||||
|
@ -107,10 +107,10 @@ feature_grammar<Iterator,FeatureType>::feature_grammar(mapnik::transcoder const&
|
||||||
("\\t", '\t') // tab
|
("\\t", '\t') // tab
|
||||||
;
|
;
|
||||||
#if BOOST_VERSION > 104200
|
#if BOOST_VERSION > 104200
|
||||||
string_ %= lit('"') >> no_skip[*(unesc_char | "\\u" >> hex4 | (char_ - lit('"')))] >> lit('"')
|
json.string_ %= lit('"') >> no_skip[*(json.unesc_char | "\\u" >> json.hex4 | (char_ - lit('"')))] >> lit('"')
|
||||||
;
|
;
|
||||||
#else
|
#else
|
||||||
string_ %= lit('"') >> lexeme[*(unesc_char | "\\u" >> hex4 | (char_ - lit('"')))] >> lit('"')
|
json.string_ %= lit('"') >> lexeme[*(json.unesc_char | "\\u" >> json.hex4 | (char_ - lit('"')))] >> lit('"')
|
||||||
;
|
;
|
||||||
#endif
|
#endif
|
||||||
// geojson types
|
// geojson types
|
||||||
|
@ -121,7 +121,7 @@ feature_grammar<Iterator,FeatureType>::feature_grammar(mapnik::transcoder const&
|
||||||
;
|
;
|
||||||
|
|
||||||
feature = lit('{')
|
feature = lit('{')
|
||||||
>> (feature_type | (lit("\"geometry\"") > lit(':') > geometry_grammar_(extract_geometry_(_r1))) | properties(_r1) | key_value) % lit(',')
|
>> (feature_type | (lit("\"geometry\"") > lit(':') > geometry_grammar_(extract_geometry_(_r1))) | properties(_r1) | json.key_value) % lit(',')
|
||||||
>> lit('}')
|
>> lit('}')
|
||||||
;
|
;
|
||||||
|
|
||||||
|
@ -129,10 +129,10 @@ feature_grammar<Iterator,FeatureType>::feature_grammar(mapnik::transcoder const&
|
||||||
>> lit(':') >> (lit('{') >> attributes(_r1) >> lit('}')) | lit("null")
|
>> lit(':') >> (lit('{') >> attributes(_r1) >> lit('}')) | lit("null")
|
||||||
;
|
;
|
||||||
|
|
||||||
attributes = (string_ [_a = _1] >> lit(':') >> attribute_value [put_property_(_r1,_a,_1)]) % lit(',')
|
attributes = (json.string_ [_a = _1] >> lit(':') >> attribute_value [put_property_(_r1,_a,_1)]) % lit(',')
|
||||||
;
|
;
|
||||||
|
|
||||||
attribute_value %= number | string_ ;
|
attribute_value %= json.number | json.string_ ;
|
||||||
|
|
||||||
feature.name("Feature");
|
feature.name("Feature");
|
||||||
properties.name("Properties");
|
properties.name("Properties");
|
||||||
|
|
Loading…
Reference in a new issue