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.scm395
1 files changed, 156 insertions, 239 deletions
diff --git a/runtime/queries/zig/highlights.scm b/runtime/queries/zig/highlights.scm
index 07960d18..d6b1f95a 100644
--- a/runtime/queries/zig/highlights.scm
+++ b/runtime/queries/zig/highlights.scm
@@ -1,290 +1,220 @@
-; 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)
+;; 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]+$")
+)
-(break_label
- (identifier) @label)
+;; _
+(
+ (IDENTIFIER) @variable.builtin
+ (#eq? @variable.builtin "_")
+)
-; Fields
+;; C Pointers [*c]T
+(PtrTypeStart "c" @variable.builtin)
-(field_initializer
- .
- (identifier) @variable.other.member)
+[
+ variable: (IDENTIFIER)
+ variable_type_function: (IDENTIFIER)
+] @variable
-(field_expression
- (_)
- member: (identifier) @variable.other.member)
+parameter: (IDENTIFIER) @variable.parameter
-(field_expression
- (_)
- member: (identifier) @type (#match? @type "^[A-Z_][a-zA-Z0-9_]*"))
+[
+ field_member: (IDENTIFIER)
+ field_access: (IDENTIFIER)
+] @variable.other.member
-(field_expression
- (_)
- member: (identifier) @constant (#match? @constant "^[A-Z][A-Z_0-9]+$"))
+[
+ function_call: (IDENTIFIER)
+ function: (IDENTIFIER)
+] @function
-(container_field
- name: (identifier) @variable.other.member)
+exception: "!" @keyword.control.exception
-(initializer_list
- (assignment_expression
- left: (field_expression
- .
- member: (identifier) @variable.other.member)))
+field_constant: (IDENTIFIER) @constant
-; Functions
+(BUILTINIDENTIFIER) @function.builtin
-(builtin_identifier) @function.builtin
+((BUILTINIDENTIFIER) @keyword.control.import
+ (#any-of? @keyword.control.import "@import" "@cImport"))
-(call_expression
- function: (identifier) @function)
+(INTEGER) @constant.numeric.integer
-(call_expression
- function: (field_expression
- member: (identifier) @function.method))
+(FLOAT) @constant.numeric.float
-(function_declaration
- name: (identifier) @function)
+[
+ (LINESTRING)
+ (STRINGLITERALSINGLE)
+] @string
-; Modules
+(CHAR_LITERAL) @constant.character
+(EscapeSequence) @constant.character.escape
+(FormatSequence) @string.special
-(variable_declaration
- (_)
- (builtin_function
- (builtin_identifier) @keyword.control.import
- (#any-of? @keyword.control.import "@import" "@cImport")))
+[
+ "anytype"
+ "anyframe"
+ (BuildinTypeExpr)
+] @type.builtin
-(variable_declaration
- (_)
- (field_expression
- object: (builtin_function
- (builtin_identifier) @keyword.control.import
- (#any-of? @keyword.control.import "@import" "@cImport"))))
+(BreakLabel (IDENTIFIER) @label)
+(BlockLabel (IDENTIFIER) @label)
-; Builtins
+[
+ "true"
+ "false"
+] @constant.builtin.boolean
[
- "c"
- "..."
-] @variable.builtin
+ "undefined"
+ "unreachable"
+ "null"
+] @constant.builtin
-((identifier) @variable.builtin
- (#eq? @variable.builtin "_"))
+[
+ "else"
+ "if"
+ "switch"
+] @keyword.control.conditional
-(calling_convention
- (identifier) @variable.builtin)
+[
+ "for"
+ "while"
+] @keyword.control.repeat
-; Keywords
+[
+ "or"
+ "and"
+ "orelse"
+] @keyword.operator
[
- "asm"
- "test"
-] @keyword
+ "enum"
+] @type.enum
[
- "error"
- "const"
- "var"
"struct"
"union"
- "enum"
+ "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 +223,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