refactor unicode string grammar - add escaped_unicode rule + use it in expressions.

This commit is contained in:
artemp 2017-03-03 15:41:46 +01:00
parent fb7139bc63
commit a50efcb2bb
2 changed files with 17 additions and 12 deletions

View file

@ -67,7 +67,7 @@ namespace mapnik { namespace grammar {
x3::uint_parser<char, 16, 2, 2> 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<class single_quoted_string, std::string> {} = lit('\'')
>> no_skip[*(unesc_char[append]
|
//(lit('\\') > escaped_unicode[append]) // FIXME (!)
//|
(~char_('\''))[append])] > lit('\'');
auto const double_quoted_string = x3::rule<class double_quoted_string, std::string> {} = lit('"')
>> no_skip[*(unesc_char[append]
|
escaped[append]
(lit('\\') > escaped_unicode[append])
|
(~char_('"'))[append])] > lit('"');

View file

@ -112,26 +112,28 @@ x3::uint_parser<uchar, 16, 8, 8> const hex8 {};
unicode_string_grammar_type const unicode_string("Unicode String");
// rules
x3::rule<class double_quoted_tag, std::string> const double_quoted("Double-quoted string");
x3::rule<class escaped_tag, std::string> const escaped("Escaped Characted");
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)");
x3::rule<class utf16_string_tag, std::vector<std::uint16_t>> 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
);