mirror of
https://github.com/boostorg/parser.git
synced 2026-01-19 04:22:13 +00:00
Allow plain-style strings (7.3.3)
This commit is contained in:
@@ -31,7 +31,6 @@ namespace omd { namespace parser
|
||||
Iterator err_pos, boost::spirit::info const& what) const
|
||||
{
|
||||
int line = boost::spirit::get_line(err_pos);
|
||||
Iterator line_start = boost::spirit::get_line_start(first, err_pos);
|
||||
|
||||
if (source_file != "")
|
||||
std::cerr << "In file " << source_file << ", ";
|
||||
@@ -41,11 +40,12 @@ namespace omd { namespace parser
|
||||
if (line != -1)
|
||||
std::cerr << "line " << line << ':' << std::endl;
|
||||
|
||||
std::cerr << "Error! Expecting " << what;
|
||||
std::cerr << "Error! Expecting " << what << " here:" << std::endl;
|
||||
|
||||
std::cerr << " here:" << std::endl;
|
||||
int ci = 0;
|
||||
int col;
|
||||
Iterator line_start = boost::spirit::get_line_start(first, err_pos);
|
||||
|
||||
for (Iterator i = ++line_start; i != last; ++i, ++ci)
|
||||
{
|
||||
typename Iterator::value_type c = *i;
|
||||
@@ -58,9 +58,7 @@ namespace omd { namespace parser
|
||||
|
||||
std::cerr << std::endl;
|
||||
for (int i = 0; i != col; ++i)
|
||||
{
|
||||
std::cerr << '_';
|
||||
}
|
||||
|
||||
std::cerr << "^_" << std::endl;
|
||||
}
|
||||
|
||||
@@ -23,6 +23,12 @@ namespace omd { namespace parser
|
||||
|
||||
typedef boost::uint32_t uchar; // a unicode code point
|
||||
|
||||
// The indicators
|
||||
char const* indicators = "-?:,[]{}#&*!|>\\\"%@`";
|
||||
|
||||
// These are not allowed as first plain-style character
|
||||
char const* unsafe_first = ",[]{}#&*!|>\\\"%@`";
|
||||
|
||||
template <typename Iterator>
|
||||
struct unicode_string : qi::grammar<Iterator, std::string()>
|
||||
{
|
||||
@@ -30,6 +36,8 @@ namespace omd { namespace parser
|
||||
|
||||
qi::rule<Iterator, void(std::string&)> char_esc;
|
||||
qi::rule<Iterator, std::string()> char_lit;
|
||||
qi::rule<Iterator, std::string()> quoted;
|
||||
qi::rule<Iterator, std::string()> unquoted;
|
||||
qi::rule<Iterator, std::string()> start;
|
||||
};
|
||||
|
||||
|
||||
@@ -73,29 +73,38 @@ namespace omd { namespace parser
|
||||
function<detail::push_utf8> push_utf8;
|
||||
function<detail::push_esc> push_esc;
|
||||
|
||||
char_esc
|
||||
= '\\'
|
||||
char_esc =
|
||||
'\\'
|
||||
> ( ('u' > hex4) [push_utf8(_r1, _1)]
|
||||
| ('U' > hex8) [push_utf8(_r1, _1)]
|
||||
| char_("btnfr/\\\"'") [push_esc(_r1, _1)]
|
||||
)
|
||||
;
|
||||
|
||||
char_lit
|
||||
= '\''
|
||||
char_lit =
|
||||
'\''
|
||||
> (char_esc(_val) | (~char_('\'')) [_val += _1])
|
||||
> '\''
|
||||
;
|
||||
|
||||
start
|
||||
= '"'
|
||||
quoted =
|
||||
'"'
|
||||
> *(char_esc(_val) | (~char_('"')) [_val += _1])
|
||||
> '"'
|
||||
;
|
||||
|
||||
unquoted =
|
||||
~char_(unsafe_first)
|
||||
>> *(~char_(indicators))
|
||||
;
|
||||
|
||||
start = quoted | unquoted;
|
||||
|
||||
BOOST_SPIRIT_DEBUG_NODES(
|
||||
(char_esc)
|
||||
(char_lit)
|
||||
(quoted)
|
||||
(unquoted)
|
||||
(start)
|
||||
);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user