我正在尝试使用 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 % ".")
会消耗整个字符串。如何更改规则以在结构中正确解析?