gdamore / tree-sitter-d

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

Parse c-style CONST_DEFINITIONS as const instead of type #31

Closed al1-ce closed 1 month ago

al1-ce commented 5 months ago

Describe the bug ALL_CAPS symbols are parsed as type. Might be because anything starting with capital letter is considered a type I.e:

SomeStruct
lowercasetype
CSTYLE_CONST

Are highlighted the same way image

Expected behavior CSTYLE_CONST would be considered a Const or Special

Additional context tree-sitter 0.22.2 neovim 0.9.5

gdamore commented 1 month ago

Capitalization is not special in D and the grammar does not consider things that are merely stylistic recommendations.

Lots of things in D are parsed as "types" that aren't really "types", because the grammar of the language makes it impossible to assess on a purely grammatical basis. I don't think there is a bug here, it's a fact of life with D.

A lot of power comes with D's grammatical flexibility. But that power comes at a steep price, and grammatical analysis is one of the prices -- the only way to really know what an object is often requires semantic analysis (meaning you have to actually compile it, not just look at a grammar tree.)

gdamore commented 1 month ago

I'm closing this as not a bug.

al1-ce commented 1 month ago

I'd argue a bit because of C bindings, in which this style is most commonly used and it's always either enum value (less frequently) or a constant value (usually #define).

So, it is indeed not a bug, but a feature request to aid with working with C bindings, which wouldn't really interfere with D because it's not a used style.

Anyway, it's your call if to do that, but it certainly would be nice thing to have