Is there any way to compose separately compiled boost::spirit::qi grammars?
Boost Spirit Qi parser grammars are wonderful, and I use them for small things all the time. However, there are times when I would like to be able to compose separate grammars.
This is easy to do all-in-one in a single compile by #including the appropriate grammars and stitching them together. However, this makes compile times start going through the roof. There are other drawbacks as well.
Is there any way to compose separately compiled grammars? In other words, I'd like to define a grammar's interface in a header file, implement the template and it's instantiation for a particular Iterator in a separate compilation unit, and then be able to use the grammar from another, without having the full template definition visible at compile time. In other words, I want to be able to use a grammar in a rule indirectly.
Is such a thing possible? If it is, how 开发者_运维百科would one go about it?
I don't think this is something specific to Spirit, but rather C++ 101. If you need to compose several grammars you need to include the corresponding header files defining the grammars you want to use while composing. What you might want to do is to separate the compilation of the grammar constructor into a separate compilation unit. See the Spirit calculator examples (mini_c and others) to see how this can be done. This will keep your compilation times at bay.
精彩评论