【发布时间】:2016-11-26 12:32:37
【问题描述】:
我正在尝试使用 boost spirit x3 将字符串解析为结构:
struct identifier {
std::vector<std::string> namespaces;
std::vector<std::string> classes;
std::string identifier;
};
现在我有一个解析器规则来匹配这样的字符串:
foo::bar::baz.bla.blub
foo.bar
boo::bar
foo
我的解析器规则如下所示。
auto const nested_identifier_def =
x3::lexeme[
-(id_string % "::")
>> -(id_string % ".")
>> id_string
];
其中id_string 解析alphanum 的组合。
我知道这条规则无法按照我的意愿进行解析,因为在解析 foo.bar 时,例如规则 -(id_string % ".") 的这一部分会消耗整个字符串。
如何更改规则以在结构中正确解析?
【问题讨论】:
标签: c++ parsing c++14 boost-spirit boost-spirit-x3