[It seems my explanations and expectations are not clear at all, so I added precision on how I\'d like to use the feature at the end of the post]
I\'m currently work
Note I just extended my answer with a few more informational links. In this particular case I have a hunch that you could just get away with the Nabialek trick and replacing the inherited attribute with a corresponding qi::locals<>
instead. If I have enough time, I might work out a demonstration later.
Please be advised that there are issues when copying proto expression trees and spirit parser expressions in particular - it will create dangling references as the internals are not supposed to live past the end of the containing full expressions. See BOOST_SPIRIT_AUTO on Zero to 60 MPH in 2 seconds!
Also see these answers which also concerns themselves with building/composing rules on the fly (at runtime):
boost::proto::deepcopy
(like BOOST_SPIRIT_AUTO does, actually)In general, I'd very strongly advise against combining rules at runtime. Instead, if you're looking to 'add alternatives' to a rule at runtime, you can always use qi::symbols<>
instead. The trick is to store a rule in the symbol-table and use qi::lazy
to call the rule. In particular, this is known as the Nabialek Trick.
I have a toy command-line arguments parser here that demonstrates how you could use this idiom to match a runtime-defined set of command line arguments:
qi::lazy
, what's next?Unfortunately, qi::lazy
does not support inherited arguments see e.g.
You might be better off writing a custom parser component, as documented here:
I'll try to find some time to work out a sample that replaces inherited arguments by qi::locals later.