From 3102fcecd7bd10bd1785ddcf11303e733f10cf76 Mon Sep 17 00:00:00 2001 From: sbancuz <sbancuz@protonmail.com> Date: Mon, 9 Sep 2024 12:25:43 +0200 Subject: [PATCH] Update zig sources and highlights --- .gitmodules | 12 +- queries/zig/highlights.scm | 427 +++++++++++++++++++++---------------- repos/zig | 2 +- 3 files changed, 248 insertions(+), 193 deletions(-) diff --git a/.gitmodules b/.gitmodules index f41f8964..e8707d9e 100644 --- a/.gitmodules +++ b/.gitmodules @@ -199,12 +199,6 @@ branch = master update = none ignore = dirty -[submodule "repos/zig"] - path = repos/zig - url = https://github.com/maxxnino/tree-sitter-zig - branch = main - update = none - ignore = dirty [submodule "repos/verilog"] path = repos/verilog url = https://github.com/tree-sitter/tree-sitter-verilog.git @@ -618,3 +612,9 @@ update = none ignore = dirty branch = main +[submodule "repos/zig"] + path = repos/zig + url = https://github.com/tree-sitter-grammars/tree-sitter-zig.git + update = none + ignore = dirty + branch = master diff --git a/queries/zig/highlights.scm b/queries/zig/highlights.scm index e7f0b662..1f900678 100644 --- a/queries/zig/highlights.scm +++ b/queries/zig/highlights.scm @@ -1,228 +1,283 @@ -(line_comment) @comment @spell +; Variables +(identifier) @variable -[ - (container_doc_comment) - (doc_comment) - ] @doc @spell +; Parameters +(parameter + name: (identifier) @variable.parameter) -;; [ -;; variable: (IDENTIFIER) -;; variable_type_function: (IDENTIFIER) -;; ] @variable +(payload + (identifier) @variable.parameter) -parameter: (IDENTIFIER) @parameter +; Types +(parameter + type: (identifier) @type) -[ - field_member: (IDENTIFIER) - field_access: (IDENTIFIER) - ] @field - -;; assume TitleCase is a type -( - [ - variable_type_function: (IDENTIFIER) - field_access: (IDENTIFIER) - parameter: (IDENTIFIER) - ] @type - (#match? @type "^[A-Z]+([a-z]+[A-Za-z0-9]*)*$") - ) - -;; assume camelCase is a function -( - [ - variable_type_function: (IDENTIFIER) - field_access: (IDENTIFIER) - parameter: (IDENTIFIER) - ] @function - (#match? @function "^[a-z]+([A-Z]+[a-z0-9]*)+$") - ) - -;; assume all CAPS_1 is a constant -( - [ - variable_type_function: (IDENTIFIER) - field_access: (IDENTIFIER) - ] @constant - (#match? @constant "^[A-Z]+[A-Z_0-9]+$") - ) - -function: (IDENTIFIER) @function - -function_call: (IDENTIFIER) @function.call - -exception: "!" @punctuation - -((IDENTIFIER) @variable.builtin - (#eq? @variable.builtin "_")) - -(PtrTypeStart "c" @variable.builtin) - -((ContainerDeclType +((identifier) @type + (#lua-match? @type "^[A-Z_][a-zA-Z0-9_]*")) + +(variable_declaration + (identifier) @type + "=" [ - (ErrorUnionExpr) - "enum" - ]) - (ContainerField (IDENTIFIER) @constant)) + (struct_declaration) + (enum_declaration) + (union_declaration) + (opaque_declaration) + ]) -field_constant: (IDENTIFIER) @constant +[ + (builtin_type) + "anyframe" +] @type.builtin -(BUILTINIDENTIFIER) @function.builtin +; Constants +((identifier) @constant + (#lua-match? @constant "^[A-Z][A-Z_0-9]+$")) -((BUILTINIDENTIFIER) @include - (#any-of? @include "@import" "@cImport")) +[ + "null" + "unreachable" + "undefined" +] @constant.builtin -(INTEGER) @number -(FLOAT) @number +(field_expression + . + member: (identifier) @constant) -[ - "true" - "false" - ] @boolean +(enum_declaration + (container_field + type: (identifier) @constant)) -[ - (LINESTRING) - (STRINGLITERALSINGLE) - ] @string @spell +; Labels +(block_label + (identifier) @label) -(CHAR_LITERAL) @string -(EscapeSequence) @string.escape -(FormatSequence) @string.special +(break_label + (identifier) @label) -(BreakLabel (IDENTIFIER) @label) -(BlockLabel (IDENTIFIER) @label) +; Fields +(field_initializer + . + (identifier) @variable.member) -[ - "asm" - "defer" - "errdefer" - "test" - "struct" - "union" - "enum" - "opaque" - "error" - ] @keyword +(field_expression + (_) + member: (identifier) @variable.member) -[ - "async" - "await" - "suspend" - "nosuspend" - "resume" - ] @keyword +(container_field + name: (identifier) @variable.member) -[ - "fn" - ] @keyword +(initializer_list + (assignment_expression + left: (field_expression + . + member: (identifier) @variable.member))) -[ - "and" - "or" - "orelse" - ] @keyword +; Functions +(builtin_identifier) @function.builtin -[ - "return" - ] @keyword +(call_expression + function: (identifier) @function.call) -[ - "if" - "else" - "switch" - ] @conditional +(call_expression + function: (field_expression + member: (identifier) @function.call)) -[ - "for" - "while" - "break" - "continue" - ] @repeat +(function_declaration + name: (identifier) @function) +; Modules +(variable_declaration + (identifier) @module + (builtin_function + (builtin_identifier) @keyword.import + (#any-of? @keyword.import "@import" "@cImport"))) + +; Builtins [ - "usingnamespace" - ] @include + "c" + "..." +] @variable.builtin + +((identifier) @variable.builtin + (#eq? @variable.builtin "_")) +(calling_convention + (identifier) @variable.builtin) + +; Keywords [ - "try" - "catch" - ] @exception + "asm" + "defer" + "errdefer" + "test" + "error" + "const" + "var" +] @keyword [ - "anytype" - (BuildinTypeExpr) - ] @keyword + "struct" + "union" + "enum" + "opaque" +] @keyword.type [ - "const" - "var" - "volatile" - "allowzero" - "noalias" - ] @keyword + "async" + "await" + "suspend" + "nosuspend" + "resume" +] @keyword.coroutine + +"fn" @keyword.function [ - "addrspace" - "align" - "callconv" - "linksection" - ] @keyword + "and" + "or" + "orelse" +] @keyword.operator + +"return" @keyword.return [ - "comptime" - "export" - "extern" - "inline" - "noinline" - "packed" - "pub" - "threadlocal" - ] @keyword + "if" + "else" + "switch" +] @keyword.conditional [ - "null" - "unreachable" - "undefined" - ] @constant.builtin + "for" + "while" + "break" + "continue" +] @keyword.repeat [ - (CompareOp) - (BitwiseOp) - (BitShiftOp) - (AdditionOp) - (AssignOp) - (MultiplyOp) - (PrefixOp) - "*" - "**" - "->" - ".?" - ".*" - "?" - ] @operator + "usingnamespace" + "export" +] @keyword.import [ - ";" - "." - "," - ":" - ] @punctuation.delimiter + "try" + "catch" +] @keyword.exception [ - ".." - "..." - ] @punctuation.special + "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 [ - "[" - "]" - "(" - ")" - "{" - "}" - (Payload "|") - (PtrPayload "|") - (PtrIndexPayload "|") - ] @punctuation.bracket - -;; Error -(ERROR) @error + ";" + "." + "," + ":" + "=>" + "->" +] @punctuation.delimiter + +(payload + "|" @punctuation.bracket) + +; Comments +(comment) @comment @spell + +((comment) @comment.documentation + (#lua-match? @comment.documentation "^//!")) diff --git a/repos/zig b/repos/zig index 2bac4cc6..21e2218e 160000 --- a/repos/zig +++ b/repos/zig @@ -1 +1 @@ -Subproject commit 2bac4cc6c697d46a193905fef6d003bfa0bfabfd +Subproject commit 21e2218e0ec7f4e3c0640d16bf8c67e6f0a61e18