@@ -4,82 +4,89 @@
44 (line_comment)
55] @comment
66
7−; field in top level decl, and in struct, union...
8−(ContainerField
9− (IDENTIFIER) @property
10− (SuffixExpr (IDENTIFIER) @type)?
11−)
7+[
8+ variable: (IDENTIFIER)
9+ variable_type_function: (IDENTIFIER)
10+] @variable
1211
13−; error.OutOfMemory;
14−(SuffixExpr
15− "error"
16− "."
17− (IDENTIFIER) @constant
12+parameter: (IDENTIFIER) @variable.parameter
13+
14+[
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+ [
31+ variable_type_function: (IDENTIFIER)
32+ field_access: (IDENTIFIER)
33+ parameter: (IDENTIFIER)
34+ ] @function
35+ (#match? @function "^[a-z]+([A-Z][a-z0-9]*)+$")
1836)
1937
20−; var x: IDENTIFIER
21−type: (SuffixExpr (IDENTIFIER) @type)
38+;; assume all CAPS_1 is a constant
39+(
40+ [
41+ variable_type_function: (IDENTIFIER)
42+ field_access: (IDENTIFIER)
43+ ] @constant
44+ (#match? @constant "^[A-Z][A-Z_0-9]+$")
45+)
2246
23−; IDENTIFIER{}
24−constructor: (SuffixExpr (IDENTIFIER) @constructor)
47+[
48+ function_call: (IDENTIFIER)
49+ function: (IDENTIFIER)
50+] @function
2551
26−; fields
27−(FieldInit (IDENTIFIER) @property)
52+exception: "!" @function.macro
2853
29−; foo.bar.baz.function() calls
3054(
31− (SuffixOp
32− (IDENTIFIER) @function
33− )
34− .
35− (FnCallArguments)
55+ (IDENTIFIER) @variable.builtin
56+ (#eq? @variable.builtin "_")
3657)
3758
38−; function() calls
59+(PtrTypeStart "c" @variable.builtin)
60+
3961(
40− (
41− (IDENTIFIER) @function
62+ (ContainerDeclType
63+ [
64+ (ErrorUnionExpr)
65+ "enum"
66+ ]
4267 )
43− .
44− (FnCallArguments)
68+ (ContainerField (IDENTIFIER) @constant)
4569)
4670
47−; functionn decl
48−(FnProto
49− (IDENTIFIER) @function
50− (SuffixExpr (IDENTIFIER) @type)?
51− ("!")? @function.macro
52−)
71+field_constant: (IDENTIFIER) @constant
5372
54−; function parameters and types
55−(ParamDecl
56− (IDENTIFIER) @variable.parameter
57− ":"
58− [
59− (ParamType (SuffixExpr (IDENTIFIER) @type))
60− (ParamType)
61− ]
62−)
73+(BUILTINIDENTIFIER) @function.builtin
6374
64−; switch
65−(SwitchItem
66− (SuffixExpr
67− "."
68− .
69− (IDENTIFIER) @constant
70− )
71−)
75+((BUILTINIDENTIFIER) @keyword.control.import
76+ (#any-of? @keyword.control.import "@import" "@cImport"))
7277
7378(INTEGER) @number
7479
7580(FLOAT) @number
7681
7782[
78− (STRINGLITERAL)
83+ (LINESTRING)
7984 (STRINGLITERALSINGLE)
8085] @string
8186
82−(CHAR_LITERAL) @string
87+(CHAR_LITERAL) @constant.character
88+(EscapeSequence) @escape
89+(FormatSequence) @string.special
8390
8491[
8592 "allowzero"
@@ -95,6 +102,9 @@ constructor: (SuffixExpr (IDENTIFIER) @constructor)
95102[
96103 "true"
97104 "false"
105+] @constant.builtin.boolean
106+
107+[
98108 "undefined"
99109 "unreachable"
100110 "null"
@@ -104,21 +114,18 @@ constructor: (SuffixExpr (IDENTIFIER) @constructor)
104114 "else"
105115 "if"
106116 "switch"
117+] @keyword.control.conditional
118+
119+[
107120 "for"
108121 "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
122129
123130[
124131 "struct"
@@ -127,21 +134,48 @@ constructor: (SuffixExpr (IDENTIFIER) @constructor)
127134 "error"
128135 "packed"
129136 "opaque"
130− "test"
131− "usingnamespace"
132− "export"
133− "extern"
134− "const"
135− "var"
136− "comptime"
137− "threadlocal"
138137] @keyword
139138
140139[
141− "pub"
140+ "try"
141+ "error"
142+ "catch"
143+] @function.macro
144+
145+; VarDecl
146+[
147+ "comptime"
148+ "threadlocal"
142149 "fn"
143150] @keyword.function
144151
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+
145179; PrecProc
146180[
147181 "inline"
@@ -149,10 +183,9 @@ constructor: (SuffixExpr (IDENTIFIER) @constructor)
149183 "asm"
150184 "callconv"
151185 "noalias"
152−] @attribute
186+] @keyword.directive
153187
154188[
155− (BUILTINIDENTIFIER)
156189 "linksection"
157190 "align"
158191] @function.builtin
@@ -164,9 +197,6 @@ constructor: (SuffixExpr (IDENTIFIER) @constructor)
164197 (AdditionOp)
165198 (MultiplyOp)
166199 (PrefixOp)
167− "or"
168− "and"
169− "orelse"
170200 "*"
171201 "**"
172202 "->"
@@ -174,6 +204,7 @@ constructor: (SuffixExpr (IDENTIFIER) @constructor)
174204 ".?"
175205 ".*"
176206 "="
207+ "?"
177208] @operator
178209
179210[
@@ -186,6 +217,9 @@ constructor: (SuffixExpr (IDENTIFIER) @constructor)
186217[
187218 ".."
188219 "..."
220+] @punctuation.special
221+
222+[
189223 "["
190224 "]"
191225 "("
@@ -195,4 +229,7 @@ constructor: (SuffixExpr (IDENTIFIER) @constructor)
195229 (Payload "|")
196230 (PtrPayload "|")
197231 (PtrIndexPayload "|")
198−] @punctuation
232+] @punctuation.bracket
233+
234+; Error
235+(ERROR) @keyword