を使用して、他のパラメーターからパーサーを動的に構築しようとしていますboost::spirit:qi
。目標は、文字列を解析し、std::map<std::string, std::string>
キーと値を入力することです。ただし、マップのキー フィールドは解析されません (つまり、パーサーが生成される前に認識されます)。
マップのキーを適切な解析値に設定するセマンティック アクションを記述する必要があると思います。がパーサーのコンテンツを提供していることはわかりqi::_1
ますが、戻り構造 (この場合は a ) を参照するにはどうすればよいstd::map
でしょうか?
範囲内にある場合は、次のstd::map
ように直接割り当てることができます。
parser = lit(prefix) >> value_parser[map_[key] = _1];
しかし、私の場合、解析を行うのではなく、実際にパーサーを生成したいと考えています。交換するものが必要だと思いますmap_[key]
。
もう少しコンテキストを提供するには (要求に応じて):
最初に、次のような「テンプレート」文字列を解析します。
/path/to/:somewhere:/nifty.json
は:somewhere:
、後で name によって参照できる任意の文字列を表すことを意図していますsomewhere
。私はそのパーサーをうまく機能させています。
次に、そのテンプレートから、次のような文字列を解析する別のパーサーを生成します。
/path/to/anywhere/nifty.json
そして、私にstd::map<std::string, std::string> m
whereを提供してくださいm["somewhere"] == "anywhere"
。