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 | 405 |
1 files changed, 163 insertions, 242 deletions
diff --git a/runtime/queries/zig/highlights.scm b/runtime/queries/zig/highlights.scm index 07960d18..404a8682 100644 --- a/runtime/queries/zig/highlights.scm +++ b/runtime/queries/zig/highlights.scm @@ -1,290 +1,223 @@ -; Variables - -(identifier) @variable - -; Parameters - -(parameter - name: (identifier) @variable.parameter) - -(payload - (identifier) @variable.parameter) - -; Types - -(parameter - type: (identifier) @type) - -((identifier) @type - (#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 - (#match? @constant "^[A-Z][A-Z_0-9]+$")) + (container_doc_comment) + (doc_comment) + (line_comment) +] @comment [ - "null" - "unreachable" - "undefined" -] @constant.builtin - -(field_expression - . - member: (identifier) @constant) + variable: (IDENTIFIER) + variable_type_function: (IDENTIFIER) +] @variable -(enum_declaration - (container_field - type: (identifier) @constant)) +parameter: (IDENTIFIER) @variable.parameter -; Labels - -(block_label - (identifier) @label) - -(break_label - (identifier) @label) - -; Fields +[ + field_member: (IDENTIFIER) + field_access: (IDENTIFIER) +] @variable.property -(field_initializer - . - (identifier) @variable.other.member) +;; 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]+$") +) -(field_expression - (_) - member: (identifier) @variable.other.member) +[ + function_call: (IDENTIFIER) + function: (IDENTIFIER) +] @function -(field_expression - (_) - member: (identifier) @type (#match? @type "^[A-Z_][a-zA-Z0-9_]*")) +exception: "!" @function.macro -(field_expression - (_) - member: (identifier) @constant (#match? @constant "^[A-Z][A-Z_0-9]+$")) +( + (IDENTIFIER) @variable.builtin + (#eq? @variable.builtin "_") +) -(container_field - name: (identifier) @variable.other.member) +(PtrTypeStart "c" @variable.builtin) -(initializer_list - (assignment_expression - left: (field_expression - . - member: (identifier) @variable.other.member))) +( + (ContainerDeclType + [ + (ErrorUnionExpr) + "enum" + ] + ) + (ContainerField (IDENTIFIER) @constant) +) -; Functions +field_constant: (IDENTIFIER) @constant -(builtin_identifier) @function.builtin +(BUILTINIDENTIFIER) @function.builtin -(call_expression - function: (identifier) @function) +((BUILTINIDENTIFIER) @keyword.control.import + (#any-of? @keyword.control.import "@import" "@cImport")) -(call_expression - function: (field_expression - member: (identifier) @function.method)) +(INTEGER) @number -(function_declaration - name: (identifier) @function) +(FLOAT) @number -; Modules +[ + (LINESTRING) + (STRINGLITERALSINGLE) +] @string -(variable_declaration - (_) - (builtin_function - (builtin_identifier) @keyword.control.import - (#any-of? @keyword.control.import "@import" "@cImport"))) +(CHAR_LITERAL) @constant.character +(EscapeSequence) @escape +(FormatSequence) @string.special -(variable_declaration - (_) - (field_expression - object: (builtin_function - (builtin_identifier) @keyword.control.import - (#any-of? @keyword.control.import "@import" "@cImport")))) +[ + "allowzero" + "volatile" + "anytype" + "anyframe" + (BuildinTypeExpr) +] @type.builtin -; Builtins +(BreakLabel (IDENTIFIER) @label) +(BlockLabel (IDENTIFIER) @label) [ - "c" - "..." -] @variable.builtin + "true" + "false" +] @constant.builtin.boolean -((identifier) @variable.builtin - (#eq? @variable.builtin "_")) +[ + "undefined" + "unreachable" + "null" +] @constant.builtin -(calling_convention - (identifier) @variable.builtin) +[ + "else" + "if" + "switch" +] @keyword.control.conditional -; Keywords +[ + "for" + "while" +] @keyword.control.repeat [ - "asm" - "test" -] @keyword + "or" + "and" + "orelse" +] @operator [ - "error" - "const" - "var" "struct" - "union" "enum" + "union" + "error" + "packed" "opaque" -] @keyword.storage.type - -; todo: keyword.coroutine -[ - "async" - "await" - "suspend" - "nosuspend" - "resume" ] @keyword -"fn" @keyword.function - [ - "and" - "or" - "orelse" -] @keyword.operator + "try" + "error" + "catch" +] @function.macro +; VarDecl [ - "try" - "unreachable" - "return" -] @keyword.control.return + "comptime" + "threadlocal" + "fn" +] @keyword.function [ - "if" - "else" - "switch" - "catch" -] @keyword.control.conditional + "const" + "var" + "test" + "pub" + "usingnamespace" +] @keyword [ - "for" - "while" + "return" "break" "continue" -] @keyword.control.repeat - -[ - "usingnamespace" - "export" -] @keyword.control.import +] @keyword.control +; Macro [ "defer" "errdefer" -] @keyword.control.exception + "async" + "nosuspend" + "await" + "suspend" + "resume" + "export" + "extern" +] @function.macro +; PrecProc [ - "volatile" - "allowzero" - "noalias" - "addrspace" - "align" - "callconv" - "linksection" - "pub" "inline" "noinline" - "extern" - "comptime" - "packed" - "threadlocal" -] @keyword.storage.modifier + "asm" + "callconv" + "noalias" +] @keyword.directive -; Operator +[ + "linksection" + "align" +] @function.builtin [ - "=" - "*=" - "*%=" - "*|=" - "/=" - "%=" - "+=" - "+%=" - "+|=" - "-=" - "-%=" - "-|=" - "<<=" - "<<|=" - ">>=" - "&=" - "^=" - "|=" - "!" - "~" - "-" - "-%" - "&" - "==" - "!=" - ">" - ">=" - "<=" - "<" - "&" - "^" - "|" - "<<" - ">>" - "<<|" - "+" - "++" - "+%" - "-%" - "+|" - "-|" + (CompareOp) + (BitwiseOp) + (BitShiftOp) + (AdditionOp) + (MultiplyOp) + (PrefixOp) "*" - "/" - "%" "**" - "*%" - "*|" - "||" - ".*" + "->" + "=>" ".?" + ".*" + "=" "?" - ".." ] @operator -; Literals - -(character) @constant.character - [ - (string) - (multiline_string) -] @string - -(integer) @constant.numeric.integer - -(float) @constant.numeric.float - -(boolean) @constant.builtin.boolean - -(escape_sequence) @constant.character.escape + ";" + "." + "," + ":" +] @punctuation.delimiter -; Punctuation +[ + ".." + "..." +] @punctuation.special [ "[" @@ -293,22 +226,10 @@ ")" "{" "}" + (Payload "|") + (PtrPayload "|") + (PtrIndexPayload "|") ] @punctuation.bracket -[ - ";" - "." - "," - ":" - "=>" - "->" -] @punctuation.delimiter - -(payload "|" @punctuation.bracket) - -; Comments - -(comment) @comment.line - -((comment) @comment.block.documentation - (#match? @comment.block.documentation "^//!")) +; Error +(ERROR) @keyword |