Skip to content

Commit 24b3bb1

Browse files
committed
update zig grammar and highlight rules
1 parent ee94031 commit 24b3bb1

File tree

2 files changed

+46
-53
lines changed

2 files changed

+46
-53
lines changed

languages.toml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -735,10 +735,9 @@ language-server = { command = "zls" }
735735
indent = { tab-width = 4, unit = " " }
736736
formatter = { command = "zig" , args = ["fmt", "--stdin"] }
737737

738-
739738
[[grammar]]
740739
name = "zig"
741-
source = { git = "https://github.com/maxxnino/tree-sitter-zig", rev = "93331b8bd8b4ebee2b575490b2758f16ad4e9f30" }
740+
source = { git = "https://github.com/maxxnino/tree-sitter-zig", rev = "8d3224c3bd0890fe08358886ebf54fca2ed448a6" }
742741

743742
[[language]]
744743
name = "prolog"

runtime/queries/zig/highlights.scm

Lines changed: 45 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,11 @@
11
[
22
(container_doc_comment)
33
(doc_comment)
4-
(line_comment)
5-
] @comment
4+
] @comment.documentation
65

76
[
8-
variable: (IDENTIFIER)
9-
variable_type_function: (IDENTIFIER)
10-
] @variable
11-
12-
parameter: (IDENTIFIER) @variable.parameter
13-
14-
[
15-
field_member: (IDENTIFIER)
16-
field_access: (IDENTIFIER)
17-
] @variable.other.member
7+
(line_comment)
8+
] @comment.line
189

1910
;; assume TitleCase is a type
2011
(
@@ -25,6 +16,7 @@ parameter: (IDENTIFIER) @variable.parameter
2516
] @type
2617
(#match? @type "^[A-Z]([a-z]+[A-Za-z0-9]*)*$")
2718
)
19+
2820
;; assume camelCase is a function
2921
(
3022
[
@@ -44,29 +36,33 @@ parameter: (IDENTIFIER) @variable.parameter
4436
(#match? @constant "^[A-Z][A-Z_0-9]+$")
4537
)
4638

47-
[
48-
function_call: (IDENTIFIER)
49-
function: (IDENTIFIER)
50-
] @function
51-
52-
exception: "!" @function.macro
53-
39+
;; _
5440
(
5541
(IDENTIFIER) @variable.builtin
5642
(#eq? @variable.builtin "_")
5743
)
5844

45+
;; C Pointers [*c]T
5946
(PtrTypeStart "c" @variable.builtin)
6047

61-
(
62-
(ContainerDeclType
63-
[
64-
(ErrorUnionExpr)
65-
"enum"
66-
]
67-
)
68-
(ContainerField (IDENTIFIER) @constant)
69-
)
48+
[
49+
variable: (IDENTIFIER)
50+
variable_type_function: (IDENTIFIER)
51+
] @variable
52+
53+
parameter: (IDENTIFIER) @variable.parameter
54+
55+
[
56+
field_member: (IDENTIFIER)
57+
field_access: (IDENTIFIER)
58+
] @variable.other.member
59+
60+
[
61+
function_call: (IDENTIFIER)
62+
function: (IDENTIFIER)
63+
] @function
64+
65+
exception: "!" @keyword.control.exception
7066

7167
field_constant: (IDENTIFIER) @constant
7268

@@ -89,8 +85,6 @@ field_constant: (IDENTIFIER) @constant
8985
(FormatSequence) @string.special
9086

9187
[
92-
"allowzero"
93-
"volatile"
9488
"anytype"
9589
"anyframe"
9690
(BuildinTypeExpr)
@@ -125,44 +119,53 @@ field_constant: (IDENTIFIER) @constant
125119
"or"
126120
"and"
127121
"orelse"
128-
] @operator
122+
] @keyword.operator
129123

130124
[
131125
"struct"
132126
"enum"
133127
"union"
134-
"error"
135128
"packed"
136129
"opaque"
137-
] @keyword
130+
"export"
131+
"extern"
132+
"linksection"
133+
] @keyword.storage.type
134+
135+
[
136+
"const"
137+
"var"
138+
"threadlocal"
139+
"allowzero"
140+
"volatile"
141+
"align"
142+
] @keyword.storage.modifier
138143

139144
[
140145
"try"
141146
"error"
142147
"catch"
143-
] @function.macro
148+
] @keyword.control.exception
144149

145-
; VarDecl
146150
[
147-
"threadlocal"
148151
"fn"
149152
] @keyword.function
150153

151154
[
152-
"const"
153-
"var"
154155
"test"
156+
] @keyword
157+
158+
[
155159
"pub"
156160
"usingnamespace"
157-
] @keyword
161+
] @namespace
158162

159163
[
160164
"return"
161165
"break"
162166
"continue"
163-
] @keyword.control
167+
] @keyword.control.return
164168

165-
; Macro
166169
[
167170
"defer"
168171
"errdefer"
@@ -171,11 +174,8 @@ field_constant: (IDENTIFIER) @constant
171174
"await"
172175
"suspend"
173176
"resume"
174-
"export"
175-
"extern"
176177
] @function.macro
177178

178-
; PrecProc
179179
[
180180
"comptime"
181181
"inline"
@@ -185,11 +185,6 @@ field_constant: (IDENTIFIER) @constant
185185
"noalias"
186186
] @keyword.directive
187187

188-
[
189-
"linksection"
190-
"align"
191-
] @function.builtin
192-
193188
[
194189
(CompareOp)
195190
(BitwiseOp)
@@ -230,5 +225,4 @@ field_constant: (IDENTIFIER) @constant
230225
(PtrIndexPayload "|")
231226
] @punctuation.bracket
232227

233-
; Error
234-
(ERROR) @keyword
228+
(ERROR) @keyword.control.exception

0 commit comments

Comments
 (0)