Merge pull request #53 from vigoux/c-queries

Add C queries
This commit is contained in:
Kiyan Yazdani 2020-05-16 15:02:12 +02:00 committed by GitHub
commit 45400888ad
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 116 additions and 1 deletions

View file

@ -92,6 +92,7 @@ are optional and will not have any effect for now.
`var`
`macro`
`type`
`field`
`@scope`

View file

@ -154,7 +154,7 @@ We are looking for maintainers to write query files for their languages.
List of currently supported languages:
- [x] lua (maintained by @vigoux)
- [x] ruby (maintained by @TravonteD)
- [ ] c
- [x] c (maintained by @vigoux)
- [ ] go
- [ ] cpp
- [ ] rust
@ -179,6 +179,7 @@ List of currently supported languages:
- [ ] elm
- [ ] yaml
- [ ] nix
- [ ] markdown
## Troubleshooting
Before doing anything run `:checkhealth nvim_treesitter`. This will help you find where the bug might come from.

77
queries/c/highlights.scm Normal file
View 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
View 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