1
votes

I have part of a grammar as follows:

typedef SemanticActions< IterType > SemanticActionsType;

string_ %= lexeme[ +( spirit::qi::alnum | punct )];

component_ = lit( '-' ) >> string_[boost::bind( &SemanticActionsType::new_component_name, &actions_, _1, _2 )] 

And the corresponding semantic actions class:

template< typename IterType >
class SemanticActions
{
public:
    SemanticActions( Design_p d ) : design_( d )
    {
    }

    void print(int const& i) const
    {
        std::cout << i << std::endl;
    }

    void new_component_name ( std::string::iterator const b, std::string::iterator const e) const
    {
        cout << "new component name" << endl;
    }

I can get the "print" function to call from an int_ token, but I can't get new_component_name to get called from the string_ token.

I'm getting the following error: boost/include/boost/bind/bind.hpp:397:9: No matching function for call to object of type 'const boost::_mfi::cmf2 >, std::__1::__wrap_iter, std::__1::__wrap_iter >'

I've tried both the iterator pair parameters as well as "std::string & s const" parameter.

1

1 Answers

0
votes

You need to use phoenix bind (with the qi placeholders)

namespace phx = boost::phoenix;

component_ = (lit( '-' ) >> string_)
       [phx::bind( &SemanticActionsType::new_component_name, &actions_, qi::_1, qi::_2 )];

Note also the added parentheses (!), otherwise that SA would be attached to the string_ rule only.

In case you're not already using it, may I suggest using the recommended

#define BOOST_SPIRIT_USE_PHOENIX_V3

which solves many spotty problems with Spirit semantic actions (and is sometimes plain required to even compile the examples on recent compilers).