I think I am having an issue understanding how my boost::spirit::qi
parser is supposed to be written. I simply want to pass matched substrings to functions via semantic actions. In an attempt to roughly emulate this boost tutorial, I have come up with the following code:
template<class Iterator>
struct _Calculator : public qi::grammar<Iterator> {
qi::rule<Iterator> number, result; //and a whole bunch of other ones too
qi::rule<Iterator,std::string()> variable;
Code& code;
Variables& variables;
_Calculator(Code& code_, Variables& variables_)
: _Calculator::base_type(result),
code(code_),
variables(variables_)
{
number =
lexeme[(qi::char_("1-9") >> +qi::char_("0-9"))[boost::phoenix::bind(&fPushIntCV, qi::_1, boost::ref(code), boost::ref(variables))]]
| lexeme[("0x" >> +qi::char_("0-9a-fA-F")) [boost::phoenix::bind(&fPushIntCV, qi::_1, boost::ref(code), boost::ref(variables))]]
| lexeme[("0b" >> +qi::char_("0-1")) [boost::phoenix::bind(&fPushIntCV, qi::_1, boost::ref(code), boost::ref(variables))]]
| lexeme[("0" >> +qi::char_("0-7")) [boost::phoenix::bind(&fPushIntCV, qi::_1, boost::ref(code), boost::ref(variables))]]
//some other junk
}
};
typedef _Calculator<std::string::const_iterator> Calculator;
When the declaration of fPushIntCV
looks like this:
void fPushIntCV (vector<char> my_str, Code& c, Variables& v);
I get this error:
function_ptr.hpp:89: error: conversion from 'char' to non-scalar type 'std::vector<char, std::allocator<char> >' requested
When I change the declaration of fPushIntCV
to look like this:
void fPushIntCV (char my_str, Code& c, Variables& v);
I get this error:
function_ptr.hpp:89: error: cannot convert 'std::vector<char, std::allocator<char> >' to 'char' in argument passing
I figured that the attribute of qi::_1
is changing, but I get unresolved references if I include both function prototypes and now pass boost::phoenix::bind
some ambiguous overloaded function pointer:
error: no matching function for call to 'bind(<unresolved overloaded function type>, const boost::spirit::_1_type&, ...
(my ...
for trailing unrelated garbage)
I know this is probably a really simple error and a really simple fix, but I'm having a helluva time understanding the spell to make the boost magic do its thing. What is the function prototype that this semantic action is expecting?