Unnamed repository; edit this file 'description' to name the repository.
Diffstat (limited to 'runtime/queries/zig/highlights.scm')
| -rw-r--r-- | runtime/queries/zig/highlights.scm | 402 |
1 files changed, 232 insertions, 170 deletions
diff --git a/runtime/queries/zig/highlights.scm b/runtime/queries/zig/highlights.scm index d6b1f95a..56c33825 100644 --- a/runtime/queries/zig/highlights.scm +++ b/runtime/queries/zig/highlights.scm @@ -1,231 +1,293 @@ -[ - (container_doc_comment) - (doc_comment) -] @comment.documentation +; Comments -[ - (line_comment) -] @comment.line +((comment) @comment.block.documentation + (#match? @comment.block.documentation "^//!")) -;; 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]+$") -) +(comment) @comment.line -;; _ -( - (IDENTIFIER) @variable.builtin - (#eq? @variable.builtin "_") -) +; Punctuation -;; C Pointers [*c]T -(PtrTypeStart "c" @variable.builtin) +[ + "[" + "]" + "(" + ")" + "{" + "}" +] @punctuation.bracket [ - variable: (IDENTIFIER) - variable_type_function: (IDENTIFIER) -] @variable + ";" + "." + "," + ":" + "=>" + "->" +] @punctuation.delimiter -parameter: (IDENTIFIER) @variable.parameter +(payload "|" @punctuation.bracket) -[ - field_member: (IDENTIFIER) - field_access: (IDENTIFIER) -] @variable.other.member +; Literals + +(character) @constant.character [ - function_call: (IDENTIFIER) - function: (IDENTIFIER) -] @function + (string) + (multiline_string) +] @string -exception: "!" @keyword.control.exception +(integer) @constant.numeric.integer -field_constant: (IDENTIFIER) @constant +(float) @constant.numeric.float -(BUILTINIDENTIFIER) @function.builtin +(boolean) @constant.builtin.boolean -((BUILTINIDENTIFIER) @keyword.control.import - (#any-of? @keyword.control.import "@import" "@cImport")) +(escape_sequence) @constant.character.escape -(INTEGER) @constant.numeric.integer +; Operator -(FLOAT) @constant.numeric.float +[ + "=" + "*=" + "*%=" + "*|=" + "/=" + "%=" + "+=" + "+%=" + "+|=" + "-=" + "-%=" + "-|=" + "<<=" + "<<|=" + ">>=" + "&=" + "^=" + "|=" + "!" + "~" + "-" + "-%" + "&" + "==" + "!=" + ">" + ">=" + "<=" + "<" + "&" + "^" + "|" + "<<" + ">>" + "<<|" + "+" + "++" + "+%" + "-%" + "+|" + "-|" + "*" + "/" + "%" + "**" + "*%" + "*|" + "||" + ".*" + ".?" + "?" + ".." +] @operator + +; Keywords [ - (LINESTRING) - (STRINGLITERALSINGLE) -] @string + "asm" + "test" +] @keyword -(CHAR_LITERAL) @constant.character -(EscapeSequence) @constant.character.escape -(FormatSequence) @string.special +[ + "error" + "const" + "var" + "struct" + "union" + "enum" + "opaque" +] @keyword.storage.type +; todo: keyword.coroutine [ - "anytype" - "anyframe" - (BuildinTypeExpr) -] @type.builtin + "async" + "await" + "suspend" + "nosuspend" + "resume" +] @keyword -(BreakLabel (IDENTIFIER) @label) -(BlockLabel (IDENTIFIER) @label) +"fn" @keyword.function [ - "true" - "false" -] @constant.builtin.boolean + "and" + "or" + "orelse" +] @keyword.operator [ - "undefined" + "try" "unreachable" - "null" -] @constant.builtin + "return" +] @keyword.control.return [ - "else" "if" + "else" "switch" + "catch" ] @keyword.control.conditional [ "for" "while" + "break" + "continue" ] @keyword.control.repeat [ - "or" - "and" - "orelse" -] @keyword.operator - -[ - "enum" -] @type.enum + "usingnamespace" + "export" +] @keyword.control.import [ - "struct" - "union" - "packed" - "opaque" - "export" - "extern" - "linksection" -] @keyword.storage.type + "defer" + "errdefer" +] @keyword.control.exception [ - "const" - "var" - "threadlocal" - "allowzero" "volatile" + "allowzero" + "noalias" + "addrspace" "align" + "callconv" + "linksection" + "pub" + "inline" + "noinline" + "extern" + "comptime" + "packed" + "threadlocal" ] @keyword.storage.modifier -[ - "try" - "error" - "catch" -] @keyword.control.exception +; Builtins [ - "fn" -] @keyword.function + "c" + "..." +] @variable.builtin -[ - "test" -] @keyword +((identifier) @variable.builtin + (#eq? @variable.builtin "_")) -[ - "pub" - "usingnamespace" -] @keyword.control.import +(calling_convention + (identifier) @variable.builtin) -[ - "return" - "break" - "continue" -] @keyword.control.return +; Modules -[ - "defer" - "errdefer" - "async" - "nosuspend" - "await" - "suspend" - "resume" -] @function.macro +(variable_declaration + (identifier) @variable ; TODO: module + (builtin_function + (builtin_identifier) @keyword.control.import + (#any-of? @keyword.control.import "@import" "@cImport"))) -[ - "comptime" - "inline" - "noinline" - "asm" - "callconv" - "noalias" -] @keyword.directive +; Functions -[ - (CompareOp) - (BitwiseOp) - (BitShiftOp) - (AdditionOp) - (AssignOp) - (MultiplyOp) - (PrefixOp) - "*" - "**" - "->" - ".?" - ".*" - "?" -] @operator +(call_expression + function: (field_expression + member: (identifier) @function.method)) -[ - ";" - "." - "," - ":" -] @punctuation.delimiter +(call_expression + function: (identifier) @function) + +(function_declaration + name: (identifier) @function) + +(builtin_identifier) @function.builtin + +; Fields + +(field_initializer + . + (identifier) @variable.other.member) + +(field_expression + (_) + member: (identifier) @variable.other.member) + +(container_field + name: (identifier) @variable.other.member) + +(initializer_list + (assignment_expression + left: (field_expression + . + member: (identifier) @variable.other.member))) + +; Labels + +(block_label (identifier) @label) + +(break_label (identifier) @label) + +; Constants + +((identifier) @constant + (#match? @constant "^[A-Z][A-Z_0-9]+$")) [ - ".." - "..." -] @punctuation.special + "null" + "undefined" +] @constant.builtin + +(field_expression + . + member: (identifier) @constant) + +(enum_declaration + (container_field + type: (identifier) @constant)) + +; 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) + ]) [ - "[" - "]" - "(" - ")" - "{" - "}" - (Payload "|") - (PtrPayload "|") - (PtrIndexPayload "|") -] @punctuation.bracket + (builtin_type) + "anyframe" +] @type.builtin + +; Parameters + +(parameter + name: (identifier) @variable.parameter) + +; Variables -(ERROR) @keyword.control.exception +(identifier) @variable |