我在对 boost::spirit 的深深钦佩和不理解它的永恒沮丧之间徘徊;)
我对过于贪婪的字符串有问题,因此它不匹配。下面是一个由于 txt 规则耗尽而无法解析的最小示例。
关于我想做的更多信息:目标是解析一些伪 SQL,我跳过空格。在类似的声明中
select foo.id, bar.id from foo, baz
我需要将from
其视为特殊关键字。规则类似于
"select" >> txt % ',' >> "from" >> txt % ','
但它显然不起作用,因为它被 bar.id from foo
视为一个项目。
#include <boost/spirit/include/qi.hpp>
#include <iostream>
namespace qi = boost::spirit::qi;
int main(int, char**) {
auto txt = +(qi::char_("a-zA-Z_"));
auto rule = qi::lit("Hello") >> txt % ',' >> "end";
std::string str = "HelloFoo,Moo,Bazend";
std::string::iterator begin = str.begin();
if (qi::parse(begin, str.end(), rule))
std::cout << "Match !" << std::endl;
else
std::cout << "No match :'(" << std::endl;
}