ブーストで解析するIteratorを使用して::スピリット文法は、
-
22-08-2019 - |
質問
私は精神文法のための解析のイテレータフォームを使用しようとすると、
私は*のconst char型へのイテレータ型から変換エラーを渡す引数を取得します。私はこの問題を解決する方法を教えてください。
いくつかの制限があります。私は、大きな入力にイテレータアダプタを使用していますので、私はCスタイルの文字列に変換することは現実的ではありません。
ここでの問題を示すサンプルコードです:
#include <boost/spirit/core.hpp>
#include <boost/spirit/iterator/file_iterator.hpp>
#include <vector>
#include <string>
using std;
using boost::spirit;
struct ex : public grammar<route_grammar> {
template <typename ScannerT> struct defintion {
definition(ex const& self) {
expression = real_p;
}
rule<ScannerT> expression;
rule<ScannerT> const& start() const { return expression; }
};
int main() {
file_iterator<char> first;
file_iterator<char> last = first.make_end();
ex ex_p;
parse_info<file_iterator<char> > info = parse(first, last, ex_p, space_p);
return 0;
}
エラー:このコードでは、と壊れconst boost::spirit::file_iterator<char_t, boost::spirit::fileiter_impl::mmap_file_iterator<char_t> >
を変換することはできません渡す引数にconst char*
する
解決
掲載され、それはいくつかの基本的なエラーが含まれているので、
ハードは、コードから指示します。 これらの補正した後、それは(MSVC ++ 7.1で)私のマシン上の罰金コンパイルします:
#include <boost/spirit/core.hpp>
#include <vector>
#include <string>
using namespace std;
using namespace boost::spirit;
struct ex : public grammar<ex> {
template <typename ScannerT>
struct definition {
definition(ex const& self)
{
expression = real_p;
}
rule<ScannerT> expression;
rule<ScannerT> const& start() const { return expression; }
};
};
int main() {
vector<char> v;
v.push_back('3'); v.push_back('.'); v.push_back('2');
ex ex_p;
parse_info<vector<char>::iterator> info = parse(v.begin(), v.end(), ex_p, space_p);
return 0;
}
他のヒント
ここ* 'sがイテレータと同じ要素を指し炭を得るための一つの方法であります
&v.front() // v.begin()
&v.back() + 1 // v.end()
私はあなたがこれはしかし、コンパイルするようになったかどうかはわかりません。
vector<char> v;
v.push_back("3.2");
コンパイルエラーが提供されているサンプルではありませんでした。コードで、私は私がした簡素化している間に上記の文法では、私は、何の意味的なアクションを持っていません。
私が使っていた*代わりにイテレータ型の文字を使用し、それらのアクションのためのコールバックます。
あなたはセマンティックアクションは、引数の型に多形だったことを確認して試すことができます。正確にコードで、あなたがこのような何かをしたいと思います:
struct my_action {
template <class ParamType>
void operator()(ParamType const & parameter) const {
// deal with parameter
}
};
以下に示すように、あなたはこのような単項セマンティックアクションを使用すると思います:
real_p[my_action()]
それとも、バイナリセマンティックアクションを必要に応じて、あなたのような何かをしたい:
struct binary_action {
template <class ParamType>
void operator()(ParamType const & param1, ParamType const & param2) const {
// deal with either parameter
}
};
(*char_p)[binary_action()]
所属していません StackOverflow