fix grammar (use iter_pos parser instead of hacking raw[] directive) + cleanups

This commit is contained in:
artemp 2015-01-16 10:05:02 +01:00
parent 785cf5c09f
commit 8b19793dc8
2 changed files with 13 additions and 23 deletions

View File

@ -2,7 +2,7 @@
*
* This file is part of Mapnik (c++ mapping toolkit)
*
* Copyright (C) 2014 Artem Pavlenko
* Copyright (C) 2015 Artem Pavlenko
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
@ -44,7 +44,6 @@ namespace mapnik { namespace json {
struct empty {};
using position = std::tuple<double,double>;
//using positions = std::vector<position>;
using boxes = std::vector<std::tuple<std::size_t,box2d<double>>>;
namespace qi = boost::spirit::qi;
@ -87,11 +86,9 @@ struct offset_impl
{
using result_type = std::size_t;
template <typename T0, typename T1>
std::size_t operator() (T0 const& begin, T1 const& range) const
std::size_t operator() (T0 const& begin, T1 const& itr) const
{
//std::cerr << std::distance(range.begin(),range.end()) << std::endl;
//std::cerr << std::string(range.begin(),range.end()) << std::endl;
return std::distance(begin, range.begin());
return std::distance(begin, itr);
}
};
@ -101,8 +98,8 @@ struct extract_bounding_box_grammar :
{
extract_bounding_box_grammar();
qi::rule<Iterator, void(boxes&), space_type> start;
qi::rule<Iterator, qi::locals<Iterator,boost::iterator_range<Iterator>>, void(boxes&), space_type> features;
qi::rule<Iterator, void(boxes&, Iterator const&, boost::iterator_range<Iterator> const&), space_type> feature;
qi::rule<Iterator, qi::locals<Iterator,Iterator>, void(boxes&), space_type> features;
qi::rule<Iterator, void(boxes&, Iterator const&, Iterator const&), space_type> feature;
qi::rule<Iterator, void(boxes&,std::size_t), space_type> bounding_box;
qi::rule<Iterator, qi::locals<box2d<double>>, box2d<double>(), space_type> coords;
qi::rule<Iterator, boost::optional<position>(), space_type> pos;

View File

@ -2,7 +2,7 @@
*
* This file is part of Mapnik (c++ mapping toolkit)
*
* Copyright (C) 2014 Artem Pavlenko
* Copyright (C) 2015 Artem Pavlenko
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
@ -59,28 +59,21 @@ extract_bounding_box_grammar<Iterator, ErrorHandler>::extract_bounding_box_gramm
using qi::on_error;
using qi::skip;
using qi::lexeme;
using qi::raw;
using boost::phoenix::push_back;
using boost::spirit::repository::qi::seek;
using boost::spirit::repository::qi::iter_pos;
start = features(_r1)
;
//features = iter_pos[_a = _1] >> *(iter_pos[_b = _1] >> seek[lexeme[skip[lit('{') >> lit("\"type\"") >> ":" >> "\"Feature\""]]]
// >> feature(_r1, _a, _b))
// ;
features = iter_pos[_a = _1] >> -(lit('{') >> -lit("\"type\"") >> lit(':') >> lit("\"FeatureCollection\"")
>> lit(',') >> lit("\"features\"") >> lit(':'))
>> lit('[') >> *(raw[seek[lexeme[skip[iter_pos > lit('{') > lit("\"type\"") > lit(':') > lit("\"Feature\"")]]]] [_b = _1]
> feature(_r1, _a, _b))
features = iter_pos[_a = _1] >> -(lit('{') >> -lit("\"type\"")
>> lit(':') >> lit("\"FeatureCollection\"")
>> lit(',') >> lit("\"features\"")
>> lit(':'))
>> lit('[') >> *(seek[lexeme[skip[iter_pos[_b = _1] >> lit('{') >> lit("\"type\"") >> lit(':') >> lit("\"Feature\"")]]]
>> feature(_r1, _a, _b))
;
//features = iter_pos[_a = _1] >> seek[lexeme[skip[lit("\"type\"") >> lit(':') >> " ]]]
// >> iter_pos[_b = _1] >> *(lit(':') >> feature(_r1, _a, _b) | seek["\"type\""] >> iter_pos[_b = _1])
// ;
feature = /*lit("\"Feature\"") >> */bounding_box(_r1, offset(_r2, _r3))
feature = bounding_box(_r1, offset(_r2, _r3))
;
bounding_box = seek["\"coordinates\""] >> lit(':') >> coords[push_box(_r1, _r2, _1)]
;