Symons, Greg - SSD wrote:
Hi!
I'm trying to use xpressive with semantic actions that use a placeholder, but I can't quite see the right way to do it. Here's my code:
namespace grammar { using namespace boost::xpressive;
struct ParsedUri { std::string hostname; std::string modelPath; std::string diagramPath; };
static placeholder<ParsedUri> result; <snip>
static sregex pathHost = (host= hostname) >> pathSep >> path [ result.hostname = host ]; static sregex modelPath = pathNoHost | pathHost static sregex uri = "rosert://" >> (model= modelPath) >> '?' >> (diagram= path) [ result.modelPath = model, result.diagramPath = diagram ]; }
What happens is that when I compile the code, I get a compile error for the lines accessing the placeholder saying that the various members of the structure are not members of placeholder<T>, which looking at regex_actions.hpp seems to make sense to me.
Right.
But in the example using placeholder<T> in the docs, it looks like you can use it in the semantic action as if it were a T. Somewhere I'm misunderstanding something, and I don't know what. Can anyone help me here?
Xpressive overloads operators to give the impression that your can use a placeholder<T> as a T. But xpressive cannot overload operator. to give the impression of data member access because in C++ you can't overload operator.. Try this instead... xpressive::function<std::string ParsedUri::*>::type getHostname = {&ParsedUri::hostname}; Now in your semantic actions, instead of doing this: [ result.hostname = host ] You can do this: [ result->*getHostname() = host ] Xpressive overloads operator->*, which is the closest thing to operator.. Note to self: it would be better if we could leave off the parens in the above, like this: [ result->*getHostname = host ]. There's always more to do. HTH, -- Eric Niebler BoostPro Computing http://www.boostpro.com