我有一个巨大的语法用于xml解析,但是在pre 2.x boost精神中写了一段时间。我想要稍微有意义的错误消息,所以我想说:
#include <boost/spirit/core.hpp>
#include <boost/spirit/iterator/multi_pass.hpp>
const char* sourcefile;
typedef const char* base_iteratory_type
typedef boost::spirit::multi_pass<base_iterator_type> forward_iterator_type;
typedef boost::spirit::position_iterator2<forward_iterator_type> pos_iterator_t;
base_iterator_type begin(m_document.c_str());
base_iterator_type end = m_document.c_str() + m_document.size();
forward_iterator_type fwd_begin = boost::spirit::make_multi_pass(begin);
forward_iterator_type fwd_end;
pos_iterator_t pos_begin(fwd_begin, fwd_end, sourcefile);
pos_iterator_t pos_end;
try{
parse(pos_begin, pos_end, document_p);
}
catch(const boost::spirit::qi::expectation_failure<pos_iterator_t>& e)
{
//retrieve info from e.first.get_position of type file_position_base;
}
然而,这并没有在捕获异常的行上编译错误并抱怨expected unqualified-id before :: token
...我可以在2.x之前的精神中解决这个问题吗?所谓的“经典”界面?如果是这样,需要进行哪些修改?
答案 0 :(得分:1)
AFAICT expectal_failure类在经典精神中不存在:
您需要查看explcitily指定的parse_error
,例如来自boost 1.41的 error_handling.cpp sample 。
此外,如果有人想花更多时间在上面的例子上工作,这里有一个实际编译的修改版本(以破坏的异常处理为模):
#include <boost/spirit/include/classic_core.hpp>
#include <boost/spirit/include/classic_multi_pass.hpp>
#include <boost/spirit/include/classic_position_iterator.hpp>
typedef const char* base_iterator_type;
typedef boost::spirit::classic::multi_pass<base_iterator_type> forward_iterator_type;
typedef boost::spirit::classic::position_iterator2<forward_iterator_type> pos_iterator_t;
int main()
{
const char* sourcefile;
std::string m_document;
base_iterator_type begin(m_document.c_str());
base_iterator_type end = m_document.c_str() + m_document.size();
forward_iterator_type fwd_begin = boost::spirit::classic::make_multi_pass(begin);
forward_iterator_type fwd_end;
pos_iterator_t pos_begin(fwd_begin, fwd_end, sourcefile);
pos_iterator_t pos_end;
try{
parse(pos_begin, pos_end, boost::spirit::classic::real_p);
}
catch(...) {}
//catch(const boost::spirit::classic::expectation_failure<pos_iterator_t>& e)
//{
////retrieve info from e.first.get_position of type file_position_base;
//}
}