如果您不在开发分支上,则没有针对该单元素序列适应错误的修复程序,所以是的,可能就是这样。
由于属性转换/传播的通用性,有很大的回旋余地,但当然它只是记录在案并最终在代码中。换句话说:没有魔法。
qi::as<>
在 Qi 时代,我只需用or拼出所需的变换,就可以“解决”这个问题qi::attr_cast<>
。X3 (还没有),但您可以使用规则很容易地模仿它:
Live On Coliru
#include <iostream>
#include <boost/fusion/adapted/struct.hpp>
#include <boost/spirit/home/x3.hpp>
namespace x3 = boost::spirit::x3;
struct Name {
std::string value;
};
BOOST_FUSION_ADAPT_STRUCT(Name, value)
int main() {
std::string const input = "Halleo123_1";
Name out;
bool ok = x3::parse(input.begin(), input.end(),
x3::rule<struct _, std::string>{} =
x3::alpha >> *(x3::alnum | x3::char_('_')),
out);
if (ok)
std::cout << "Parsed: " << out.value << "\n";
else
std::cout << "Parse failed\n";
}
印刷:
Parsed: Halleo123_1
自动化
因为 X3 与 c++14 核心语言特性配合得非常好,所以减少输入并不难:
理解 Boost.Spirit 中的列表运算符 (%)