The question is in bold at the bottom, the problem is also summarized by the distillation code fragment towards the end.
I am trying to unify my type system (the type sy
I'm not so sure I get the full extent of the question, but here are a few hints
The line commented with // THIS is what I need to do.
compiles fine with me (problem solved? I'm guessing you actually meant assigning a parser, not a rule?)
Initialization of function-local static
has been defined to be thread safe in the latest standard (C++11). Check your compiler support for C++0x threading. (If the initializer throws, a pass of the initialization statement will try to initialize again, by the way).
rules alias()
As described in http://boost-spirit.com/home/articles/doc-addendum/faq/#aliases
You can create 'logical copies' of rules without having to actually value-copy the proto expression. As the FAQ says, this is mainly to allow lazy-binding
The Nabialek Trick might be precisely what you need, basically it lazily selects a parser for subsequent parsing
one = id;
two = id >> ',' >> id;
keyword.add
("one", &one)
("two", &two)
;
start = *(keyword[_a = _1] >> lazy(*_a));
In your context, I could see keyword
defined as
qi::symbols*> keyword;
doing all the work with attributes from semantic actions. Alternatively,
qi::symbols() >*> keyword;
Bring the rules under the same type (like shown in the previous line, basically)
This is the part where I'm getting confused: You say you want to unify your type system. There might not be a need for strongtyped parsers (distinct attribute signatures).
typedef boost::variant unified_type;
typedef qi::rule unified_rule;
unified_rule rstring = +(qi::char_ - '.');
unified_rule rint = qi::int_;
unified_rule combine = rstring | rint;