Merge pull request #3390 from mapnik/bare-strings

Bare strings
This commit is contained in:
Artem Pavlenko 2016-04-01 18:33:44 +02:00
commit 8d9dc27355
3 changed files with 12 additions and 1 deletions

View file

@ -87,6 +87,7 @@ struct expression_grammar : qi::grammar<Iterator, expr_node(), space_type>
qi::rule<Iterator, std::string() , space_type> attr;
qi::rule<Iterator, std::string() , space_type> global_attr;
qi::rule<Iterator, std::string(), qi::locals<char> > quoted_ustring;
qi::rule<Iterator, std::string()> unquoted_ustring;
qi::rule<Iterator, std::string(), space_type> ustring;
qi::symbols<char const, char const> unesc_char;

View file

@ -168,7 +168,7 @@ expression_grammar<Iterator>::expression_grammar(std::string const& encoding)
;
expr = logical_expr [_val = _1]
| ustring [_val = unicode(_1)]
//| ustring [_val = unicode(_1)]
;
logical_expr = not_expr [_val = _1]
@ -255,6 +255,9 @@ expression_grammar<Iterator>::expression_grammar(std::string const& encoding)
| unary_function_expr [_val = _1]
| binary_function_expr [_val = _1]
| '(' > logical_expr [_val = _1 ] > ')'
// TODO: this is a backward compatibility hack to allow unquoted strings
| unquoted_ustring [_val = unicode(_1)]
// ^ https://github.com/mapnik/mapnik/pull/3389
;
unesc_char.add("\\a", '\a')("\\b", '\b')("\\f", '\f')("\\n", '\n')
@ -267,6 +270,7 @@ expression_grammar<Iterator>::expression_grammar(std::string const& encoding)
quoted_ustring %= omit[quote_char[_a = _1]]
>> *(unesc_char | "\\x" >> hex | (char_ - lit(_a)))
>> lit(_a);
unquoted_ustring %= no_skip[alpha >> *alnum] - lit("not");
attr %= '[' >> no_skip[+~char_(']')] >> ']';
global_attr %= '@' >> no_skip[alpha >> * (alnum | char_('-'))];

View file

@ -182,4 +182,10 @@ TEST_CASE("expressions")
// 'Québec' =~ m:^Q\S*$:
TRY_CHECK(eval(" [name].match('^Q\\S*$') ") == true);
TRY_CHECK(parse_and_dump(" [name].match('^Q\\S*$') ") == "[name].match('^Q\\S*$')");
// string & value concatenation
// this should evaluate as two strings concatenating, but currently fails
TRY_CHECK(eval("Hello + '!'") == eval("'Hello!'"));
// this should evaulate as a combination of an int value and string, but fails
TRY_CHECK(eval("[int]+m") == eval("'123m'"));
}