diff options
| author | Christian Clason <c.clason@uni-graz.at> | 2023-06-12 09:54:30 -0600 |
|---|---|---|
| committer | Christian Clason <c.clason@uni-graz.at> | 2025-05-12 18:43:40 +0200 |
| commit | 692b051b09935653befdb8f7ba8afdb640adf17b (patch) | |
| tree | 167162b6b129ae04f68c5735078521a72917c742 /runtime/queries/zig | |
| parent | feat(c-family): inherit injections (diff) | |
| download | nvim-treesitter-692b051b09935653befdb8f7ba8afdb640adf17b.tar nvim-treesitter-692b051b09935653befdb8f7ba8afdb640adf17b.tar.gz nvim-treesitter-692b051b09935653befdb8f7ba8afdb640adf17b.tar.bz2 nvim-treesitter-692b051b09935653befdb8f7ba8afdb640adf17b.tar.lz nvim-treesitter-692b051b09935653befdb8f7ba8afdb640adf17b.tar.xz nvim-treesitter-692b051b09935653befdb8f7ba8afdb640adf17b.tar.zst nvim-treesitter-692b051b09935653befdb8f7ba8afdb640adf17b.zip | |
feat!: drop modules, general refactor and cleanup
Diffstat (limited to 'runtime/queries/zig')
| -rw-r--r-- | runtime/queries/zig/folds.scm | 23 | ||||
| -rw-r--r-- | runtime/queries/zig/highlights.scm | 283 | ||||
| -rw-r--r-- | runtime/queries/zig/indents.scm | 28 | ||||
| -rw-r--r-- | runtime/queries/zig/injections.scm | 10 | ||||
| -rw-r--r-- | runtime/queries/zig/locals.scm | 96 |
5 files changed, 440 insertions, 0 deletions
diff --git a/runtime/queries/zig/folds.scm b/runtime/queries/zig/folds.scm new file mode 100644 index 000000000..6be5c62ba --- /dev/null +++ b/runtime/queries/zig/folds.scm @@ -0,0 +1,23 @@ +[ + (block) + (switch_expression) + (initializer_list) + (asm_expression) + (multiline_string) + (if_statement) + (while_statement) + (for_statement) + (if_expression) + (else_clause) + (for_expression) + (while_expression) + (if_type_expression) + (function_signature) + (parameters) + (call_expression) + (struct_declaration) + (opaque_declaration) + (enum_declaration) + (union_declaration) + (error_set_declaration) +] @fold diff --git a/runtime/queries/zig/highlights.scm b/runtime/queries/zig/highlights.scm new file mode 100644 index 000000000..1f9006781 --- /dev/null +++ b/runtime/queries/zig/highlights.scm @@ -0,0 +1,283 @@ +; Variables +(identifier) @variable + +; Parameters +(parameter + name: (identifier) @variable.parameter) + +(payload + (identifier) @variable.parameter) + +; Types +(parameter + type: (identifier) @type) + +((identifier) @type + (#lua-match? @type "^[A-Z_][a-zA-Z0-9_]*")) + +(variable_declaration + (identifier) @type + "=" + [ + (struct_declaration) + (enum_declaration) + (union_declaration) + (opaque_declaration) + ]) + +[ + (builtin_type) + "anyframe" +] @type.builtin + +; Constants +((identifier) @constant + (#lua-match? @constant "^[A-Z][A-Z_0-9]+$")) + +[ + "null" + "unreachable" + "undefined" +] @constant.builtin + +(field_expression + . + member: (identifier) @constant) + +(enum_declaration + (container_field + type: (identifier) @constant)) + +; Labels +(block_label + (identifier) @label) + +(break_label + (identifier) @label) + +; Fields +(field_initializer + . + (identifier) @variable.member) + +(field_expression + (_) + member: (identifier) @variable.member) + +(container_field + name: (identifier) @variable.member) + +(initializer_list + (assignment_expression + left: (field_expression + . + member: (identifier) @variable.member))) + +; Functions +(builtin_identifier) @function.builtin + +(call_expression + function: (identifier) @function.call) + +(call_expression + function: (field_expression + member: (identifier) @function.call)) + +(function_declaration + name: (identifier) @function) + +; Modules +(variable_declaration + (identifier) @module + (builtin_function + (builtin_identifier) @keyword.import + (#any-of? @keyword.import "@import" "@cImport"))) + +; Builtins +[ + "c" + "..." +] @variable.builtin + +((identifier) @variable.builtin + (#eq? @variable.builtin "_")) + +(calling_convention + (identifier) @variable.builtin) + +; Keywords +[ + "asm" + "defer" + "errdefer" + "test" + "error" + "const" + "var" +] @keyword + +[ + "struct" + "union" + "enum" + "opaque" +] @keyword.type + +[ + "async" + "await" + "suspend" + "nosuspend" + "resume" +] @keyword.coroutine + +"fn" @keyword.function + +[ + "and" + "or" + "orelse" +] @keyword.operator + +"return" @keyword.return + +[ + "if" + "else" + "switch" +] @keyword.conditional + +[ + "for" + "while" + "break" + "continue" +] @keyword.repeat + +[ + "usingnamespace" + "export" +] @keyword.import + +[ + "try" + "catch" +] @keyword.exception + +[ + "volatile" + "allowzero" + "noalias" + "addrspace" + "align" + "callconv" + "linksection" + "pub" + "inline" + "noinline" + "extern" + "comptime" + "packed" + "threadlocal" +] @keyword.modifier + +; Operator +[ + "=" + "*=" + "*%=" + "*|=" + "/=" + "%=" + "+=" + "+%=" + "+|=" + "-=" + "-%=" + "-|=" + "<<=" + "<<|=" + ">>=" + "&=" + "^=" + "|=" + "!" + "~" + "-" + "-%" + "&" + "==" + "!=" + ">" + ">=" + "<=" + "<" + "&" + "^" + "|" + "<<" + ">>" + "<<|" + "+" + "++" + "+%" + "-%" + "+|" + "-|" + "*" + "/" + "%" + "**" + "*%" + "*|" + "||" + ".*" + ".?" + "?" + ".." +] @operator + +; Literals +(character) @character + +([ + (string) + (multiline_string) +] @string + (#set! "priority" 95)) + +(integer) @number + +(float) @number.float + +(boolean) @boolean + +(escape_sequence) @string.escape + +; Punctuation +[ + "[" + "]" + "(" + ")" + "{" + "}" +] @punctuation.bracket + +[ + ";" + "." + "," + ":" + "=>" + "->" +] @punctuation.delimiter + +(payload + "|" @punctuation.bracket) + +; Comments +(comment) @comment @spell + +((comment) @comment.documentation + (#lua-match? @comment.documentation "^//!")) diff --git a/runtime/queries/zig/indents.scm b/runtime/queries/zig/indents.scm new file mode 100644 index 000000000..11ff9ca16 --- /dev/null +++ b/runtime/queries/zig/indents.scm @@ -0,0 +1,28 @@ +[ + (block) + (struct_declaration) + (enum_declaration) + (union_declaration) + (switch_expression) + (if_expression) + (while_expression) + (for_expression) + (initializer_list) +] @indent.begin + +(block + "}" @indent.end) + +[ + "(" + ")" + "[" + "]" + "{" + "}" +] @indent.branch + +[ + (comment) + (multiline_string) +] @indent.ignore diff --git a/runtime/queries/zig/injections.scm b/runtime/queries/zig/injections.scm new file mode 100644 index 000000000..48a1b44c9 --- /dev/null +++ b/runtime/queries/zig/injections.scm @@ -0,0 +1,10 @@ +((comment) @injection.content + (#set! injection.language "comment")) + +; TODO: add when asm is added +; (asm_output_item (string) @injection.content +; (#set! injection.language "asm")) +; (asm_input_item (string) @injection.content +; (#set! injection.language "asm")) +; (asm_clobbers (string) @injection.content +; (#set! injection.language "asm")) diff --git a/runtime/queries/zig/locals.scm b/runtime/queries/zig/locals.scm new file mode 100644 index 000000000..b9e63441d --- /dev/null +++ b/runtime/queries/zig/locals.scm @@ -0,0 +1,96 @@ +; Definitions +(function_declaration + name: (identifier) @local.definition.function) + +(parameter + name: (identifier) @local.definition.parameter) + +(variable_declaration + (identifier) @local.definition.var) + +(variable_declaration + (identifier) @local.definition.type + (enum_declaration)) + +(container_field + type: (identifier) @local.definition.field) + +(enum_declaration + (function_declaration + name: (identifier) @local.definition.method)) + +(variable_declaration + (identifier) @local.definition.type + (struct_declaration)) + +(struct_declaration + (function_declaration + name: (identifier) @local.definition.method)) + +(container_field + name: (identifier) @local.definition.field) + +(variable_declaration + (identifier) @local.definition.type + (union_declaration)) + +(union_declaration + (function_declaration + name: (identifier) @local.definition.method)) + +(payload + (identifier) @local.definition.var) + +(block_label + (identifier) @local.definition) + +; References +(identifier) @local.reference + +(parameter + type: (identifier) @local.reference + (#set! reference.kind "type")) + +(pointer_type + (identifier) @local.reference + (#set! reference.kind "type")) + +(nullable_type + (identifier) @local.reference + (#set! reference.kind "type")) + +(struct_initializer + (identifier) @local.reference + (#set! reference.kind "type")) + +(array_type + (_) + (identifier) @local.reference + (#set! reference.kind "type")) + +(slice_type + (identifier) @local.reference + (#set! reference.kind "type")) + +(field_expression + member: (identifier) @local.reference + (#set! reference.kind "field")) + +(call_expression + function: (field_expression + member: (identifier) @local.reference + (#set! reference.kind "function"))) + +(break_label + (identifier) @local.reference) + +[ + (for_statement) + (if_statement) + (while_statement) + (function_declaration) + (block) + (source_file) + (enum_declaration) + (struct_declaration) +] @local.scope |
