[xpressive] Calling a function with captured text as a parameter from a rule action

Hi all,
I've been trying to wrap my head around xpressive. I've got a rule
that captures some text, calls a function as part of the action. The
function call works, but as soon as I try to pass my captured text as
a parameter to the function, I run into a rather long and
incomprehensible compilation error.
Are there working examples somewhere that do this? (There are
examples on calling functions and examples on using captured text in
the docs, but nothing that does both)
Here's the important bits of my code:
My function object:
struct append_element_impl
{
typedef void result_type;
void operator()(std::string& text) const
{
std::cout << "appending " << text;
}
};
function

Hi Ami, Some answers are inline below... You were very close. Ami Ganguli wrote:
Here's the important bits of my code:
My function object:
struct append_element_impl { typedef void result_type; void operator()(std::string& text) const -----------------------^^^^^^^^^^^^^^^^^
Make this std::string const &. Note the const.
{ std::cout << "appending " << text; } }; function
::type const append_element = {{}}; The part of the parser that calls the function:
h1 = "=" >> +blank >> * (s1= ~_ln) >> eol [append_element(asstd::string(s1))];
---------------------------^^^^^^^^^^^^^^^ asstd::string should not be necessary. <snip>
/usr/local/include/boost/proto/context/default.hpp:357: error: return-statement with a value, in function returning 'void'
This one is a little strange. I assume you're using gcc. It's possible that once the other errors are corrected, this one will go away. If not, change the return type of append_element_impl to int, and return just 0. Hope that helps, -- Eric Niebler BoostPro Computing http://www.boostpro.com

On Thu, Oct 1, 2009 at 6:26 PM, Eric Niebler
Some answers are inline below... You were very close.
Thanks! This did indeed work. My parser is working pretty well now. Cheers, Ami.
participants (2)
-
Ami Ganguli
-
Eric Niebler