diff options
Diffstat (limited to 'runtime/queries/c')
-rw-r--r-- | runtime/queries/c/folds.scm | 32 | ||||
-rw-r--r-- | runtime/queries/c/highlights.scm | 182 | ||||
-rw-r--r-- | runtime/queries/c/injections.scm | 23 |
3 files changed, 143 insertions, 94 deletions
diff --git a/runtime/queries/c/folds.scm b/runtime/queries/c/folds.scm index 5a35334a24..2e2a6b4d0c 100644 --- a/runtime/queries/c/folds.scm +++ b/runtime/queries/c/folds.scm @@ -1,19 +1,21 @@ [ - (for_statement) - (if_statement) - (while_statement) - (switch_statement) - (case_statement) - (function_definition) - (struct_specifier) - (enum_specifier) - (comment) - (preproc_if) - (preproc_elif) - (preproc_else) - (preproc_ifdef) - (initializer_list) - (gnu_asm_expression) + (for_statement) + (if_statement) + (while_statement) + (do_statement) + (switch_statement) + (case_statement) + (function_definition) + (struct_specifier) + (enum_specifier) + (comment) + (preproc_if) + (preproc_elif) + (preproc_else) + (preproc_ifdef) + (preproc_function_def) + (initializer_list) + (gnu_asm_expression) ] @fold (compound_statement 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 diff --git a/runtime/queries/c/injections.scm b/runtime/queries/c/injections.scm index 5a49e20df5..ce2f88a215 100644 --- a/runtime/queries/c/injections.scm +++ b/runtime/queries/c/injections.scm @@ -1,21 +1,2 @@ -((preproc_def - (preproc_arg) @injection.content) - (#lua-match? @injection.content "\n") - (#set! injection.language "c")) - -(preproc_function_def - (preproc_arg) @injection.content - (#set! injection.language "c")) - -(preproc_call - (preproc_arg) @injection.content - (#set! injection.language "c")) - -; ((comment) @injection.content -; (#set! injection.language "comment")) - -; TODO: add when asm is added -; (gnu_asm_expression assembly_code: (string_literal) @injection.content -; (#set! injection.language "asm")) -; (gnu_asm_expression assembly_code: (concatenated_string (string_literal) @injection.content) -; (#set! injection.language "asm")) +((preproc_arg) @injection.content + (#set! injection.self)) |