mirror of
https://github.com/nvim-treesitter/nvim-treesitter.git
synced 2026-07-01 19:17:02 -04:00
queries: add C queries
Also add a missing `field` capture in locals query.
This commit is contained in:
parent
7fab1a8b12
commit
92aafcf51c
3 changed files with 114 additions and 0 deletions
|
|
@ -92,6 +92,7 @@ are optional and will not have any effect for now.
|
|||
`var`
|
||||
`macro`
|
||||
`type`
|
||||
`field`
|
||||
|
||||
`@scope`
|
||||
|
||||
|
|
|
|||
77
queries/c/highlights.scm
Normal file
77
queries/c/highlights.scm
Normal file
|
|
@ -0,0 +1,77 @@
|
|||
"break" @keyword
|
||||
"case" @conditional
|
||||
"const" @keyword
|
||||
"continue" @repeat
|
||||
"default" @keyword
|
||||
"do" @repeat
|
||||
"else" @conditional
|
||||
"enum" @keyword
|
||||
"extern" @keyword
|
||||
"for" @repeat
|
||||
"if" @conditional
|
||||
"inline" @keyword
|
||||
"return" @keyword
|
||||
"sizeof" @keyword
|
||||
"static" @keyword
|
||||
"struct" @keyword
|
||||
"switch" @keyword
|
||||
"typedef" @keyword
|
||||
"union" @keyword
|
||||
"volatile" @keyword
|
||||
"while" @repeat
|
||||
|
||||
"#define" @constant.macro
|
||||
"#else" @keyword
|
||||
"#endif" @keyword
|
||||
"#if" @keyword
|
||||
"#ifdef" @keyword
|
||||
"#ifndef" @keyword
|
||||
"#include" @keyword
|
||||
(preproc_directive) @keyword
|
||||
|
||||
"--" @operator
|
||||
"-" @operator
|
||||
"-=" @operator
|
||||
"->" @operator
|
||||
"!=" @operator
|
||||
"*" @operator
|
||||
"&" @operator
|
||||
"&&" @operator
|
||||
"+" @operator
|
||||
"++" @operator
|
||||
"+=" @operator
|
||||
"<" @operator
|
||||
"==" @operator
|
||||
">" @operator
|
||||
"||" @operator
|
||||
|
||||
"." @delimiter
|
||||
";" @delimiter
|
||||
|
||||
(string_literal) @string
|
||||
(system_lib_string) @string
|
||||
|
||||
(null) @constant.builtin
|
||||
(number_literal) @number
|
||||
(char_literal) @number
|
||||
|
||||
(call_expression
|
||||
function: (identifier) @function)
|
||||
(call_expression
|
||||
function: (field_expression
|
||||
field: (field_identifier) @function))
|
||||
(function_declarator
|
||||
declarator: (identifier) @function)
|
||||
(preproc_function_def
|
||||
name: (identifier) @function.macro)
|
||||
|
||||
(field_identifier) @property
|
||||
(statement_identifier) @label
|
||||
(type_identifier) @type
|
||||
(primitive_type) @type
|
||||
(sized_type_specifier) @type
|
||||
|
||||
((identifier) @constant
|
||||
(match? @constant "^[A-Z][A-Z\\d_]+$"))
|
||||
|
||||
(comment) @comment
|
||||
36
queries/c/locals.scm
Normal file
36
queries/c/locals.scm
Normal file
|
|
@ -0,0 +1,36 @@
|
|||
;; Functions definitions
|
||||
(function_declarator
|
||||
declarator: (identifier) @definition.function) @scope
|
||||
(preproc_function_def
|
||||
name: (identifier) @definition.macro) @scope
|
||||
|
||||
(preproc_def
|
||||
name: (identifier) @definition.macro)
|
||||
(pointer_declarator
|
||||
declarator: (identifier) @definition.variable)
|
||||
(parameter_declaration
|
||||
declarator: (identifier) @definition.variable)
|
||||
(init_declarator
|
||||
declarator: (identifier) @definition.variable)
|
||||
(array_declarator
|
||||
declarator: (identifier) @definition.variable)
|
||||
(declaration
|
||||
declarator: (identifier) @definition.variable)
|
||||
(enum_specifier
|
||||
name: (*) @definition.type
|
||||
(enumerator_list
|
||||
(enumerator name: (identifier) @definition.variable)))
|
||||
|
||||
;; Type / Struct / Enum
|
||||
(field_declaration
|
||||
declarator: (field_identifier) @definition.field)
|
||||
(type_definition
|
||||
declarator: (type_identifier) @definition.type)
|
||||
|
||||
;; References
|
||||
(identifier) @reference
|
||||
|
||||
;; Scope
|
||||
(for_statement) @scope
|
||||
(if_statement) @scope
|
||||
(while_statement) @scope
|
||||
Loading…
Add table
Add a link
Reference in a new issue