在简单的解析器测试中Live On Coliru,
std::string str("x123x");
boost::iterator_range<boost::range_iterator<decltype(str)>::type> attr;
if( x3::parse( boost::begin(str), boost::end(str), x3::lit('x') >> x3::raw[+x3::digit] >> x3::lit('x'), attr ) ) {
std::cout<<"Match! attr = "<<attr<<std::endl;
} else {
std::cout<<"Not match!"<<std::endl;
}
解析器
x3::lit('x') >> x3::raw[+x3::digit] >> x3::lit('x')
应该合成类型为boost::iterator_range<Iterator>
的属性。但它无法编译。如果我们删除两个x3::lit('x')
中的任何一个,它就会编译。相同的代码用qi编译Live on Coliru。
答案 0 :(得分:2)
有趣。实际上它确实编译:
<强> Live On Coliru 强>
#include <iostream>
#include <boost/spirit/home/x3.hpp>
namespace x3 = boost::spirit::x3;
int main() {
std::string const str("x123x");
boost::iterator_range<std::string::const_iterator> attr;
if(x3::parse(boost::begin(str), boost::end(str), x3::raw[+x3::digit], attr)) {
std::cout<<"Match! attr = "<<attr<<std::endl;
} else {
std::cout<<"Not match!"<<std::endl;
}
}
让它破裂的是周围环境:
// simple (ok):
x3::parse(boost::begin(str), boost::end(str), x3::raw[+x3::digit], attr);
// ok:
parse(boost::begin(str), boost::end(str), x3::eps >> x3::raw[+x3::digit], attr);
parse(boost::begin(str), boost::end(str), x3::raw[+x3::digit] >> x3::eps, attr);
// breaks:
parse(boost::begin(str), boost::end(str), x3::eps >> x3::raw[+x3::digit] >> x3::eps, attr);
在某种情况下,我的猜测是元编程在这种情况下错误地将iterator_range
视为Fusion序列。我当然认为这是一个错误。
你应该向上游报告。
可悲的是,我还没有找到顺势疗法&#34;解决方法。