当我尝试使用迭代器形式解析 Spirit 语法时,我得到一个参数传递从迭代器类型到 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;
}
关于c++ - 使用 Iterator 解析 Boost::Spirit Grammars,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/529706/