Boost logo

Boost Users :

Subject: Re: [Boost-users] [spirit][qi] on_error handler
From: Joel de Guzman (djowel_at_[hidden])
Date: 2012-12-21 20:03:14


On 12/22/12 8:44 AM, Diederick C. Niehorster wrote:
> Hi All,
>
> I have struggled through getting a parser set up with qi, but in the
> end it all worked out. Its really a nice library once you get the hang
> of it a bit!
> I have one leftover question. I now have an inline function with
> phoenix for the error handler as per the example, but as i'm using it
> multiple times, i would like to make its own function that i can
> reuse. I have tried a function object, wrapped in a phoenix function
> or not, but never got it to work (either got number of argument
> mismatches or errors that const-volatile qualifiers were being
> dropped).
>
> So basically, how would i rewrite the below into a free function (object/etc)?
>
> qi::on_error<qi::fail>
> (
> stimSpecVec // rule name
> , std::cout // the function
> << phoenix::val("Error! Expecting \"")
> << qi::_4 // what failed?
> << phoenix::val("\", but got: \"")
> << phoenix::construct<std::string>(qi::_3, qi::_2) // iterators
> to error-pos, end
> << phoenix::val("\"")
> << std::endl
> );

Taka a look at the compiler_tutorial examples. The error handlers use function
objects there. You will see lots of examples.

Regards,

-- 
Joel de Guzman
http://www.boostpro.com
http://boost-spirit.com

Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net