
On 09/21/2010 11:55 AM, Thomas Heller wrote:
<snip> Solved the mistery. here is the code, explanation comes afterward:
<snip> So, everything works as expected!
Thomas, wow, this was driving me crazy, thanks for solving and explaining in all the detail! :-) I am still not sure if this isn't a conceptual problem, though: The "equation" grammar is perfectly OK. But without or-ing it with the "addition" grammar, the extension does not allow ANY valid expression to be created. I wonder if that is a bug or a feature? Thanks and regards, Roland
#include
using namespace boost;
typedef proto::terminal<int>::type terminal;
struct addition: proto::or_ < proto::plus
, proto::terminalproto::_ > {}; struct equation: proto::or_ < proto::equal_to
> {}; template<class Expr> struct extension;
struct my_domain: proto::domain < proto::pod_generator< extension>, // we need both grammars in our domain grammar proto::or_
, proto::default_domain > {}; template<class Expr> struct extension { BOOST_PROTO_EXTENDS( Expr , extension<Expr> , my_domain ) };
template
void matches(Expr const&) { std::cout<< std::boolalpha << proto::matches ::value<< "\n"; } int main() { extension<terminal> i; extension<terminal> j;
matches<equation>(i); // 1) false matches<equation>(i == j); // 2) true matches<equation>(i == i + i); // 3) true matches<equation>(i + i == i); // 4) true matches<equation>(i + i == i + i); // 5) true matches<equation>(i + i); // 6) false }