[language-c] Scope identifiers as types when they are unambiguously so

Anything that is one of the reserved type words in C must be a type in all contexts. And any identifier that ends in `_t` is, by strong convention, a type.
This commit is contained in:
Andrew Dupont 2023-08-21 00:46:29 -07:00
parent 9954068f8f
commit ebf5333022
2 changed files with 21 additions and 0 deletions

View File

@ -46,6 +46,16 @@
(primitive_type) @storage.type.builtin.c
(type_identifier) @storage.type.other.c
; These types are all reserved words; if we see an identifier with this name,
; it must be a type.
((identifier) @storage.type.builtin.c
(#match? @storage.type.builtin.c "^(char|int|float|double|long)$"))
; Assume any identifier that ends in `_t` is a type. This convention is not
; always followed, but it's a very strong indicator when it's present.
((identifier) @storage.type.other.c
(#match? @storage.type.other.c "_t$"))
[
"enum"
"long"

View File

@ -58,6 +58,17 @@
(type_identifier) @storage.type.other.cpp
; (struct_specifier) @storage.type.cpp
; These types are all reserved words; if we see an identifier with this name,
; it must be a type.
((identifier) @storage.type.builtin.cpp
(#match? @storage.type.builtin.cpp "^(char|int|float|double|long)$"))
; Assume any identifier that ends in `_t` is a type. This convention is not
; always followed, but it's a very strong indicator when it's present.
((identifier) @storage.type.other.cpp
(#match? @storage.type.other.cpp "_t$"))
[
"enum"
"long"