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 | 394 |
1 files changed, 154 insertions, 240 deletions
diff --git a/runtime/queries/zig/highlights.scm b/runtime/queries/zig/highlights.scm index 07960d18..e2e79518 100644 --- a/runtime/queries/zig/highlights.scm +++ b/runtime/queries/zig/highlights.scm @@ -1,290 +1,217 @@ -; 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) +] @comment.documentation [ - "null" - "unreachable" - "undefined" -] @constant.builtin - -(field_expression - . - member: (identifier) @constant) - -(enum_declaration - (container_field - type: (identifier) @constant)) - -; Labels + (line_comment) +] @comment.line -(block_label - (identifier) @label) - -(break_label - (identifier) @label) +;; 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]+$") +) -; Fields +;; _ +( + (IDENTIFIER) @variable.builtin + (#eq? @variable.builtin "_") +) -(field_initializer - . - (identifier) @variable.other.member) +;; C Pointers [*c]T +(PtrTypeStart "c" @variable.builtin) -(field_expression - (_) - member: (identifier) @variable.other.member) +[ + variable: (IDENTIFIER) + variable_type_function: (IDENTIFIER) +] @variable -(field_expression - (_) - member: (identifier) @type (#match? @type "^[A-Z_][a-zA-Z0-9_]*")) +parameter: (IDENTIFIER) @variable.parameter -(field_expression - (_) - member: (identifier) @constant (#match? @constant "^[A-Z][A-Z_0-9]+$")) +[ + field_member: (IDENTIFIER) + field_access: (IDENTIFIER) +] @variable.other.member -(container_field - name: (identifier) @variable.other.member) +[ + function_call: (IDENTIFIER) + function: (IDENTIFIER) +] @function -(initializer_list - (assignment_expression - left: (field_expression - . - member: (identifier) @variable.other.member))) +exception: "!" @keyword.control.exception -; 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) @constant.numeric.integer -(function_declaration - name: (identifier) @function) +(FLOAT) @constant.numeric.float -; 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) @constant.character.escape +(FormatSequence) @string.special -(variable_declaration - (_) - (field_expression - object: (builtin_function - (builtin_identifier) @keyword.control.import - (#any-of? @keyword.control.import "@import" "@cImport")))) +[ + "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" +] @keyword.operator [ - "error" - "const" - "var" "struct" - "union" "enum" + "union" + "packed" "opaque" + "export" + "extern" + "linksection" ] @keyword.storage.type -; todo: keyword.coroutine -[ - "async" - "await" - "suspend" - "nosuspend" - "resume" -] @keyword - -"fn" @keyword.function - [ - "and" - "or" - "orelse" -] @keyword.operator + "const" + "var" + "threadlocal" + "allowzero" + "volatile" + "align" +] @keyword.storage.modifier [ "try" - "unreachable" - "return" -] @keyword.control.return + "error" + "catch" +] @keyword.control.exception [ - "if" - "else" - "switch" - "catch" -] @keyword.control.conditional + "fn" +] @keyword.function [ - "for" - "while" - "break" - "continue" -] @keyword.control.repeat + "test" +] @keyword [ + "pub" "usingnamespace" - "export" ] @keyword.control.import [ + "return" + "break" + "continue" +] @keyword.control.return + +[ "defer" "errdefer" -] @keyword.control.exception + "async" + "nosuspend" + "await" + "suspend" + "resume" +] @function.macro [ - "volatile" - "allowzero" - "noalias" - "addrspace" - "align" - "callconv" - "linksection" - "pub" + "comptime" "inline" "noinline" - "extern" - "comptime" - "packed" - "threadlocal" -] @keyword.storage.modifier - -; Operator + "asm" + "callconv" + "noalias" +] @keyword.directive [ - "=" - "*=" - "*%=" - "*|=" - "/=" - "%=" - "+=" - "+%=" - "+|=" - "-=" - "-%=" - "-|=" - "<<=" - "<<|=" - ">>=" - "&=" - "^=" - "|=" - "!" - "~" - "-" - "-%" - "&" - "==" - "!=" - ">" - ">=" - "<=" - "<" - "&" - "^" - "|" - "<<" - ">>" - "<<|" - "+" - "++" - "+%" - "-%" - "+|" - "-|" + (CompareOp) + (BitwiseOp) + (BitShiftOp) + (AdditionOp) + (AssignOp) + (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 +220,9 @@ ")" "{" "}" + (Payload "|") + (PtrPayload "|") + (PtrIndexPayload "|") ] @punctuation.bracket -[ - ";" - "." - "," - ":" - "=>" - "->" -] @punctuation.delimiter - -(payload "|" @punctuation.bracket) - -; Comments - -(comment) @comment.line - -((comment) @comment.block.documentation - (#match? @comment.block.documentation "^//!")) +(ERROR) @keyword.control.exception |