feat!: drop modules, general refactor and cleanup

This commit is contained in:
Christian Clason 2023-06-12 09:54:30 -06:00
parent c13e28f894
commit 2c8f2f2fad
829 changed files with 4905 additions and 8010 deletions

View file

@ -0,0 +1,20 @@
[
(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)
] @fold
(compound_statement
(compound_statement) @fold)

View file

@ -0,0 +1,286 @@
; Lower priority to prefer @parameter when identifier appears in parameter_declaration.
((identifier) @variable (#set! "priority" 95))
(preproc_def (preproc_arg) @variable)
[
"default"
"enum"
"struct"
"typedef"
"union"
"goto"
"asm"
"__asm__"
] @keyword
[
"sizeof"
"offsetof"
] @keyword.operator
(alignof_expression . _ @keyword.operator)
"return" @keyword.return
[
"while"
"for"
"do"
"continue"
"break"
] @repeat
[
"if"
"else"
"case"
"switch"
] @conditional
[
"#if"
"#ifdef"
"#ifndef"
"#else"
"#elif"
"#endif"
"#elifdef"
"#elifndef"
(preproc_directive)
] @preproc
"#define" @define
"#include" @include
[ ";" ":" "," "::" ] @punctuation.delimiter
"..." @punctuation.special
[ "(" ")" "[" "]" "{" "}"] @punctuation.bracket
[
"="
"-"
"*"
"/"
"+"
"%"
"~"
"|"
"&"
"^"
"<<"
">>"
"->"
"."
"<"
"<="
">="
">"
"=="
"!="
"!"
"&&"
"||"
"-="
"+="
"*="
"/="
"%="
"|="
"&="
"^="
">>="
"<<="
"--"
"++"
] @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)
(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_defined) @function.macro
(((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))
(statement_identifier) @label
[
(type_identifier)
(type_descriptor)
] @type
(storage_class_specifier) @storageclass
[
(type_qualifier)
(gnu_asm_qualifier)
"__extension__"
] @type.qualifier
(linkage_specification
"extern" @storageclass)
(type_definition
declarator: (type_identifier) @type.definition)
(primitive_type) @type.builtin
(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_]+$"))
(enumerator
name: (identifier) @constant)
(case_statement
value: (identifier) @constant)
((identifier) @constant.builtin
(#any-of? @constant.builtin
"stderr" "stdin" "stdout"
"__FILE__" "__LINE__" "__DATE__" "__TIME__"
"__STDC__" "__STDC_VERSION__" "__STDC_HOSTED__"
"__cplusplus" "__OBJC__" "__ASSEMBLER__"
"__BASE_FILE__" "__FILE_NAME__" "__INCLUDE_LEVEL__"
"__TIMESTAMP__" "__clang__" "__clang_major__"
"__clang_minor__" "__clang_patchlevel__"
"__clang_version__" "__clang_literal_encoding__"
"__clang_wide_literal_encoding__"
"__FUNCTION__" "__func__" "__PRETTY_FUNCTION__"
"__VA_ARGS__" "__VA_OPT__"))
(preproc_def (preproc_arg) @constant.builtin
(#any-of? @constant.builtin
"stderr" "stdin" "stdout"
"__FILE__" "__LINE__" "__DATE__" "__TIME__"
"__STDC__" "__STDC_VERSION__" "__STDC_HOSTED__"
"__cplusplus" "__OBJC__" "__ASSEMBLER__"
"__BASE_FILE__" "__FILE_NAME__" "__INCLUDE_LEVEL__"
"__TIMESTAMP__" "__clang__" "__clang_major__"
"__clang_minor__" "__clang_patchlevel__"
"__clang_version__" "__clang_literal_encoding__"
"__clang_wide_literal_encoding__"
"__FUNCTION__" "__func__" "__PRETTY_FUNCTION__"
"__VA_ARGS__" "__VA_OPT__"))
(attribute_specifier
(argument_list (identifier) @variable.builtin))
((attribute_specifier
(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)
(#has-ancestor? @function.builtin attribute_specifier))
;; Preproc def / undef
(preproc_def
name: (_) @constant)
(preproc_call
directive: (preproc_directive) @_u
argument: (_) @constant
(#eq? @_u "#undef"))
(call_expression
function: (identifier) @function.call)
(call_expression
function: (field_expression
field: (field_identifier) @function.call))
(function_declarator
declarator: (identifier) @function)
(function_declarator
declarator: (parenthesized_declarator
(pointer_declarator
declarator: (field_identifier) @function)))
(preproc_function_def
name: (identifier) @function.macro)
(comment) @comment @spell
((comment) @comment.documentation
(#lua-match? @comment.documentation "^/[*][*][^*].*[*]/$"))
;; Parameters
(parameter_declaration
declarator: (identifier) @parameter)
(parameter_declaration
declarator: (array_declarator) @parameter)
(parameter_declaration
declarator: (pointer_declarator) @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) @parameter)
;
; (function_definition
; declarator: _
; (declaration
; declarator: (identifier) @parameter))
;
; (function_definition
; declarator: _
; (declaration
; declarator: (array_declarator) @parameter))
;
; (function_definition
; declarator: _
; (declaration
; declarator: (pointer_declarator) @parameter))
(preproc_params (identifier) @parameter)
[
"__attribute__"
"__declspec"
"__based"
"__cdecl"
"__clrcall"
"__stdcall"
"__fastcall"
"__thiscall"
"__vectorcall"
(ms_pointer_modifier)
(attribute_declaration)
] @attribute
(ERROR) @error

View file

@ -0,0 +1,90 @@
[
(compound_statement)
(field_declaration_list)
(case_statement)
(enumerator_list)
(compound_literal_expression)
(initializer_list)
(init_declarator)
] @indent.begin
; With current indent logic, if we capture expression_statement with @indent.begin
; It will be affected by _parent_ node with error subnodes deep down the tree
; So narrow indent capture to check for error inside expression statement only,
(expression_statement
(_) @indent.begin
";" @indent.end)
(ERROR
"for" "(" @indent.begin ";" ";" ")" @indent.end)
((for_statement
body: (_) @_body) @indent.begin
(#not-has-type? @_body compound_statement))
(while_statement
condition: (_) @indent.begin)
((while_statement
body: (_) @_body) @indent.begin
(#not-has-type? @_body compound_statement))
(
(if_statement)
.
(ERROR "else" @indent.begin))
(if_statement
condition: (_) @indent.begin)
;; Supports if without braces (but not both if-else without braces)
((if_statement
consequence:
(_ ";" @indent.end) @_consequence
(#not-has-type? @_consequence compound_statement)
alternative:
(else_clause
"else" @indent.branch
[
(if_statement (compound_statement) @indent.dedent)? @indent.dedent
(compound_statement)? @indent.dedent
(_)? @indent.dedent
]
)?
) @indent.begin)
(else_clause (_ . "{" @indent.branch))
(compound_statement "}" @indent.end)
[
")"
"}"
(statement_identifier)
] @indent.branch
[
"#define"
"#ifdef"
"#ifndef"
"#elif"
"#if"
"#else"
"#endif"
] @indent.zero
[
(preproc_arg)
(string_literal)
] @indent.ignore
((ERROR (parameter_declaration)) @indent.align
(#set! indent.open_delimiter "(")
(#set! indent.close_delimiter ")"))
([(argument_list) (parameter_list)] @indent.align
(#set! indent.open_delimiter "(")
(#set! indent.close_delimiter ")"))
(comment) @indent.auto

View file

@ -0,0 +1,19 @@
((preproc_arg) @injection.content
(#set! injection.language "c"))
((comment) @injection.content
(#set! injection.language "comment"))
((comment) @injection.content
(#match? @injection.content "/\\*!([a-zA-Z]+:)?re2c")
(#set! injection.language "re2c"))
((comment) @injection.content
(#lua-match? @injection.content "/[*][!<*][^a-zA-Z]")
(#set! injection.language "doxygen"))
; 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"))

View file

@ -0,0 +1,53 @@
;; Functions definitions
(function_declarator
declarator: (identifier) @definition.function)
(preproc_function_def
name: (identifier) @definition.macro) @scope
(preproc_def
name: (identifier) @definition.macro)
(pointer_declarator
declarator: (identifier) @definition.var)
(parameter_declaration
declarator: (identifier) @definition.parameter)
(init_declarator
declarator: (identifier) @definition.var)
(array_declarator
declarator: (identifier) @definition.var)
(declaration
declarator: (identifier) @definition.var)
(enum_specifier
name: (_) @definition.type
(enumerator_list
(enumerator name: (identifier) @definition.var)))
;; Type / Struct / Enum
(field_declaration
declarator: (field_identifier) @definition.field)
(type_definition
declarator: (type_identifier) @definition.type)
(struct_specifier
name: (type_identifier) @definition.type)
;; goto
(labeled_statement (statement_identifier) @definition)
;; References
(identifier) @reference
((field_identifier) @reference
(#set! reference.kind "field"))
((type_identifier) @reference
(#set! reference.kind "type"))
(goto_statement (statement_identifier) @reference)
;; Scope
[
(for_statement)
(if_statement)
(while_statement)
(translation_unit)
(function_definition)
(compound_statement) ; a block in curly braces
(struct_specifier)
] @scope