Geometry/Feature parsers -truncate 'where' message in on_error handler (currently 16 chars max)
This commit is contained in:
parent
1e1e2d1e79
commit
5d0c36fb65
4 changed files with 29 additions and 4 deletions
|
@ -128,6 +128,7 @@ struct feature_grammar :
|
|||
|
||||
phoenix::function<put_property> put_property_;
|
||||
phoenix::function<extract_geometry> extract_geometry_;
|
||||
boost::phoenix::function<where_message> where_message_;
|
||||
|
||||
geometry_grammar<Iterator> geometry_grammar_;
|
||||
};
|
||||
|
|
|
@ -73,6 +73,21 @@ struct cleanup
|
|||
}
|
||||
};
|
||||
|
||||
struct where_message
|
||||
{
|
||||
typedef std::string result_type;
|
||||
|
||||
template <typename Iterator>
|
||||
std::string operator() (Iterator first, Iterator last, std::size_t size) const
|
||||
{
|
||||
std::string str(first, last);
|
||||
if (str.length() > size)
|
||||
return str.substr(0, size) + "..." ;
|
||||
return str;
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
template <typename Iterator>
|
||||
struct geometry_grammar :
|
||||
qi::grammar<Iterator,qi::locals<int>, void(boost::ptr_vector<mapnik::geometry_type>& )
|
||||
|
@ -107,6 +122,7 @@ struct geometry_grammar :
|
|||
boost::phoenix::function<push_vertex> push_vertex_;
|
||||
boost::phoenix::function<close_path> close_path_;
|
||||
boost::phoenix::function<cleanup> cleanup_;
|
||||
boost::phoenix::function<where_message> where_message_;
|
||||
};
|
||||
|
||||
}}
|
||||
|
|
|
@ -135,15 +135,18 @@ feature_grammar<Iterator,FeatureType>::feature_grammar(mapnik::transcoder const&
|
|||
|
||||
attribute_value %= number | string_ ;
|
||||
|
||||
feature.name("Feature");
|
||||
properties.name("Properties");
|
||||
attributes.name("Attributes");
|
||||
|
||||
on_error<fail>
|
||||
(
|
||||
feature
|
||||
, std::clog
|
||||
<< phoenix::val("Error! Expecting ")
|
||||
<< _4 // what failed?
|
||||
<< _4 // what failed?
|
||||
<< phoenix::val(" here: \"")
|
||||
<< construct<std::string>(_3, _2) // iterators to error-pos, end
|
||||
<< where_message_(_3, _2, 16) // where? 16 is max chars to output
|
||||
<< phoenix::val("\"")
|
||||
<< std::endl
|
||||
);
|
||||
|
|
|
@ -146,15 +146,20 @@ geometry_grammar<Iterator>::geometry_grammar()
|
|||
// points
|
||||
points = lit('[')[_a = SEG_MOVETO] > -(point (_a,_r1) % lit(',')[_a = SEG_LINETO]) > lit(']');
|
||||
|
||||
// give some rules names
|
||||
geometry.name("Geometry");
|
||||
geometry_collection.name("GeometryCollection");
|
||||
geometry_dispatch.name("Geometry dispatch");
|
||||
coordinates.name("Coordinates");
|
||||
// error handler
|
||||
on_error<fail>
|
||||
(
|
||||
geometry
|
||||
, std::clog
|
||||
<< boost::phoenix::val("Error! Expecting ")
|
||||
<< _4 // what failed?
|
||||
<< _4 // what failed?
|
||||
<< boost::phoenix::val(" here: \"")
|
||||
<< construct<std::string>(_3, _2) // iterators to error-pos, end
|
||||
<< where_message_(_3, _2, 16) // max 16 chars
|
||||
<< boost::phoenix::val("\"")
|
||||
<< std::endl
|
||||
);
|
||||
|
|
Loading…
Add table
Reference in a new issue