我的解析器快要工作了:)(仍然对Spirit功能集(和编译时)以及非常欢迎的社区(在堆栈溢出时感到惊讶))
在线尝试的小样本:http://coliru.stacked-crooked.com/a/1c1bf88909dce7e3
所以我已经学会使用更多的lexeme-rules并尝试防止no_skip-我的规则较小,因此更易于阅读,但现在我坚持使用结合lexeme-rules和skipping-rules似乎不可能(编译时错误,并带有警告,提示无法将其转换为Skipper)
我的问题是订阅中用逗号分隔的列表不会跳过表达式周围的空格
parses:
"a.b[a,b]"
失败:
"a.b[ a , b ]"
这些是我的规则:
qi::rule<std::string::const_iterator, std::string()> identifier_chain;
qi::rule<std::string::const_iterator, std::string()>
expression_list = identifier_chain >> *(qi::char_(',') >> identifier_chain);
qi::rule < std::string::const_iterator, std::string() >
subscription = qi::char_('[') >> expression_list >> qi::char_(']');
qi::rule<std::string::const_iterator, std::string()>
identifier = qi::ascii::alpha >> *(qi::ascii::alnum | '_');
identifier_chain = identifier >> *(('.' >> identifier) | subscription);
如您所见,所有规则都是“ lexeme”,我认为订阅规则应为ascii :: space_type跳过程序,但不能编译
我应该在expression_list的identifier_chains的前后添加空格符吗?
感觉就像写一个正则表达式:(
expression_list = *qi::blank >> identifier_chain >> *(*qi::blank >> qi::char_(',') >> *qi::blank >> identifier_chain >> *qi::blank);
它可以工作,但是我已经读到,这最终将使我进入更大的解析器(处理所有由我自己跳过的空间)
向任何建议致谢
btw:任何想法,如果用'.'
包围indentifier_chain中的qi::char_('.')
,我为什么不能编译>
identifier_chain = identifier >> *(('.' >> identifier) | subscription);
我的解析器几乎可以工作了:)(仍然对Spirit功能集(和编译时)以及非常欢迎的社区(在堆栈溢出时感到惊讶),在线尝试的小样本:http://coliru.stacked -...
我先前链接的答案描述了所有组合(如果我没记错的话:Boost spirit skipper issues
简而言之: