[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<append_element_impl>::type const append_element = {{}}; The part of the parser that calls the function: h1 = "=" >> +blank >> * (s1= ~_ln) >> eol [append_element(as<std::string>(s1))]; I've tried various variations on this (the "as<std::string>" is a recent addition, and doesn't seem to make much difference). If I get rid of the s1 parameter in both the function and the call, then everything works as expected. The last part of the error message (the part that I sort of understand) is: /usr/local/include/boost/proto/context/default.hpp:357: error: no match for call to ‘(const append_element_impl(std::basic_string<char, std::char_traits<char>, std::allocator<char> >)’ /home/ganguli/acms/plug-ins/wikitext/wikitext.C:27: note: candidates are: void append_element_impl::operator((std::string&) const /usr/local/include/boost/proto/context/default.hpp:357: error: return-statement with a value, in function returning 'void' I'd really appreciate any pointers on this, or just some examples on how to do something similar. Cheers, Ami.

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<append_element_impl>::type const append_element = {{}};
The part of the parser that calls the function:
h1 = "=" >> +blank >> * (s1= ~_ln) >> eol [append_element(as<std::string>(s1))];
---------------------------^^^^^^^^^^^^^^^ as<std::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 <eric@boostpro.com> wrote:
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