I am using Boost Spirit parser, and as the parser is parsing, semantic actions are reflected to an instance of the class ParserActions.
Here is the code for the parser (the relevant part)
struct urdf_grammar : public grammar<urdf_grammar> {
template <typename ScannerT>
struct definition {
definition(urdf_grammar const& self) {
prog = (alpha_p >> *alnum_p)[&(self.actions.do_prog)];
}
rule<ScannerT> prog;
rule<ScannerT> const&
start() const {
return prog;
}
};
const ParserActions & actions;
explicit urdf_grammar(const ParserActions & actions = ParserActions()) : actions(actions) {
}
};
In order to call a member function of an object you need to provide two things:
&my_class::my_memberSpirit semantic actions expect you to provide a function or function object exposing a certain interface. In your case the expected interface is:
where Iterator is the iterator type used to call the parse function (accessible through
typename ScannerT::iterator_t). What you need to do is to create a function object exposing the mentioned interface while still calling your member function. While this can be done manually, doing so is tedious at best. The simplest way to create a function object is by using Boost.Bind:which will create the required function object for you, binding and wrapping your member function.
All this assumes your member function does not take any arguments. If you need to pass the pair of iterators the semantic action will be invoked with to your function the construct needs to be written as:
instructing the function object to forward its first and second parameter to the bound function.