2011/4/6 Vincent Agnus <vincent.agnus@ircad.fr>
Hi,

 I have some trouble to retreive error parsing information using qi::on_error<fail> to work on a std::string.

The documentation propose the following code :

on_error<fail>
(
  start
  , std::cout
    << val("constituent: expected ")
    << _4                               // what failed?
    << val(" here: \"")
    << construct<std::string>(_3, _2)   // iterators to error-pos, end
    << val("\"")
    << std::endl
);


 * On my First attempt. I have define a class member (std::stringstream  m_error) in my grammar class  and replace std::cout by phx::ref(m_error). But this code generate a compilation error

Seems like a Phoenix bug to me. Here's a workaround:
    (ostream&)m_error << ...
 
* For the second attempt, I declare class member m_error as std::string and use this error handler:


namespace qi = boost::spirit::qi;
namespace phx = boost::phoenix;


on_error< qi::fail>
(
   start
   , phx::ref(m_error)
      = (    phx::construct<std::string>(phx::val("Error! Expecting "))
           // + qi::_4      REMARK1
           + phx::construct<std::string>( phx::val(" here: \"") )
           + phx::construct<std::string>(qi::_3, qi::_2)
           + phx::construct<std::string>( phx::val("\"") )
        )
      );

that's work perfectly. On error my string is correctly filled. But my problem is that I can't get the expected token (_4) (REMARK1), If I uncomment line REMARK1, I get a compilation error, same result using the code    phx::construct<std::string>(qi::_4).

How can a get qi::_4 as string ?

phx::bind(&boost::spirit::info::tag, qi::_4)
 
Can any one with kindness help me?

HTH