aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorThomas Vigouroux <tomvig38@gmail.com>2020-05-15 11:45:25 +0200
committerThomas Vigouroux <tomvig38@gmail.com>2020-05-16 14:47:17 +0200
commit92aafcf51cb2bd8a4fa04017849cab7212512b23 (patch)
tree67c4b927170fea8a68f90886140a2904cb699282
parentMerge pull request #55 from vigoux/install-multiple-args (diff)
downloadnvim-treesitter-92aafcf51cb2bd8a4fa04017849cab7212512b23.tar
nvim-treesitter-92aafcf51cb2bd8a4fa04017849cab7212512b23.tar.gz
nvim-treesitter-92aafcf51cb2bd8a4fa04017849cab7212512b23.tar.bz2
nvim-treesitter-92aafcf51cb2bd8a4fa04017849cab7212512b23.tar.lz
nvim-treesitter-92aafcf51cb2bd8a4fa04017849cab7212512b23.tar.xz
nvim-treesitter-92aafcf51cb2bd8a4fa04017849cab7212512b23.tar.zst
nvim-treesitter-92aafcf51cb2bd8a4fa04017849cab7212512b23.zip
queries: add C queries
Also add a missing `field` capture in locals query.
-rw-r--r--CONTRIBUTING.md1
-rw-r--r--queries/c/highlights.scm77
-rw-r--r--queries/c/locals.scm36
3 files changed, 114 insertions, 0 deletions
diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md
index 46c7a9419..5335d04ea 100644
--- a/CONTRIBUTING.md
+++ b/CONTRIBUTING.md
@@ -92,6 +92,7 @@ are optional and will not have any effect for now.
`var`
`macro`
`type`
+ `field`
`@scope`
diff --git a/queries/c/highlights.scm b/queries/c/highlights.scm
new file mode 100644
index 000000000..4cfb042cc
--- /dev/null
+++ b/queries/c/highlights.scm
@@ -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
diff --git a/queries/c/locals.scm b/queries/c/locals.scm
new file mode 100644
index 000000000..159deca3a
--- /dev/null
+++ b/queries/c/locals.scm
@@ -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