Robert Ramey wrote:

I have the following simple program which I can't get to compile.  Its based
on the spirit docs and bind example.  It differs from the bind example in
that the semantic action follows the standard prototype and takes two
arguments.

Basically I'm having trouble with the bind

I know its been discussed on the list but I never saw fix for it when I was
raised.  Also the fact that the example doesn't use the standard semantic
action prototype is sort of suspicious.

Could anyone help me with this?

[...]

Hi Robert,

Try this:

#include <boost/bind.hpp>

#define BOOST_SPIRIT_SINGLE_GRAMMAR_INSTANCE
#include <boost/spirit/core.hpp>

using namespace boost::spirit;

class psort_parser :
    public boost::spirit::grammar<psort_parser>
{
    typedef boost::spirit::chlit<char> chlit_t;
    typedef boost::spirit::scanner<const char *> scanner_t;
        typedef boost::spirit::rule<> rule_t;
    int m_start_pos;
    int m_end_pos;

    void append_prange(char const* first, char const* last);
public:
        rule_t prange;

    psort_parser();
};

psort_parser::psort_parser(){
    // character position
    prange = (uint_p >> eps_p)
        [ boost::bind(&psort_parser::append_prange, this, _1, _2)]
    ;
}

1) Since you want the standard interface f(first, last), you have
to append eps_p to make it do so. Otherwise, the expected interface
is f(int).

2) Since it expects 2 arguments now (plus the implicit "this"), you'll
have to tell it so:

   [ boost::bind(&psort_parser::append_prange, this, _1, _2)]

<< note: this, _1, _2 >>

HTH,
--
Joel de Guzman
http://www.boost-consulting.com
http://spirit.sf.net


------------------------------------------------------- This SF.Net email is sponsored by BEA Weblogic Workshop FREE Java Enterprise J2EE developer tools! Get your free copy of BEA WebLogic Workshop 8.1 today. http://ads.osdn.com/?ad_id=5047&alloc_id=10808&op=click _______________________________________________ Boost-docs mailing list [EMAIL PROTECTED] Unsubscribe and other administrative requests: https://lists.sourceforge.net/lists/listinfo/boost-docs

Reply via email to