diff options
| author | Amaan Qureshi <amaanq12@gmail.com> | 2024-08-29 22:37:17 -0400 |
|---|---|---|
| committer | Amaan Qureshi <amaanq12@gmail.com> | 2024-08-30 00:49:33 -0400 |
| commit | ba921c9aef386ad895b0a6551968126ff90a288d (patch) | |
| tree | 14efaecff8e7655a6c26fc0081d5e64f43834e23 /queries/zig | |
| parent | bot(lockfile): update angular, mlir (diff) | |
| download | nvim-treesitter-ba921c9aef386ad895b0a6551968126ff90a288d.tar nvim-treesitter-ba921c9aef386ad895b0a6551968126ff90a288d.tar.gz nvim-treesitter-ba921c9aef386ad895b0a6551968126ff90a288d.tar.bz2 nvim-treesitter-ba921c9aef386ad895b0a6551968126ff90a288d.tar.lz nvim-treesitter-ba921c9aef386ad895b0a6551968126ff90a288d.tar.xz nvim-treesitter-ba921c9aef386ad895b0a6551968126ff90a288d.tar.zst nvim-treesitter-ba921c9aef386ad895b0a6551968126ff90a288d.zip | |
feat!: switch upstream Zig parser
The new parser is faster, does not lag while editing, correctly parses
the entire Zig code base, and is much easier to write queries for.
Diffstat (limited to 'queries/zig')
| -rw-r--r-- | queries/zig/folds.scm | 33 | ||||
| -rw-r--r-- | queries/zig/highlights.scm | 280 | ||||
| -rw-r--r-- | queries/zig/indents.scm | 15 | ||||
| -rw-r--r-- | queries/zig/injections.scm | 14 |
4 files changed, 198 insertions, 144 deletions
diff --git a/queries/zig/folds.scm b/queries/zig/folds.scm index 6953091be..6be5c62ba 100644 --- a/queries/zig/folds.scm +++ b/queries/zig/folds.scm @@ -1,14 +1,23 @@ [ - (Block) - (ContainerDecl) - (SwitchExpr) - (InitList) - (AsmExpr) - (ErrorSetDecl) - (LINESTRING) - [ - (IfPrefix) - (WhilePrefix) - (ForPrefix) - ] + (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/queries/zig/highlights.scm b/queries/zig/highlights.scm index d0f6e5b79..1f9006781 100644 --- a/queries/zig/highlights.scm +++ b/queries/zig/highlights.scm @@ -1,104 +1,116 @@ -(line_comment) @comment @spell +; Variables +(identifier) @variable -[ - (container_doc_comment) - (doc_comment) -] @comment.documentation @spell +; Parameters +(parameter + name: (identifier) @variable.parameter) -[ - variable: (IDENTIFIER) - variable_type_function: (IDENTIFIER) -] @variable +(payload + (identifier) @variable.parameter) -parameter: (IDENTIFIER) @variable.parameter +; Types +(parameter + type: (identifier) @type) -[ - field_member: (IDENTIFIER) - field_access: (IDENTIFIER) -] @variable.member - -; assume TitleCase is a type -([ - variable_type_function: (IDENTIFIER) - field_access: (IDENTIFIER) - parameter: (IDENTIFIER) -] @type - (#lua-match? @type "^%u([%l]+[%u%l%d]*)*$")) +((identifier) @type + (#lua-match? @type "^[A-Z_][a-zA-Z0-9_]*")) -; assume camelCase is a function -([ - variable_type_function: (IDENTIFIER) - field_access: (IDENTIFIER) - parameter: (IDENTIFIER) -] @function - (#lua-match? @function "^%l+([%u][%l%d]*)+$")) +(variable_declaration + (identifier) @type + "=" + [ + (struct_declaration) + (enum_declaration) + (union_declaration) + (opaque_declaration) + ]) -; assume all CAPS_1 is a constant -([ - variable_type_function: (IDENTIFIER) - field_access: (IDENTIFIER) -] @constant - (#lua-match? @constant "^%u[%u%d_]+$")) +[ + (builtin_type) + "anyframe" +] @type.builtin -function: (IDENTIFIER) @function +; Constants +((identifier) @constant + (#lua-match? @constant "^[A-Z][A-Z_0-9]+$")) -function_call: (IDENTIFIER) @function.call +[ + "null" + "unreachable" + "undefined" +] @constant.builtin -exception: "!" @keyword.exception +(field_expression + . + member: (identifier) @constant) -((IDENTIFIER) @variable.builtin - (#eq? @variable.builtin "_")) +(enum_declaration + (container_field + type: (identifier) @constant)) -(PtrTypeStart - "c" @variable.builtin) +; Labels +(block_label + (identifier) @label) -(ContainerDecl - (ContainerDeclType - "enum") - (ContainerField - (ErrorUnionExpr - (SuffixExpr - (IDENTIFIER) @constant)))) +(break_label + (identifier) @label) -field_constant: (IDENTIFIER) @constant +; Fields +(field_initializer + . + (identifier) @variable.member) -(BUILTINIDENTIFIER) @function.builtin +(field_expression + (_) + member: (identifier) @variable.member) -((BUILTINIDENTIFIER) @keyword.import - (#any-of? @keyword.import "@import" "@cImport")) +(container_field + name: (identifier) @variable.member) -(INTEGER) @number +(initializer_list + (assignment_expression + left: (field_expression + . + member: (identifier) @variable.member))) -(FLOAT) @number.float +; Functions +(builtin_identifier) @function.builtin -[ - "true" - "false" -] @boolean +(call_expression + function: (identifier) @function.call) -[ - (LINESTRING) - (STRINGLITERALSINGLE) -] @string @spell +(call_expression + function: (field_expression + member: (identifier) @function.call)) -(CHAR_LITERAL) @character +(function_declaration + name: (identifier) @function) -(EscapeSequence) @string.escape +; Modules +(variable_declaration + (identifier) @module + (builtin_function + (builtin_identifier) @keyword.import + (#any-of? @keyword.import "@import" "@cImport"))) -(FormatSequence) @string.special +; Builtins +[ + "c" + "..." +] @variable.builtin -(BreakLabel - (IDENTIFIER) @label) +((identifier) @variable.builtin + (#eq? @variable.builtin "_")) -(BlockLabel - (IDENTIFIER) @label) +(calling_convention + (identifier) @variable.builtin) +; Keywords [ "asm" "defer" "errdefer" "test" - "opaque" "error" "const" "var" @@ -108,6 +120,7 @@ field_constant: (IDENTIFIER) @constant "struct" "union" "enum" + "opaque" ] @keyword.type [ @@ -152,11 +165,6 @@ field_constant: (IDENTIFIER) @constant ] @keyword.exception [ - "anytype" - (BuildinTypeExpr) -] @type.builtin - -[ "volatile" "allowzero" "noalias" @@ -168,50 +176,85 @@ field_constant: (IDENTIFIER) @constant "inline" "noinline" "extern" -] @keyword.modifier - -[ "comptime" "packed" "threadlocal" -] @attribute - -[ - "null" - "unreachable" - "undefined" -] @constant.builtin +] @keyword.modifier +; Operator [ - (CompareOp) - (BitwiseOp) - (BitShiftOp) - (AdditionOp) - (AssignOp) - (MultiplyOp) - (PrefixOp) "=" + "*=" + "*%=" + "*|=" + "/=" + "%=" + "+=" + "+%=" + "+|=" + "-=" + "-%=" + "-|=" + "<<=" + "<<|=" + ">>=" + "&=" + "^=" + "|=" + "!" + "~" + "-" + "-%" + "&" + "==" + "!=" + ">" + ">=" + "<=" + "<" + "&" + "^" + "|" + "<<" + ">>" + "<<|" + "+" + "++" + "+%" + "-%" + "+|" + "-|" "*" + "/" + "%" "**" - "->" - ".?" + "*%" + "*|" + "||" ".*" + ".?" "?" + ".." ] @operator -[ - ";" - "." - "," - ":" - "=>" -] @punctuation.delimiter +; Literals +(character) @character -[ - ".." - "..." -] @punctuation.special +([ + (string) + (multiline_string) +] @string + (#set! "priority" 95)) +(integer) @number + +(float) @number.float + +(boolean) @boolean + +(escape_sequence) @string.escape + +; Punctuation [ "[" "]" @@ -221,19 +264,20 @@ field_constant: (IDENTIFIER) @constant "}" ] @punctuation.bracket -(Payload - "|" @punctuation.bracket) - -(PtrPayload - "|" @punctuation.bracket) +[ + ";" + "." + "," + ":" + "=>" + "->" +] @punctuation.delimiter -(PtrIndexPayload +(payload "|" @punctuation.bracket) -(PtrListPayload - "|" @punctuation.bracket) +; Comments +(comment) @comment @spell -(ParamType - (ErrorUnionExpr - (SuffixExpr - variable_type_function: (IDENTIFIER) @type))) +((comment) @comment.documentation + (#lua-match? @comment.documentation "^//!")) diff --git a/queries/zig/indents.scm b/queries/zig/indents.scm index bf9d3e42a..431aed5b6 100644 --- a/queries/zig/indents.scm +++ b/queries/zig/indents.scm @@ -1,11 +1,10 @@ [ - (Block) - (ContainerDecl) - (SwitchExpr) - (InitList) + (block) + (switch_expression) + (initializer_list) ] @indent.begin -(Block +(block "}" @indent.end) [ @@ -18,8 +17,6 @@ ] @indent.branch [ - (line_comment) - (container_doc_comment) - (doc_comment) - (LINESTRING) + (comment) + (multiline_string) ] @indent.ignore diff --git a/queries/zig/injections.scm b/queries/zig/injections.scm index 9e687ca76..48a1b44c9 100644 --- a/queries/zig/injections.scm +++ b/queries/zig/injections.scm @@ -1,6 +1,10 @@ -([ - (container_doc_comment) - (doc_comment) - (line_comment) -] @injection.content +((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")) |
