fix(c)!: update C, CPP parsers and queries

also update derived parsers (arduino, cuda, glsl, hlsl, ispc, objc)
This commit is contained in:
Amaan Qureshi 2023-07-27 03:51:13 -04:00 committed by GitHub
parent 203981d288
commit ad3805f5c3
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
7 changed files with 68 additions and 93 deletions

View file

@ -13,7 +13,8 @@
(preproc_else)
(preproc_ifdef)
(initializer_list)
(gnu_asm_expression)
] @fold
(compound_statement
(compound_statement
(compound_statement) @fold)

View file

@ -8,9 +8,14 @@
"typedef"
"union"
"goto"
"asm"
"__asm__"
] @keyword
"sizeof" @keyword.operator
[
"sizeof"
"offsetof"
] @keyword.operator
"return" @keyword.return
@ -36,6 +41,8 @@
"#else"
"#elif"
"#endif"
"#elifdef"
"#elifndef"
(preproc_directive)
] @preproc
@ -43,7 +50,7 @@
"#include" @include
[ ";" ":" "," ] @punctuation.delimiter
[ ";" ":" "," "::" ] @punctuation.delimiter
"..." @punctuation.special
@ -98,8 +105,8 @@
(comma_expression [ "," ] @operator)
[
(true)
(false)
(true)
(false)
] @boolean
(conditional_expression [ "?" ":" ] @conditional.ternary)
@ -133,7 +140,10 @@
(storage_class_specifier) @storageclass
(type_qualifier) @type.qualifier
[
(type_qualifier)
(gnu_asm_qualifier)
] @type.qualifier
(linkage_specification
"extern" @storageclass)
@ -193,15 +203,15 @@
[
"__attribute__"
"__declspec"
"__based"
"__cdecl"
"__clrcall"
"__stdcall"
"__fastcall"
"__thiscall"
"__vectorcall"
"_unaligned"
"__unaligned"
"__declspec"
(ms_pointer_modifier)
(attribute_declaration)
] @attribute

View file

@ -15,85 +15,46 @@
(_) @indent.begin
";" @indent.end)
(
ERROR
"for" "(" @indent.begin ";" ";" ")" @indent.end)
(
(for_statement
body: (_) @_body
) @indent.begin
(#not-has-type? @_body compound_statement)
)
(ERROR
"for" "(" @indent.begin ";" ";" ")" @indent.end)
(
while_statement
condition: (_) @indent.begin
)
(
(while_statement
body: (_) @_body
) @indent.begin
(#not-has-type? @_body compound_statement)
)
((for_statement
body: (_) @_body) @indent.begin
(#not-has-type? @_body compound_statement))
(while_statement
condition: (_) @indent.begin)
((while_statement
body: (_) @_body) @indent.begin
(#not-has-type? @_body compound_statement))
(
(if_statement)
(ERROR "else") @indent.begin
)
.
(ERROR "else" @indent.begin))
(
if_statement
condition: (_) @indent.begin
)
;; Make sure all cases of if-else are tagged with @indent.begin
;; So we will offset the indents for the else case
(
(if_statement
consequence: (compound_statement)
"else" @indent.branch
alternative:
[
[ "{" "}" ] @indent.branch
(compound_statement ["{" "}"] @indent.branch)
(_)
]
) @indent.begin
)
(
(if_statement
consequence: (_ ";" @indent.end) @_consequence
) @indent.begin
(#not-has-type? @_consequence compound_statement)
)
(
(if_statement
consequence: (_) @_consequence
"else" @indent.branch
alternative:
[
[ "{" "}" ] @indent.branch
(compound_statement ["{" "}"] @indent.branch)
(_)
]
)
(#not-has-type? @_consequence compound_statement)
)
(if_statement
condition: (_) @indent.begin)
;; Supports if without braces (but not both if-else without braces)
((if_statement
consequence:
(_ ";" @indent.end) @_consequence
(#not-has-type? @_consequence compound_statement)
alternative:
(else_clause
"else" @indent.branch
[
(if_statement (compound_statement) @indent.dedent)? @indent.dedent
(compound_statement)? @indent.dedent
(_)? @indent.dedent
]
)?
) @indent.begin)
(else_clause (_ . "{" @indent.branch))
;; Dedent for chaining if-else statements
;; this will go recursively through each if-elseif
;; if-elseif -> second `if` is dedented once, indented twice
;; if-elseif-elseif -> third `if` is dedented twice, indented 3 times
;; -> all are indented once
(
(if_statement
consequence: (_)
alternative:
[
(if_statement consequence: (compound_statement) @indent.dedent)
(_)
] @indent.dedent
)
)
(compound_statement "}" @indent.end)

View file

@ -1,3 +1,7 @@
(preproc_arg) @c
(comment) @comment
; TODO: add when asm is added
; (gnu_asm_expression assembly_code: (string_literal) @asm)
; (gnu_asm_expression assembly_code: (concatenated_string (string_literal) @asm))

View file

@ -160,7 +160,7 @@
; Constants
(this) @variable.builtin
(nullptr) @constant.builtin
(null "nullptr" @constant.builtin)
(true) @boolean
(false) @boolean