
Thorsten Ottosen wrote:
maybe
rule<> a, b; a = parser >> that >> refers >> to >> b; b = parser >> that >> refers >> to >> a; a = a.clone();
?
No. operator= should not do deep copy; otherwise, you cannot use rule<> objects in generic code like STL containers. I have a new idea. Deep copy can be triggered by assigning to a dummy member: rule<> a, b; a.rule = parser >> that >> refers >> to >> b; b.rule = parser >> that >> refers >> to >> a; This allows: a = b; // shallow copy, creates alias a.rule = b.rule; // deep copy, modifies 'a' and all its aliases xpressive now works this way. It's heavier syntactically, but far less confusing then using a special deep-assign operator.
| I don't know. Another question is: would spirit's users accept any | amount of syntactic/conceptual overhead to have a rule with standard | copy semantics and that was able to track its references and avoid | cyclic dependencies?
I'm not an expert spirit user, but the current semantics already carries some conceptual overhead with it. Anything that can reduce surprises would help. And I can replace this code
template< int > rule<>& some_rule(...) { static rule<> r = ...; return r; }
rule<> r1 = some_rule<1>(...) rule<> r2 = some_rule<2>(...)
with
rule<> some_rule(...) { return ...; }
rule<> r1 = some_rule(...) rule<> r2 = some_rule(...)
Yes, that is the idea. You would be able to return a rule by value, even if it refers to other local/temporary rules. -- Eric Niebler Boost Consulting www.boost-consulting.com