Is there a good way to make a grammar nonterminal which is parsed differently, depending on results of some boost phoenix function?
In my use-case, I have a grammar which among other things includes CPP-style #define directives, and #ifdef #else #endif directives. (It's not actually CPP-style its just some crude imitation made by someone else though.) When I parse it in qi, I pass my grammar (in its ctor) a reference to a "preprocessor database" object which is adapted to a fusion structure, and I have adapted phoenix functions which allow to add PP definitions / check for PP definitions. I have made it so that the #define directives have a semantic action which registers new definitions.
When I try to implement the #ifdef #else directives I'm not sure what I should do. The only way that I can think of to do this is to add a boolean flag to all of the attributes types of all of my grammar nonterminals that marks whether it is in a discarded #ifdef branch, and after my AST is parsed then crawl through that again and toss the marked guys. But that's pretty inelegant, there has to be a better way, right?
If possible I would like to be able to keep track of the original line numbers (before ifdefs are resolved).
I hope the question is clear, if it's not I can cook up a minimal example to show what I'm trying to do but my actual grammar is large.
Aucun commentaire:
Enregistrer un commentaire