Giter VIP home page Giter VIP logo

Comments (4)

Darkyenus avatar Darkyenus commented on September 15, 2024

I have started working on this, in branch define_macro. So far it correctly parses simple #define directives (not function-like yet). Problem is, that it is not trivial (or at least I don't see how) to substitute one IDENTIFIER with defined tokens, so all the GLSLElement type classes have problems with it.

What I'd like to do is to somehow expand GLSLRedefinedPsiElement (see that branch) to the #defined tokens inside GLSLElementImpl or somewhere around that. This would also be a good place to strip all preprocessor tokens that got mixed in during parsing.

This approach is not perfect though, it will most likely fail for something like:

#define FOO + 3.0 +

float bar = 5.0 FOO 1.0;

because it will be too late to do that substitution and retain precise token boundaries. (Above should get parsed correctly though. EDIT: Yes it does)

from glsl4idea.

AbigailBuccaneer avatar AbigailBuccaneer commented on September 15, 2024

I've been having a look (via PsiViewer) at how CLion handles this for C++. I think we can do better than we're doing with regards to the PSI tree we generate.

Considering the code:

#define BAR (true)
// ...
BAR ? 1 : 2;

CLion generates a tree that looks something like this:

OCMacroCall
 └─ OCMacroReferenceElement
     └─ PsiElement(IDENTIFIER)
OCExpressionStatement
 ├─ OCConditionalExpression
 ├─ OCParenthesizedExpression
 │   ├─ ForeignLeaf(OCPunctuator:(: ()
 │   ├─ OCLiteralExpression
 │   │   └─ ForeignLeaf(OCKeyword:true: true)
 │   └─ ForeignLeaf(OCPunctuator:): ))
 ├─ PsiElement(OCPunctuator:?)
 ├─ OCLiteralExpression
 │   └─ PsiElement(INTEGER_LITERAL)
 ├─ PsiElement(OCPunctuator::)
 ├─ OCLiteralExpression
 │   └─ PsiElement(INTEGER_LITERAL)
 └─ PsiElement(OCPunctuator:;)

So it generates an OCMacroCall element, and then continues parsing the substituted tokens, but generates a ForeignLeaf wrapper for each one. This way, the parse tree is exactly the same as it would be after substitution, other than the fact that it uses ForeignLeafPsiElement elements for the substituted tokens.

from glsl4idea.

Darkyenus avatar Darkyenus commented on September 15, 2024

There is a lot to be improved in the preprocessor macro handling, but I don't have time and experience with/knowledge about psi and how it is implemented in IntelliJ. Their approach is what I attempted to do first, but I didn't find out how to "inject" those foreign tokens into the parsing token stream conveniently, without rewriting substantial amounts of code. However if you or anybody else figures that out, PRs are welcome.

from glsl4idea.

AbigailBuccaneer avatar AbigailBuccaneer commented on September 15, 2024

I'll investigate.

from glsl4idea.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.