Zig tree-sitter rework (#811)

- update tree-sitter-zig subproject
- use highlights.scm from upstream, just use helix scopes
- update indents.toml, this one actually works
This commit is contained in:
voroskoi 2021-10-05 05:18:15 +02:00 committed by GitHub
parent c4ae17dfd4
commit 0e06c10d8c
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 130 additions and 92 deletions

@ -1 +1 @@
Subproject commit 049162bea8a44e1a4acd01b06e1c8672d9231a86 Subproject commit 1f27fd1dfe7f352408f01b4894c7825f3a1d6c47

View file

@ -4,82 +4,89 @@
(line_comment) (line_comment)
] @comment ] @comment
; field in top level decl, and in struct, union...
(ContainerField
(IDENTIFIER) @property
(SuffixExpr (IDENTIFIER) @type)?
)
; error.OutOfMemory;
(SuffixExpr
"error"
"."
(IDENTIFIER) @constant
)
; var x: IDENTIFIER
type: (SuffixExpr (IDENTIFIER) @type)
; IDENTIFIER{}
constructor: (SuffixExpr (IDENTIFIER) @constructor)
; fields
(FieldInit (IDENTIFIER) @property)
; foo.bar.baz.function() calls
(
(SuffixOp
(IDENTIFIER) @function
)
.
(FnCallArguments)
)
; function() calls
(
(
(IDENTIFIER) @function
)
.
(FnCallArguments)
)
; functionn decl
(FnProto
(IDENTIFIER) @function
(SuffixExpr (IDENTIFIER) @type)?
("!")? @function.macro
)
; function parameters and types
(ParamDecl
(IDENTIFIER) @variable.parameter
":"
[ [
(ParamType (SuffixExpr (IDENTIFIER) @type)) variable: (IDENTIFIER)
(ParamType) variable_type_function: (IDENTIFIER)
] @variable
parameter: (IDENTIFIER) @variable.parameter
[
field_member: (IDENTIFIER)
field_access: (IDENTIFIER)
] @variable.property
;; 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_call: (IDENTIFIER)
function: (IDENTIFIER)
] @function
exception: "!" @function.macro
(
(IDENTIFIER) @variable.builtin
(#eq? @variable.builtin "_")
)
(PtrTypeStart "c" @variable.builtin)
(
(ContainerDeclType
[
(ErrorUnionExpr)
"enum"
] ]
) )
(ContainerField (IDENTIFIER) @constant)
)
; switch field_constant: (IDENTIFIER) @constant
(SwitchItem
(SuffixExpr (BUILTINIDENTIFIER) @function.builtin
"."
. ((BUILTINIDENTIFIER) @keyword.control.import
(IDENTIFIER) @constant (#any-of? @keyword.control.import "@import" "@cImport"))
)
)
(INTEGER) @number (INTEGER) @number
(FLOAT) @number (FLOAT) @number
[ [
(STRINGLITERAL) (LINESTRING)
(STRINGLITERALSINGLE) (STRINGLITERALSINGLE)
] @string ] @string
(CHAR_LITERAL) @string (CHAR_LITERAL) @constant.character
(EscapeSequence) @escape
(FormatSequence) @string.special
[ [
"allowzero" "allowzero"
@ -95,6 +102,9 @@ constructor: (SuffixExpr (IDENTIFIER) @constructor)
[ [
"true" "true"
"false" "false"
] @constant.builtin.boolean
[
"undefined" "undefined"
"unreachable" "unreachable"
"null" "null"
@ -104,21 +114,18 @@ constructor: (SuffixExpr (IDENTIFIER) @constructor)
"else" "else"
"if" "if"
"switch" "switch"
] @keyword.control.conditional
[
"for" "for"
"while" "while"
"return" ] @keyword.control.repeat
"break"
"continue" [
"defer" "or"
"errdefer" "and"
"async" "orelse"
"nosuspend" ] @operator
"await"
"suspend"
"resume"
"try"
"catch"
] @keyword.control
[ [
"struct" "struct"
@ -127,21 +134,48 @@ constructor: (SuffixExpr (IDENTIFIER) @constructor)
"error" "error"
"packed" "packed"
"opaque" "opaque"
"test"
"usingnamespace"
"export"
"extern"
"const"
"var"
"comptime"
"threadlocal"
] @keyword ] @keyword
[ [
"pub" "try"
"error"
"catch"
] @function.macro
; VarDecl
[
"comptime"
"threadlocal"
"fn" "fn"
] @keyword.function ] @keyword.function
[
"const"
"var"
"test"
"pub"
"usingnamespace"
] @keyword
[
"return"
"break"
"continue"
] @keyword.control
; Macro
[
"defer"
"errdefer"
"async"
"nosuspend"
"await"
"suspend"
"resume"
"export"
"extern"
] @function.macro
; PrecProc ; PrecProc
[ [
"inline" "inline"
@ -149,10 +183,9 @@ constructor: (SuffixExpr (IDENTIFIER) @constructor)
"asm" "asm"
"callconv" "callconv"
"noalias" "noalias"
] @attribute ] @keyword.directive
[ [
(BUILTINIDENTIFIER)
"linksection" "linksection"
"align" "align"
] @function.builtin ] @function.builtin
@ -164,9 +197,6 @@ constructor: (SuffixExpr (IDENTIFIER) @constructor)
(AdditionOp) (AdditionOp)
(MultiplyOp) (MultiplyOp)
(PrefixOp) (PrefixOp)
"or"
"and"
"orelse"
"*" "*"
"**" "**"
"->" "->"
@ -174,6 +204,7 @@ constructor: (SuffixExpr (IDENTIFIER) @constructor)
".?" ".?"
".*" ".*"
"=" "="
"?"
] @operator ] @operator
[ [
@ -186,6 +217,9 @@ constructor: (SuffixExpr (IDENTIFIER) @constructor)
[ [
".." ".."
"..." "..."
] @punctuation.special
[
"[" "["
"]" "]"
"(" "("
@ -195,4 +229,7 @@ constructor: (SuffixExpr (IDENTIFIER) @constructor)
(Payload "|") (Payload "|")
(PtrPayload "|") (PtrPayload "|")
(PtrIndexPayload "|") (PtrIndexPayload "|")
] @punctuation ] @punctuation.bracket
; Error
(ERROR) @keyword

View file

@ -1,8 +1,9 @@
indent = [ indent = [
"block", "Block",
"match_block", "BlockExpr",
"arguments", "ContainerDecl",
"parameters" "SwitchExpr",
"InitList"
] ]
outdent = [ outdent = [