on master help sign in
Zig tree-sitter rework (#811)
0e06c10voroskoi
helix-syntax/languages/tree-sitter-zig+1−1

Submodule changed.

runtime/queries/zig/highlights.scm+117−80
@@ -4,82 +4,89 @@
4 (line_comment)
4 (line_comment)
5] @comment
5] @comment
6
6
7−; field in top level decl, and in struct, union...
7+[
8−(ContainerField
9− (IDENTIFIER) @property
8+ variable: (IDENTIFIER)
10− (SuffixExpr (IDENTIFIER) @type)?
9+ variable_type_function: (IDENTIFIER)
11−)
10+] @variable
12
11
13−; error.OutOfMemory;
12+parameter: (IDENTIFIER) @variable.parameter
14−(SuffixExpr
13+
15− "error"
14+[
16− "."
15+ field_member: (IDENTIFIER)
16+ field_access: (IDENTIFIER)
17+] @variable.property
18+
19+;; assume TitleCase is a type
20+(
21+ [
22+ variable_type_function: (IDENTIFIER)
23+ field_access: (IDENTIFIER)
24+ parameter: (IDENTIFIER)
25+ ] @type
26+ (#match? @type "^[A-Z]([a-z]+[A-Za-z0-9]*)*$")
27+)
28+;; assume camelCase is a function
29+(
30+ [
17− (IDENTIFIER) @constant
31+ variable_type_function: (IDENTIFIER)
32+ field_access: (IDENTIFIER)
33+ parameter: (IDENTIFIER)
34+ ] @function
35+ (#match? @function "^[a-z]+([A-Z][a-z0-9]*)+$")
18)
36)
19
37
38+;; assume all CAPS_1 is a constant
39+(
40+ [
20−; var x: IDENTIFIER
41+ variable_type_function: (IDENTIFIER)
21−type: (SuffixExpr (IDENTIFIER) @type)
42+ field_access: (IDENTIFIER)
43+ ] @constant
44+ (#match? @constant "^[A-Z][A-Z_0-9]+$")
45+)
22
46
47+[
23−; IDENTIFIER{}
48+ function_call: (IDENTIFIER)
24−constructor: (SuffixExpr (IDENTIFIER) @constructor)
49+ function: (IDENTIFIER)
50+] @function
25
51
26−; fields
52+exception: "!" @function.macro
27−(FieldInit (IDENTIFIER) @property)
28
53
29−; foo.bar.baz.function() calls
30(
54(
31− (SuffixOp
32− (IDENTIFIER) @function
55+ (IDENTIFIER) @variable.builtin
33− )
56+ (#eq? @variable.builtin "_")
34− .
35− (FnCallArguments)
36)
57)
37
58
38−; function() calls
59+(PtrTypeStart "c" @variable.builtin)
60+
39(
61(
40− (
62+ (ContainerDeclType
41− (IDENTIFIER) @function
63+ [
64+ (ErrorUnionExpr)
65+ "enum"
66+ ]
42 )
67 )
43− .
68+ (ContainerField (IDENTIFIER) @constant)
44− (FnCallArguments)
45)
69)
46
70
47−; functionn decl
71+field_constant: (IDENTIFIER) @constant
48−(FnProto
49− (IDENTIFIER) @function
50− (SuffixExpr (IDENTIFIER) @type)?
51− ("!")? @function.macro
52−)
53
72
54−; function parameters and types
73+(BUILTINIDENTIFIER) @function.builtin
55−(ParamDecl
56− (IDENTIFIER) @variable.parameter
57− ":"
58− [
59− (ParamType (SuffixExpr (IDENTIFIER) @type))
60− (ParamType)
61− ]
62−)
63
74
64−; switch
75+((BUILTINIDENTIFIER) @keyword.control.import
65−(SwitchItem
76+ (#any-of? @keyword.control.import "@import" "@cImport"))
66− (SuffixExpr
67− "."
68− .
69− (IDENTIFIER) @constant
70− )
71−)
72
77
73(INTEGER) @number
78(INTEGER) @number
74
79
75(FLOAT) @number
80(FLOAT) @number
76
81
77[
82[
78− (STRINGLITERAL)
83+ (LINESTRING)
79 (STRINGLITERALSINGLE)
84 (STRINGLITERALSINGLE)
80] @string
85] @string
81
86
82−(CHAR_LITERAL) @string
87+(CHAR_LITERAL) @constant.character
88+(EscapeSequence) @escape
89+(FormatSequence) @string.special
83
90
84[
91[
85 "allowzero"
92 "allowzero"
@@ -95,6 +102,9 @@ constructor: (SuffixExpr (IDENTIFIER) @constructor)
95[
102[
96 "true"
103 "true"
97 "false"
104 "false"
105+] @constant.builtin.boolean
106+
107+[
98 "undefined"
108 "undefined"
99 "unreachable"
109 "unreachable"
100 "null"
110 "null"
@@ -104,21 +114,18 @@ constructor: (SuffixExpr (IDENTIFIER) @constructor)
104 "else"
114 "else"
105 "if"
115 "if"
106 "switch"
116 "switch"
117+] @keyword.control.conditional
118+
119+[
107 "for"
120 "for"
108 "while"
121 "while"
109− "return"
110− "break"
111− "continue"
112− "defer"
113− "errdefer"
114− "async"
115− "nosuspend"
116− "await"
117− "suspend"
118− "resume"
119− "try"
120− "catch"
121−] @keyword.control
122+] @keyword.control.repeat
123+
124+[
125+ "or"
126+ "and"
127+ "orelse"
128+] @operator
122
129
123[
130[
124 "struct"
131 "struct"
@@ -127,21 +134,48 @@ constructor: (SuffixExpr (IDENTIFIER) @constructor)
127 "error"
134 "error"
128 "packed"
135 "packed"
129 "opaque"
136 "opaque"
130− "test"
131− "usingnamespace"
132− "export"
133− "extern"
134− "const"
135− "var"
136− "comptime"
137− "threadlocal"
138] @keyword
137] @keyword
139
138
140[
139[
141− "pub"
140+ "try"
141+ "error"
142+ "catch"
143+] @function.macro
144+
145+; VarDecl
146+[
147+ "comptime"
148+ "threadlocal"
142 "fn"
149 "fn"
143] @keyword.function
150] @keyword.function
144
151
152+[
153+ "const"
154+ "var"
155+ "test"
156+ "pub"
157+ "usingnamespace"
158+] @keyword
159+
160+[
161+ "return"
162+ "break"
163+ "continue"
164+] @keyword.control
165+
166+; Macro
167+[
168+ "defer"
169+ "errdefer"
170+ "async"
171+ "nosuspend"
172+ "await"
173+ "suspend"
174+ "resume"
175+ "export"
176+ "extern"
177+] @function.macro
178+
145; PrecProc
179; PrecProc
146[
180[
147 "inline"
181 "inline"
@@ -149,10 +183,9 @@ constructor: (SuffixExpr (IDENTIFIER) @constructor)
149 "asm"
183 "asm"
150 "callconv"
184 "callconv"
151 "noalias"
185 "noalias"
152−] @attribute
186+] @keyword.directive
153
187
154[
188[
155− (BUILTINIDENTIFIER)
156 "linksection"
189 "linksection"
157 "align"
190 "align"
158] @function.builtin
191] @function.builtin
@@ -164,9 +197,6 @@ constructor: (SuffixExpr (IDENTIFIER) @constructor)
164 (AdditionOp)
197 (AdditionOp)
165 (MultiplyOp)
198 (MultiplyOp)
166 (PrefixOp)
199 (PrefixOp)
167− "or"
168− "and"
169− "orelse"
170 "*"
200 "*"
171 "**"
201 "**"
172 "->"
202 "->"
@@ -174,6 +204,7 @@ constructor: (SuffixExpr (IDENTIFIER) @constructor)
174 ".?"
204 ".?"
175 ".*"
205 ".*"
176 "="
206 "="
207+ "?"
177] @operator
208] @operator
178
209
179[
210[
@@ -186,6 +217,9 @@ constructor: (SuffixExpr (IDENTIFIER) @constructor)
186[
217[
187 ".."
218 ".."
188 "..."
219 "..."
220+] @punctuation.special
221+
222+[
189 "["
223 "["
190 "]"
224 "]"
191 "("
225 "("
@@ -195,4 +229,7 @@ constructor: (SuffixExpr (IDENTIFIER) @constructor)
195 (Payload "|")
229 (Payload "|")
196 (PtrPayload "|")
230 (PtrPayload "|")
197 (PtrIndexPayload "|")
231 (PtrIndexPayload "|")
198−] @punctuation
232+] @punctuation.bracket
233+
234+; Error
235+(ERROR) @keyword
runtime/queries/zig/indents.toml+5−4
@@ -1,8 +1,9 @@
1indent = [
1indent = [
2− "block",
2+ "Block",
3− "match_block",
3+ "BlockExpr",
4− "arguments",
4+ "ContainerDecl",
5− "parameters"
5+ "SwitchExpr",
6+ "InitList"
6]
7]
7
8
8outdent = [
9outdent = [