|
Boost Users : |
Subject: [Boost-users] [proto] Handling String Terminals
From: David A. Greene (greened_at_[hidden])
Date: 2010-02-07 17:05:42
If I have a grammar like this:
typedef boost::proto::literal<std::string>::type StringTerminal;
typedef or_<
StringTerminal,
...
> Rule;
and I do this:
checkMatch<Rule>(boost::proto::lit(std::string("str")));
checkMatch<Rule>(std::string("str"));
checkMatch<Rule>("str");
where checkMatch is a wrapper around matches<>, the first
line is the only one that passes. This is presumably because
the string needs to be "protoized" and to match StringTerminal
it has to be cast to std::string explicitly.
This is rather ugly for constructs like this:
term["str"] => term[lit(string("str"))]
I would really rather not have to do the lit(string()) thing.
Is there a good strategy to avoid this clutter? I could predefine
literals like this:
StringTerminal strlit = {{"str"}}.
term[strlit]
but that's a bit burdensome on the user.
Would the same massaging be needed for, say,
term + "strlit"
Perhaps I can reformulate the grammar to avoid the cluttter by
using constructs that promote constants to proper proto terminals.
Any advice?
Thanks!
-Dave
Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net