【发布时间】:2017-10-31 15:55:58
【问题描述】:
我正在尝试解析以下字符串并提取括号内的部分。
此字符串失败:
_找东西', '')_ 应该返回 part1 = '某事' 第 2 部分 = ''这个字符串通过了:
_找东西', '*')_ 退货 part1 = '某事' 第 2 部分 = '*'我认为问题在于“quoted_string”
find_parser() : find_parser::base_type(start)
{
using qi::lit;
using qi::lexeme;
using standard_wide::char_;
/// simple quoted string.
quoted_string %= lexeme['\'' >> +(char_ - '\'') >> '\''];
start %=
-(lit("$(")) // optional
>> lit("_FIND")
>> '('
>> quoted_string
>> -(',' >> quoted_string) // 2nd parameter optional
>> ")_"
>> -(lit(")")) // optional
;
}
我尝试像这样添加一个“空”字符串词素,但它不起作用。
quoted_string %= lexeme['\'' >> +(char_ - '\'') >> '\''];
empty_quoted_string %= lexeme['\'' >> +(qi::space - '\'') >> '\''];
start %=
lit("_FIND")
>> '('
>> (quoted_string|empty_quoted_string)
>> -(',' >> (quoted_string|empty_quoted_string)) // 2nd parameter optional
>> ")_"
;
我知道这一定是一件简单的事情,但我不能指手画脚。
感谢您的任何意见、提示或提示。
【问题讨论】:
标签: c++11 boost-spirit