avoid symbols duplication

This commit is contained in:
Artem Pavlenko 2018-03-09 09:57:49 +01:00
parent 030b0de105
commit c737f4d56f
8 changed files with 26 additions and 13 deletions

View file

@ -38,9 +38,9 @@ using x3::lit;
using x3::lexeme; using x3::lexeme;
using ascii::char_; using ascii::char_;
struct unesc_char_ : x3::symbols<char> struct csv_unesc_chars_ : x3::symbols<char>
{ {
unesc_char_() csv_unesc_chars_()
{ {
add("\\a", '\a') add("\\a", '\a')
("\\b", '\b') ("\\b", '\b')
@ -55,7 +55,7 @@ struct unesc_char_ : x3::symbols<char>
("\"\"", '\"') // double quote ("\"\"", '\"') // double quote
; ;
} }
} unesc_char; } csv_unesc_chars;
template <typename T> template <typename T>
struct literal : x3::parser<literal<T>> struct literal : x3::parser<literal<T>>
@ -97,7 +97,7 @@ auto const column_def = quoted_text | *(char_ - separator)
auto const quoted_text_def = quote > text > quote // support unmatched quotes or not (??) auto const quoted_text_def = quote > text > quote // support unmatched quotes or not (??)
; ;
auto const text_def = *(unesc_char | (char_ - quote)) auto const text_def = *(csv_unesc_chars | (char_ - quote))
; ;
BOOST_SPIRIT_DEFINE ( BOOST_SPIRIT_DEFINE (

View file

@ -24,7 +24,7 @@
#define MAPNIK_EXPRESSIONS_GRAMMAR_X3_DEF_HPP #define MAPNIK_EXPRESSIONS_GRAMMAR_X3_DEF_HPP
#include <mapnik/expression_grammar_x3.hpp> #include <mapnik/expression_grammar_x3.hpp>
#include <mapnik/json/unicode_string_grammar_x3_def.hpp> #include <mapnik/json/unicode_string_grammar_x3.hpp>
#include <mapnik/expression_node.hpp> #include <mapnik/expression_node.hpp>
#include <mapnik/function_call.hpp> #include <mapnik/function_call.hpp>
#include <mapnik/unicode.hpp> #include <mapnik/unicode.hpp>
@ -67,7 +67,7 @@ namespace mapnik { namespace grammar {
x3::uint_parser<char, 16, 2, 2> const hex2 {}; x3::uint_parser<char, 16, 2, 2> const hex2 {};
namespace { namespace {
auto const& escaped_unicode = json::grammar::escaped_unicode; auto const& escaped_unicode = json::escaped_unicode_grammar();
} }
auto append = [](auto const& ctx) auto append = [](auto const& ctx)

View file

@ -74,7 +74,7 @@ namespace { auto const& json_string = mapnik::json::unicode_string_grammar(); }
// exported rules // exported rules
// start // start
generic_json_grammar_type const value MAPNIK_INIT_PRIORITY(102) ("JSON Value"); generic_json_grammar_type const value MAPNIK_INIT_PRIORITY(103) ("JSON Value");
generic_json_key_value_type const key_value("JSON Object element"); generic_json_key_value_type const key_value("JSON Object element");
// rules // rules
x3::rule<class json_object_tag, json_object> const object("JSON Object"); x3::rule<class json_object_tag, json_object> const object("JSON Object");

View file

@ -43,7 +43,7 @@ auto assign_helper = [](auto const& ctx)
} // anonymous ns } // anonymous ns
// start rule // start rule
positions_grammar_type const positions MAPNIK_INIT_PRIORITY(103) ("Positions"); positions_grammar_type const positions MAPNIK_INIT_PRIORITY(104) ("Positions");
// rules // rules
x3::rule<class point_class, point> const point("Position"); x3::rule<class point_class, point> const point("Position");
x3::rule<class ring_class, ring> const ring("Ring"); x3::rule<class ring_class, ring> const ring("Ring");

View file

@ -306,7 +306,7 @@ struct topojson_geometry_type_ : x3::symbols<int>
} topojson_geometry_type; } topojson_geometry_type;
// start rule // start rule
topojson_grammar_type const topology MAPNIK_INIT_PRIORITY(104) ("Topology"); topojson_grammar_type const topology MAPNIK_INIT_PRIORITY(105) ("Topology");
// rules // rules
x3::rule<class transform_tag, mapnik::topojson::transform> const transform = "Transform"; x3::rule<class transform_tag, mapnik::topojson::transform> const transform = "Transform";
x3::rule<class bbox_tag, mapnik::topojson::bounding_box> const bbox = "Bounding Box"; x3::rule<class bbox_tag, mapnik::topojson::bounding_box> const bbox = "Bounding Box";

View file

@ -33,12 +33,15 @@ namespace mapnik { namespace json { namespace grammar {
namespace x3 = boost::spirit::x3; namespace x3 = boost::spirit::x3;
using unicode_string_grammar_type = x3::rule<class unicode_string_tag, std::string>; using unicode_string_grammar_type = x3::rule<class unicode_string_tag, std::string>;
using escaped_unicode_type = x3::rule<class escaped_unicode_tag, std::string>;
BOOST_SPIRIT_DECLARE(unicode_string_grammar_type); BOOST_SPIRIT_DECLARE(unicode_string_grammar_type);
BOOST_SPIRIT_DECLARE(escaped_unicode_type);
} }
grammar::unicode_string_grammar_type const& unicode_string_grammar(); grammar::unicode_string_grammar_type const& unicode_string_grammar();
grammar::escaped_unicode_type const& escaped_unicode_grammar();
}} }}

View file

@ -110,11 +110,11 @@ x3::uint_parser<std::uint16_t, 16, 4, 4> const hex4 {};
x3::uint_parser<uchar, 16, 8, 8> const hex8 {}; x3::uint_parser<uchar, 16, 8, 8> const hex8 {};
// start rule // start rule
unicode_string_grammar_type const unicode_string MAPNIK_INIT_PRIORITY(101) ("Unicode String"); unicode_string_grammar_type const unicode_string MAPNIK_INIT_PRIORITY(102) ("Unicode String");
// rules // rules
x3::rule<class double_quoted_tag, std::string> const double_quoted("Double-quoted string"); x3::rule<class double_quoted_tag, std::string> const double_quoted("Double-quoted string");
x3::rule<class escaped_tag, std::string> const escaped("Escaped Character"); x3::rule<class escaped_tag, std::string> const escaped("Escaped Character");
x3::rule<class escaped_unicode_tag, std::string> const escaped_unicode("Escaped Unicode code point(s)"); escaped_unicode_type const escaped_unicode MAPNIK_INIT_PRIORITY(101) ("Escaped Unicode code point(s)");
x3::rule<class utf16_string_tag, std::vector<std::uint16_t>> const utf16_string("UTF16 encoded string"); x3::rule<class utf16_string_tag, std::vector<std::uint16_t>> const utf16_string("UTF16 encoded string");
auto unicode_string_def = double_quoted auto unicode_string_def = double_quoted

View file

@ -22,9 +22,19 @@
#include <mapnik/expression_grammar_x3_def.hpp> #include <mapnik/expression_grammar_x3_def.hpp>
#include <mapnik/expression_grammar_x3_config.hpp> #include <mapnik/expression_grammar_x3_config.hpp>
#include <mapnik/json/unicode_string_grammar_x3_def.hpp>
namespace mapnik { namespace grammar { namespace mapnik { namespace json { namespace grammar {
BOOST_SPIRIT_INSTANTIATE(unicode_string_grammar_type, mapnik::grammar::iterator_type, mapnik::grammar::context_type);
}
BOOST_SPIRIT_INSTANTIATE(expression_grammar_type, iterator_type, context_type); grammar::escaped_unicode_type const& escaped_unicode_grammar()
{
return grammar::escaped_unicode;
}
}} }}
namespace mapnik { namespace grammar {
BOOST_SPIRIT_INSTANTIATE(expression_grammar_type, iterator_type, context_type);
}}