Darkyenus / glsl4idea

A GLSL language plugin for IntelliJ IDEA
GNU Lesser General Public License v3.0
101 stars 31 forks source link

Support for simple #define #62

Closed Darkyenus closed 9 years ago

Darkyenus commented 9 years ago

Overview of functionality

This adds support and highlighting for #define (and #undef). It also makes all subclasses of GLSLElement much more robust and tolerant to malformed tree, which is easy to cause when creating more complex macros.

There is a special support when #define defines:

If it defines something else (anything), it will parse fine, tree should not get malformed, but GLSLElement-s won't be able to inspect themselves, because they will get mapped to unexpected token. That is why this PR makes them robust against that.

All* tokens which are redefined are highlighted as such and hovering over them will reveal what they are redefined as.

*There is a small bug, which is quite hard to hit and is not critical, that prevents highlighting of some tokens. See test file. Also, nested redefined tokens work, but are not highlighted yet.

Technical

It was needed to rewrite a good amount of GLSLParsing's utility methods and add a lot more code to them. So the GLSLParsing has been split to two: GLSLParsingBase which contains all utility methods, interfaces directly to PsiBuilder and deals with #define complexity, and GLSLParsing, which contains all grammar parsing code, as before. GLSLParsing extends GLSLParsingBase as only subclass. (No other class is intended to do that, ever).

Standard grammar-parsing methods no longer use PsiBuilder directly, all calls are routed through proxy methods, which handle tokens injected by redefined tokens automatically.

Redefining is only supported for IDENTIFIERs (= #define 1 2 is not supported).