gdamore / tree-sitter-d

D Grammar for Tree Sitter
MIT License
41 stars 7 forks source link

Current tree-sitter-d status (with combined prev issues) #34

Closed al1-ce closed 3 months ago

al1-ce commented 5 months ago

Currently tree-sitter-d missing a lot of important things including some new features from 2.108.0 (which was already released) and breaks in many spots

How to reproduce: create test.d and paste in code block from below.

Comments signify what's wrong

void main() {
    // Highlight works only when it's first???
    const string varname;
    // Missing highlight for `string` keyword
    // Missing highlight for escaped characters
    // ALL_CAPS highlighted as type (better would be if it was Const or Special)
    const string HB_VIEW = "hb-view \"$FONT\"";
    // No support for Hex string literals
    immutable uint[] data = x"AABBCCDD";
    int a = 6;
    // No support for interpolated strings
    writeln(i"Content $(a + 4)");
    string a1 = i"Content $(a + 4)";
    string a2 = i`Content $(a + 4)`;
    string a3 = iq{Content $(a + 4)};
    // No support for token strings
    string a4 = q{this is the voice of};

    void func(T)(int a) {}

    // No highlight for template functions
    func!int(20);
    func!(int)(20);

    union U {
        float asFloat;
        uint asInt;
    }

    // Highlighted as function
    auto u0 = U(1.0);
    // Highlighted as type
    // asInt highlighted as type (should be variable)
    // u1 highlighted as type
    auto u1 = U(asInt : 0x3F800000);
    // And here for some reason it's broken
    auto u2 = U(asInt : 0x3F800000);

}

Image of highlight on neovim 0.10.0 image

Same image with incorrect highlight being highlighted image

Related:

gdamore commented 3 months ago

Yes, the grammar needs to be updated for 2.108. I haven't done that yet.

gdamore commented 3 months ago

Some of the things in D 2.108 are going to require a bit larger surgery on the grammar. Part of the reason I've also not done this is that (for other reasons) I'm stuck on D 2.101.

gdamore commented 3 months ago

A number of improvements have been made lately. I'm closing this ticket as there is nothing specifically actionable here.

gdamore commented 3 months ago

Btw, token strings are very roughly supported. It's impossible to support them well, because the grammar for them is ... well.. incredibly loose.

gdamore commented 3 months ago

A lot of your complaints here are a consequence of the limitations of D grammar.

As one example, when looking at struct or union initializers... it's quite impossible to determine that that's what they are not some form of other function call ... unless you have semantic analysis. (So that's far beyond what tree-sitter can do.)

Essentially, with much of D, there is so much ambiguity in the language that you cannot only really resolve many things by doing a full D front end (compiler). I've done what I can here, but it's far short of what you might like, but closing the gap simply isn't possible for D.

gdamore commented 3 months ago

If you would like to contribute however, contributions are welcome. Especially the queries can likely be improved for different editors.