diff options
Diffstat (limited to 'runtime/queries/c/highlights.scm')
-rw-r--r-- | runtime/queries/c/highlights.scm | 182 |
1 files changed, 124 insertions, 58 deletions
diff --git a/runtime/queries/c/highlights.scm b/runtime/queries/c/highlights.scm index 29fb5747ca..c848f68dca 100644 --- a/runtime/queries/c/highlights.scm +++ b/runtime/queries/c/highlights.scm @@ -1,6 +1,9 @@ -; Lower priority to prefer @parameter when identifier appears in parameter_declaration. -((identifier) @variable (#set! "priority" 95)) -(preproc_def (preproc_arg) @variable) +; Lower priority to prefer @variable.parameter when identifier appears in parameter_declaration. +((identifier) @variable + (#set! "priority" 95)) + +(preproc_def + (preproc_arg) @variable) [ "default" @@ -17,7 +20,10 @@ "sizeof" "offsetof" ] @keyword.operator -(alignof_expression . _ @keyword.operator) + +(alignof_expression + . + _ @keyword.operator) "return" @keyword.return @@ -27,14 +33,14 @@ "do" "continue" "break" -] @repeat +] @keyword.repeat [ - "if" - "else" - "case" - "switch" -] @conditional + "if" + "else" + "case" + "switch" +] @keyword.conditional [ "#if" @@ -46,48 +52,54 @@ "#elifdef" "#elifndef" (preproc_directive) -] @preproc +] @keyword.directive -"#define" @define +"#define" @keyword.directive.define -"#include" @include +"#include" @keyword.import -[ ";" ":" "," "::" ] @punctuation.delimiter +[ + ";" + ":" + "," + "::" +] @punctuation.delimiter "..." @punctuation.special -[ "(" ")" "[" "]" "{" "}"] @punctuation.bracket +[ + "(" + ")" + "[" + "]" + "{" + "}" +] @punctuation.bracket [ "=" - "-" "*" "/" "+" "%" - "~" "|" "&" "^" "<<" ">>" - "->" "." - "<" "<=" ">=" ">" "==" "!=" - "!" "&&" "||" - "-=" "+=" "*=" @@ -102,45 +114,57 @@ "++" ] @operator -;; Make sure the comma operator is given a highlight group after the comma -;; punctuator so the operator is highlighted properly. -(comma_expression [ "," ] @operator) +; Make sure the comma operator is given a highlight group after the comma +; punctuator so the operator is highlighted properly. +(comma_expression + "," @operator) [ (true) (false) ] @boolean -(conditional_expression [ "?" ":" ] @conditional.ternary) +(conditional_expression + [ + "?" + ":" + ] @keyword.conditional.ternary) (string_literal) @string + (system_lib_string) @string + (escape_sequence) @string.escape (null) @constant.builtin + (number_literal) @number + (char_literal) @character -((preproc_arg) @function.macro (#set! "priority" 90)) +((preproc_arg) @function.macro + (#set! "priority" 90)) + (preproc_defined) @function.macro -(((field_expression - (field_identifier) @property)) @_parent - (#not-has-parent? @_parent template_method function_declarator call_expression)) +((field_expression + (field_identifier) @property) @_parent + (#not-has-parent? @_parent template_method function_declarator call_expression)) (field_designator) @property -(((field_identifier) @property) - (#has-ancestor? @property field_declaration) - (#not-has-ancestor? @property function_declarator)) + +((field_identifier) @property + (#has-ancestor? @property field_declaration) + (#not-has-ancestor? @property function_declarator)) (statement_identifier) @label [ - (type_identifier) - (type_descriptor) + (type_identifier) + (type_descriptor) ] @type -(storage_class_specifier) @storageclass +(storage_class_specifier) @keyword.storage [ (type_qualifier) @@ -149,25 +173,32 @@ ] @type.qualifier (linkage_specification - "extern" @storageclass) + "extern" @keyword.storage) (type_definition declarator: (type_identifier) @type.definition) (primitive_type) @type.builtin -(sized_type_specifier _ @type.builtin type: _?) +(sized_type_specifier + _ @type.builtin + type: _?) ((identifier) @constant - (#lua-match? @constant "^[A-Z][A-Z0-9_]+$")) -(preproc_def (preproc_arg) @constant (#lua-match? @constant "^[A-Z][A-Z0-9_]+$")) + +(preproc_def + (preproc_arg) @constant + (#lua-match? @constant "^[A-Z][A-Z0-9_]+$")) + (enumerator name: (identifier) @constant) + (case_statement value: (identifier) @constant) ((identifier) @constant.builtin + ; format-ignore (#any-of? @constant.builtin "stderr" "stdin" "stdout" "__FILE__" "__LINE__" "__DATE__" "__TIME__" @@ -180,7 +211,10 @@ "__clang_wide_literal_encoding__" "__FUNCTION__" "__func__" "__PRETTY_FUNCTION__" "__VA_ARGS__" "__VA_OPT__")) -(preproc_def (preproc_arg) @constant.builtin + +(preproc_def + (preproc_arg) @constant.builtin + ; format-ignore (#any-of? @constant.builtin "stderr" "stdin" "stdout" "__FILE__" "__LINE__" "__DATE__" "__TIME__" @@ -195,21 +229,26 @@ "__VA_ARGS__" "__VA_OPT__")) (attribute_specifier - (argument_list (identifier) @variable.builtin)) + (argument_list + (identifier) @variable.builtin)) + ((attribute_specifier - (argument_list (call_expression - function: (identifier) @variable.builtin)))) + (argument_list + (call_expression + function: (identifier) @variable.builtin)))) ((call_expression function: (identifier) @function.builtin) (#lua-match? @function.builtin "^__builtin_")) + ((call_expression - function: (identifier) @function.builtin) + function: (identifier) @function.builtin) (#has-ancestor? @function.builtin attribute_specifier)) -;; Preproc def / undef +; Preproc def / undef (preproc_def name: (_) @constant) + (preproc_call directive: (preproc_directive) @_u argument: (_) @constant @@ -217,15 +256,21 @@ (call_expression function: (identifier) @function.call) + (call_expression - function: (field_expression - field: (field_identifier) @function.call)) + function: + (field_expression + field: (field_identifier) @function.call)) + (function_declarator declarator: (identifier) @function) + (function_declarator - declarator: (parenthesized_declarator - (pointer_declarator - declarator: (field_identifier) @function))) + declarator: + (parenthesized_declarator + (pointer_declarator + declarator: (field_identifier) @function))) + (preproc_function_def name: (identifier) @function.macro) @@ -234,17 +279,40 @@ ((comment) @comment.documentation (#lua-match? @comment.documentation "^/[*][*][^*].*[*]/$")) -;; Parameters +; Parameters (parameter_declaration - declarator: (identifier) @parameter) + declarator: (identifier) @variable.parameter) (parameter_declaration - declarator: (array_declarator) @parameter) + declarator: (array_declarator) @variable.parameter) (parameter_declaration - declarator: (pointer_declarator) @parameter) - -(preproc_params (identifier) @parameter) + declarator: (pointer_declarator) @variable.parameter) + +; K&R functions +; To enable support for K&R functions, +; add the following lines to your own query config and uncomment them. +; They are commented out as they'll conflict with C++ +; Note that you'll need to have `; extends` at the top of your query file. +; +; (parameter_list (identifier) @variable.parameter) +; +; (function_definition +; declarator: _ +; (declaration +; declarator: (identifier) @variable.parameter)) +; +; (function_definition +; declarator: _ +; (declaration +; declarator: (array_declarator) @variable.parameter)) +; +; (function_definition +; declarator: _ +; (declaration +; declarator: (pointer_declarator) @variable.parameter)) +(preproc_params + (identifier) @variable.parameter) [ "__attribute__" @@ -259,5 +327,3 @@ (ms_pointer_modifier) (attribute_declaration) ] @attribute - -(ERROR) @error |