mirror of
https://github.com/nvim-treesitter/nvim-treesitter.git
synced 2026-07-01 19:17:02 -04:00
fix(c)!: update C, CPP parsers and queries
also update derived parsers (arduino, cuda, glsl, hlsl, ispc, objc)
This commit is contained in:
parent
203981d288
commit
ad3805f5c3
7 changed files with 68 additions and 93 deletions
|
|
@ -6,7 +6,7 @@
|
||||||
"revision": "80ea622cf952a0059e168e5c92a798b2f1925652"
|
"revision": "80ea622cf952a0059e168e5c92a798b2f1925652"
|
||||||
},
|
},
|
||||||
"arduino": {
|
"arduino": {
|
||||||
"revision": "4de2f3e6235ee8659ecb7467c16ed13bde7fb272"
|
"revision": "3446bac828d5db2a6cf60ab31813c02ab53547a7"
|
||||||
},
|
},
|
||||||
"astro": {
|
"astro": {
|
||||||
"revision": "e122a8fcd07e808a7b873bfadc2667834067daf1"
|
"revision": "e122a8fcd07e808a7b873bfadc2667834067daf1"
|
||||||
|
|
@ -33,7 +33,7 @@
|
||||||
"revision": "7f1a5df44861291d6951b6b2146a9fef4c226e14"
|
"revision": "7f1a5df44861291d6951b6b2146a9fef4c226e14"
|
||||||
},
|
},
|
||||||
"c": {
|
"c": {
|
||||||
"revision": "6adee194587678b250608cdb808544f06bcd26e7"
|
"revision": "ad095896dd223f1c22b85ac5ec84ab11fb732b07"
|
||||||
},
|
},
|
||||||
"c_sharp": {
|
"c_sharp": {
|
||||||
"revision": "1648e21b4f087963abf0101ee5221bb413107b07"
|
"revision": "1648e21b4f087963abf0101ee5221bb413107b07"
|
||||||
|
|
@ -69,13 +69,13 @@
|
||||||
"revision": "f4b3cbc8b0bd4e13035d39940fef09f1392e8739"
|
"revision": "f4b3cbc8b0bd4e13035d39940fef09f1392e8739"
|
||||||
},
|
},
|
||||||
"cpp": {
|
"cpp": {
|
||||||
"revision": "0e7b7a02b6074859b51c1973eb6a8275b3315b1d"
|
"revision": "f88bf81238ec2842682e4d1dac0acf3b43b686e9"
|
||||||
},
|
},
|
||||||
"css": {
|
"css": {
|
||||||
"revision": "5f2c94b897601b4029fedcce7db4c6d76ce8a128"
|
"revision": "5f2c94b897601b4029fedcce7db4c6d76ce8a128"
|
||||||
},
|
},
|
||||||
"cuda": {
|
"cuda": {
|
||||||
"revision": "c5befe09c99f5e88190574676ffa8eb29775d410"
|
"revision": "2af3d43cd96dd3f3c3868095222c7f5e2462b3ab"
|
||||||
},
|
},
|
||||||
"cue": {
|
"cue": {
|
||||||
"revision": "0deecf48944aa54bb73e5383ba8acfbf9f2c44b4"
|
"revision": "0deecf48944aa54bb73e5383ba8acfbf9f2c44b4"
|
||||||
|
|
@ -174,7 +174,7 @@
|
||||||
"revision": "d3031a8294bf331600d5046b1d14e690a0d8ba0c"
|
"revision": "d3031a8294bf331600d5046b1d14e690a0d8ba0c"
|
||||||
},
|
},
|
||||||
"glsl": {
|
"glsl": {
|
||||||
"revision": "7d76863f2126ed3b246fead68f9591760d546c94"
|
"revision": "34e0657e37323874c6b67c718a0f83410c4602cf"
|
||||||
},
|
},
|
||||||
"go": {
|
"go": {
|
||||||
"revision": "8c8007eaee47702bb0291a3c7aeb004909baab4d"
|
"revision": "8c8007eaee47702bb0291a3c7aeb004909baab4d"
|
||||||
|
|
@ -219,7 +219,7 @@
|
||||||
"revision": "02fa3b79b3ff9a296066da6277adfc3f26cbc9e0"
|
"revision": "02fa3b79b3ff9a296066da6277adfc3f26cbc9e0"
|
||||||
},
|
},
|
||||||
"hlsl": {
|
"hlsl": {
|
||||||
"revision": "b8fab02e808bab41c49829fb5e4fb0ce7eab8d1a"
|
"revision": "20c40a3f1bb68c596f56bb0c0290008b9d4f58dd"
|
||||||
},
|
},
|
||||||
"hocon": {
|
"hocon": {
|
||||||
"revision": "c390f10519ae69fdb03b3e5764f5592fb6924bcc"
|
"revision": "c390f10519ae69fdb03b3e5764f5592fb6924bcc"
|
||||||
|
|
@ -243,7 +243,7 @@
|
||||||
"revision": "1a0ce072ebf3afac7d5603d9a95bb7c9a6709b44"
|
"revision": "1a0ce072ebf3afac7d5603d9a95bb7c9a6709b44"
|
||||||
},
|
},
|
||||||
"ispc": {
|
"ispc": {
|
||||||
"revision": "848e58874ffa2f7e540a6ec01ab9652b26995f37"
|
"revision": "0bdbb03d9abde78d8be2f2199e57119b2c7f8fd7"
|
||||||
},
|
},
|
||||||
"janet_simple": {
|
"janet_simple": {
|
||||||
"revision": "bd9cbaf1ea8b942dfd58e68df10c9a378ab3d2b6"
|
"revision": "bd9cbaf1ea8b942dfd58e68df10c9a378ab3d2b6"
|
||||||
|
|
@ -345,7 +345,7 @@
|
||||||
"revision": "1a305093569632de50f9a316ff843dcda25b4ef5"
|
"revision": "1a305093569632de50f9a316ff843dcda25b4ef5"
|
||||||
},
|
},
|
||||||
"objc": {
|
"objc": {
|
||||||
"revision": "6d876afade2d5e70d394aaf994321c78297e3607"
|
"revision": "77e28aeaede824a5f4aa501fb5f3138ab1019b9f"
|
||||||
},
|
},
|
||||||
"ocaml": {
|
"ocaml": {
|
||||||
"revision": "694c57718fd85d514f8b81176038e7a4cfabcaaf"
|
"revision": "694c57718fd85d514f8b81176038e7a4cfabcaaf"
|
||||||
|
|
|
||||||
|
|
@ -13,7 +13,8 @@
|
||||||
(preproc_else)
|
(preproc_else)
|
||||||
(preproc_ifdef)
|
(preproc_ifdef)
|
||||||
(initializer_list)
|
(initializer_list)
|
||||||
|
(gnu_asm_expression)
|
||||||
] @fold
|
] @fold
|
||||||
|
|
||||||
(compound_statement
|
(compound_statement
|
||||||
(compound_statement) @fold)
|
(compound_statement) @fold)
|
||||||
|
|
|
||||||
|
|
@ -8,9 +8,14 @@
|
||||||
"typedef"
|
"typedef"
|
||||||
"union"
|
"union"
|
||||||
"goto"
|
"goto"
|
||||||
|
"asm"
|
||||||
|
"__asm__"
|
||||||
] @keyword
|
] @keyword
|
||||||
|
|
||||||
"sizeof" @keyword.operator
|
[
|
||||||
|
"sizeof"
|
||||||
|
"offsetof"
|
||||||
|
] @keyword.operator
|
||||||
|
|
||||||
"return" @keyword.return
|
"return" @keyword.return
|
||||||
|
|
||||||
|
|
@ -36,6 +41,8 @@
|
||||||
"#else"
|
"#else"
|
||||||
"#elif"
|
"#elif"
|
||||||
"#endif"
|
"#endif"
|
||||||
|
"#elifdef"
|
||||||
|
"#elifndef"
|
||||||
(preproc_directive)
|
(preproc_directive)
|
||||||
] @preproc
|
] @preproc
|
||||||
|
|
||||||
|
|
@ -43,7 +50,7 @@
|
||||||
|
|
||||||
"#include" @include
|
"#include" @include
|
||||||
|
|
||||||
[ ";" ":" "," ] @punctuation.delimiter
|
[ ";" ":" "," "::" ] @punctuation.delimiter
|
||||||
|
|
||||||
"..." @punctuation.special
|
"..." @punctuation.special
|
||||||
|
|
||||||
|
|
@ -98,8 +105,8 @@
|
||||||
(comma_expression [ "," ] @operator)
|
(comma_expression [ "," ] @operator)
|
||||||
|
|
||||||
[
|
[
|
||||||
(true)
|
(true)
|
||||||
(false)
|
(false)
|
||||||
] @boolean
|
] @boolean
|
||||||
|
|
||||||
(conditional_expression [ "?" ":" ] @conditional.ternary)
|
(conditional_expression [ "?" ":" ] @conditional.ternary)
|
||||||
|
|
@ -133,7 +140,10 @@
|
||||||
|
|
||||||
(storage_class_specifier) @storageclass
|
(storage_class_specifier) @storageclass
|
||||||
|
|
||||||
(type_qualifier) @type.qualifier
|
[
|
||||||
|
(type_qualifier)
|
||||||
|
(gnu_asm_qualifier)
|
||||||
|
] @type.qualifier
|
||||||
|
|
||||||
(linkage_specification
|
(linkage_specification
|
||||||
"extern" @storageclass)
|
"extern" @storageclass)
|
||||||
|
|
@ -193,15 +203,15 @@
|
||||||
|
|
||||||
[
|
[
|
||||||
"__attribute__"
|
"__attribute__"
|
||||||
|
"__declspec"
|
||||||
|
"__based"
|
||||||
"__cdecl"
|
"__cdecl"
|
||||||
"__clrcall"
|
"__clrcall"
|
||||||
"__stdcall"
|
"__stdcall"
|
||||||
"__fastcall"
|
"__fastcall"
|
||||||
"__thiscall"
|
"__thiscall"
|
||||||
"__vectorcall"
|
"__vectorcall"
|
||||||
"_unaligned"
|
(ms_pointer_modifier)
|
||||||
"__unaligned"
|
|
||||||
"__declspec"
|
|
||||||
(attribute_declaration)
|
(attribute_declaration)
|
||||||
] @attribute
|
] @attribute
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -15,85 +15,46 @@
|
||||||
(_) @indent.begin
|
(_) @indent.begin
|
||||||
";" @indent.end)
|
";" @indent.end)
|
||||||
|
|
||||||
(
|
(ERROR
|
||||||
ERROR
|
"for" "(" @indent.begin ";" ";" ")" @indent.end)
|
||||||
"for" "(" @indent.begin ";" ";" ")" @indent.end)
|
|
||||||
(
|
|
||||||
(for_statement
|
|
||||||
body: (_) @_body
|
|
||||||
) @indent.begin
|
|
||||||
(#not-has-type? @_body compound_statement)
|
|
||||||
)
|
|
||||||
|
|
||||||
(
|
((for_statement
|
||||||
while_statement
|
body: (_) @_body) @indent.begin
|
||||||
condition: (_) @indent.begin
|
(#not-has-type? @_body compound_statement))
|
||||||
)
|
|
||||||
(
|
(while_statement
|
||||||
(while_statement
|
condition: (_) @indent.begin)
|
||||||
body: (_) @_body
|
|
||||||
) @indent.begin
|
((while_statement
|
||||||
(#not-has-type? @_body compound_statement)
|
body: (_) @_body) @indent.begin
|
||||||
)
|
(#not-has-type? @_body compound_statement))
|
||||||
|
|
||||||
(
|
(
|
||||||
(if_statement)
|
(if_statement)
|
||||||
(ERROR "else") @indent.begin
|
.
|
||||||
)
|
(ERROR "else" @indent.begin))
|
||||||
|
|
||||||
(
|
(if_statement
|
||||||
if_statement
|
condition: (_) @indent.begin)
|
||||||
condition: (_) @indent.begin
|
|
||||||
)
|
;; Supports if without braces (but not both if-else without braces)
|
||||||
;; Make sure all cases of if-else are tagged with @indent.begin
|
((if_statement
|
||||||
;; So we will offset the indents for the else case
|
consequence:
|
||||||
(
|
(_ ";" @indent.end) @_consequence
|
||||||
(if_statement
|
(#not-has-type? @_consequence compound_statement)
|
||||||
consequence: (compound_statement)
|
alternative:
|
||||||
"else" @indent.branch
|
(else_clause
|
||||||
alternative:
|
"else" @indent.branch
|
||||||
[
|
[
|
||||||
[ "{" "}" ] @indent.branch
|
(if_statement (compound_statement) @indent.dedent)? @indent.dedent
|
||||||
(compound_statement ["{" "}"] @indent.branch)
|
(compound_statement)? @indent.dedent
|
||||||
(_)
|
(_)? @indent.dedent
|
||||||
]
|
]
|
||||||
) @indent.begin
|
)?
|
||||||
)
|
) @indent.begin)
|
||||||
(
|
|
||||||
(if_statement
|
(else_clause (_ . "{" @indent.branch))
|
||||||
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)
|
|
||||||
)
|
|
||||||
|
|
||||||
;; 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)
|
(compound_statement "}" @indent.end)
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,3 +1,7 @@
|
||||||
(preproc_arg) @c
|
(preproc_arg) @c
|
||||||
|
|
||||||
(comment) @comment
|
(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))
|
||||||
|
|
|
||||||
|
|
@ -160,7 +160,7 @@
|
||||||
; Constants
|
; Constants
|
||||||
|
|
||||||
(this) @variable.builtin
|
(this) @variable.builtin
|
||||||
(nullptr) @constant.builtin
|
(null "nullptr" @constant.builtin)
|
||||||
|
|
||||||
(true) @boolean
|
(true) @boolean
|
||||||
(false) @boolean
|
(false) @boolean
|
||||||
|
|
|
||||||
|
|
@ -55,6 +55,5 @@ int baz(int x){
|
||||||
else
|
else
|
||||||
x++;
|
x++;
|
||||||
}
|
}
|
||||||
else
|
return 0;
|
||||||
return x;
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue