tree-sitter / tree-sitter-c

C grammar for tree-sitter
MIT License
237 stars 106 forks source link

C23 constexpr types are not highlighted correctly #143

Closed Soupertonic closed 1 year ago

Soupertonic commented 1 year ago

C23 (N3006 + N3018) introduced the constexpr to the gang. While it is identified/highlighted as a keyword, the types following it are not.

I swapped multiple themes to see if this just an issue with missing scopes in the theme file, but the incorrect highlighting applies to every theme.

Expected:

image

Status quo:

Screenshot 2023-07-03 at 10 46 55

It seems to me Tree Sitter treats the constexpr statement as a type identifier and the actual type identifier as a regular identifier. Here's the Tree Sitter Playground output:

translation_unit [0, 0] - [3, 0]
  declaration [0, 0] - [0, 43]
    type: type_identifier [0, 0] - [0, 9]
    ERROR [0, 10] - [0, 13]
      identifier [0, 10] - [0, 13]
    declarator: init_declarator [0, 14] - [0, 42]
      declarator: identifier [0, 14] - [0, 37]
      value: number_literal [0, 40] - [0, 42]
  declaration [1, 0] - [1, 40]
    type: type_identifier [1, 0] - [1, 9]
    ERROR [1, 10] - [1, 13]
      identifier [1, 10] - [1, 13]
    declarator: init_declarator [1, 14] - [1, 39]
      declarator: identifier [1, 14] - [1, 34]
      value: number_literal [1, 37] - [1, 39]
  declaration [2, 0] - [2, 45]
    type: type_identifier [2, 0] - [2, 9]
    ERROR [2, 10] - [2, 13]
      identifier [2, 10] - [2, 13]
    declarator: init_declarator [2, 14] - [2, 44]
      declarator: identifier [2, 14] - [2, 39]
      value: number_literal [2, 42] - [2, 44]

Editor: Helix Tree Sitter Rev: 84bdf409067676dd5c003b2a7cb7760456e731bf

amaanq commented 1 year ago

C23 is still a draft right? best to wait for it to be released

Soupertonic commented 1 year ago

It seems to be finalized.

C23 now finalized!

amaanq commented 1 year ago

C23 itself will therefore differ in a number of subtle but important ways from n3096, most importantly in the fact that UB no longer time-travels (!!!).

we also standardized $identifiers at the very last second because YOLO :P

Mmm, still leaning towards waiting until the C2y draft at least since there's potentially some unknown changes, unless something indicates that nothing will change from C3096

Soupertonic commented 1 year ago

So as a quick fix and for the time being, because I cannot stand inconsistency in highlighting, I forked the repository and added constexpr to the type qualifiers. Works like a charm.

amaanq commented 1 year ago

that's totally fine - it'll be added here sooner or later 😁