$include_dir="/home/hyper-archives/boost-users/include"; include("$include_dir/msg-header.inc") ?>
Subject: [Boost-users] [Spirit 2] on_error to string
From: Vincent Agnus (vincent.agnus_at_[hidden])
Date: 2011-04-06 09:27:39
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
* 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 ?
Can any one with kindness help me?