From a50efcb2bbef24c23cb489598d53187c7828fe63 Mon Sep 17 00:00:00 2001 From: artemp Date: Fri, 3 Mar 2017 15:41:46 +0100 Subject: [PATCH] refactor unicode string grammar - add `escaped_unicode` rule + use it in expressions. --- include/mapnik/expression_grammar_x3_def.hpp | 6 +++-- .../json/unicode_string_grammar_x3_def.hpp | 23 +++++++++++-------- 2 files changed, 17 insertions(+), 12 deletions(-) diff --git a/include/mapnik/expression_grammar_x3_def.hpp b/include/mapnik/expression_grammar_x3_def.hpp index f468b5904..a7efe6173 100644 --- a/include/mapnik/expression_grammar_x3_def.hpp +++ b/include/mapnik/expression_grammar_x3_def.hpp @@ -67,7 +67,7 @@ namespace mapnik { namespace grammar { x3::uint_parser const hex2 {}; namespace { - auto const& escaped = json::grammar::escaped; + auto const& escaped_unicode = json::grammar::escaped_unicode; } auto append = [](auto const& ctx) @@ -315,12 +315,14 @@ namespace mapnik { namespace grammar { auto const single_quoted_string = x3::rule {} = lit('\'') >> no_skip[*(unesc_char[append] | + //(lit('\\') > escaped_unicode[append]) // FIXME (!) + //| (~char_('\''))[append])] > lit('\''); auto const double_quoted_string = x3::rule {} = lit('"') >> no_skip[*(unesc_char[append] | - escaped[append] + (lit('\\') > escaped_unicode[append]) | (~char_('"'))[append])] > lit('"'); diff --git a/include/mapnik/json/unicode_string_grammar_x3_def.hpp b/include/mapnik/json/unicode_string_grammar_x3_def.hpp index 43d40c9aa..fd0bcebe1 100644 --- a/include/mapnik/json/unicode_string_grammar_x3_def.hpp +++ b/include/mapnik/json/unicode_string_grammar_x3_def.hpp @@ -112,26 +112,28 @@ x3::uint_parser const hex8 {}; unicode_string_grammar_type const unicode_string("Unicode String"); // rules x3::rule const double_quoted("Double-quoted string"); -x3::rule const escaped("Escaped Characted"); +x3::rule const escaped("Escaped Character"); +x3::rule const escaped_unicode("Escaped Unicode code point(s)"); x3::rule> const utf16_string("UTF16 encoded string"); auto unicode_string_def = double_quoted ; - -auto utf16_string_def = lit('u') > hex4 > *(lit("\\u") > hex4); - +auto utf16_string_def = lit('u') > hex4 > *(lit("\\u") > hex4) + ; +auto escaped_unicode_def = + (lit('x') > hex2[push_char]) + | + utf16_string[push_utf16] + | + (lit('U') > hex8[push_utf8]) + ; auto const escaped_def = lit('\\') > - ((lit('x') > hex2[push_char]) - | - utf16_string[push_utf16] - | - (lit('U') > hex8[push_utf8]) + (escaped_unicode[append] | char_("0abtnvfre\"/\\N_LP \t")[push_esc] | eol) // continue to next line ; - auto const double_quoted_def = lit('"') > no_skip[*(escaped[append] | (~char_('"'))[append])] > lit('"'); #pragma GCC diagnostic push @@ -141,6 +143,7 @@ BOOST_SPIRIT_DEFINE( unicode_string, double_quoted, escaped, + escaped_unicode, utf16_string );