I have a huge grammar for xml parsing but written a while back in pre 2.x boost spirit. I would like slightly more meaningful error messages and so I though of saying:
#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;
}
This, however, is not compiling with error on the line which catches the exception and complaining expected unqualified-id before :: token… Can i pull this off in pre 2.x spirit? the so-called “classic” interface? If so, what modifications would this need?
AFAICT the expectation_failure class didn’t exist in classic Spirit:
You will want to look at explcitily specified
parse_error, like in the error_handling.cpp sample from boost 1.41.Also, in case anyone wants to spend some more time working on the above example, here’s a modified version that actually compiles (modulo the broken exception handling):