識別子を解析するためのパーサーと、foo, bar, baz
ネストされた識別子を解析するためのパーサーがあります。foo::bar, foo::bar.baz, foo::bar.baz.baham
これらは両方とも、次のように同じ ast 構造体に解析されます。
struct identifier : x3::position_tagged{
std::vector <std::string> namespaces;
std::vector <std::string> classes;
std::string identifier;
};
のパーサーはidentifier
次のようになります。
#define VEC_ATR x3::attr(std::vector<std::string>({})) //ugly hack
auto const identifier_def =
VEC_ATR
>> VEC_ATR
>> id_string;
そして、このnested_identifier
ようなもののために:
auto const nested_identifier_def =
x3::lexeme[
(+(id_string >> "::") >> +(id_string >> ".") > id_string)
| (+(id_string >> "::") >> VEC_ATR > id_string)
| (VEC_ATR >> +(id_string >> ".") > id_string)
| identifier
];
私はマクロの恥を知っています。識別子パーサーは正常に
動作しますが、パーサーから外れる ast オブジェクトのnested_identifier
ようなものを解析しようとすると、奇妙な動作が発生し、すべての名前空間 (この場合はベクター内に2 回) があります。ここに、この奇妙な動作の小さな例があり
ます。なぜこれが起こるのか、どうすればこれを回避できるのか、誰か説明してもらえますか?foo::bar::baz
foo
bar
namespaces