Hi dear IntelliJ IDEA specialists.
I’m developing a programming language support plugin for IntelliJ IDEA.
I want to add a support for programming languages A (already implemented) and A+ (want to add) where A+ is a superset of A.
(For detail here A = Posix AWK, A+ = Gawk.)
The most obvious approach I’m thinking of is just to extend the BNF grammar I already have for A (possibly lexer as well) to support A+. This should not break A since it’s a subset of A+.
However what I dislike is that when I only want to use A dialect for my program (for the most portability) - nothing will prevent me from accidental usage of some A+ features.
Now having this config option added I don’t quite get how can I enforce the A-only restriction for the developer. Should it be via hints/annotations? I.e. I will correctly parse A+ but will have a set of additional checks in place that will mark the unsupported features as errors in editor?
Initially I was thinking to have 2 separate BNF’s to keep the two explicitly distinct. But I realized that this will enormously increase the work efforts and cause code duplication.
Then I thought that maybe it is possible to come up with “conditional” BNF grammar, that depending on a flag will use some additional clauses/variants in grammar. Obviously this can allow most code reuse. I have a guess that this might work using higher-order external rules << ... >>. Do you think this is viable approach? Is there any recommended approach at building “conditional” grammar/parser? Is this even possible?
I admit though that this approach is somewhat limiting for developer, because it will strictly prevent parsing of A+ in A mode instead of, say, parse and highlight unsupported and ask to switch to A+.
I hope I described it clear enough. Would be glad to hear any recommendations and, even better, see some links to existing code solving similar problem.