C++ Boost qi recursive rule construction

廉价感情. 提交于 2019-11-28 00:25:26
sehe

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.

Caveats, expositioning the problem

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):

Nabialek Trick

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:

Limitations of 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.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!