Skip to content

Commit 8c24f02

Browse files
authored
feat: Add highlights.scm for Zig (#444)
* feat: Add highlights.scm for Zig * chore: Chnagelog
1 parent 55d095e commit 8c24f02

File tree

2 files changed

+229
-0
lines changed

2 files changed

+229
-0
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
# Changelog
22

33
## Unreleased
4+
- Add `highlights.scm` for `Zig`
45

56
## 0.12.149 - 2024-03-03
67

queries/zig/highlights.scm

Lines changed: 228 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,228 @@
1+
(line_comment) @comment @spell
2+
3+
[
4+
(container_doc_comment)
5+
(doc_comment)
6+
] @doc @spell
7+
8+
;; [
9+
;; variable: (IDENTIFIER)
10+
;; variable_type_function: (IDENTIFIER)
11+
;; ] @variable
12+
13+
parameter: (IDENTIFIER) @parameter
14+
15+
[
16+
field_member: (IDENTIFIER)
17+
field_access: (IDENTIFIER)
18+
] @field
19+
20+
;; assume TitleCase is a type
21+
(
22+
[
23+
variable_type_function: (IDENTIFIER)
24+
field_access: (IDENTIFIER)
25+
parameter: (IDENTIFIER)
26+
] @type
27+
(#match? @type "^[A-Z]([a-z]+[A-Za-z0-9]*)*$")
28+
)
29+
30+
;; assume camelCase is a function
31+
(
32+
[
33+
variable_type_function: (IDENTIFIER)
34+
field_access: (IDENTIFIER)
35+
parameter: (IDENTIFIER)
36+
] @function
37+
(#match? @function "^[a-z]+([A-Z][a-z0-9]*)+$")
38+
)
39+
40+
;; assume all CAPS_1 is a constant
41+
(
42+
[
43+
variable_type_function: (IDENTIFIER)
44+
field_access: (IDENTIFIER)
45+
] @constant
46+
(#match? @constant "^[A-Z][A-Z_0-9]+$")
47+
)
48+
49+
function: (IDENTIFIER) @function
50+
51+
function_call: (IDENTIFIER) @function.call
52+
53+
exception: "!" @punctuation
54+
55+
((IDENTIFIER) @variable.builtin
56+
(#eq? @variable.builtin "_"))
57+
58+
(PtrTypeStart "c" @variable.builtin)
59+
60+
((ContainerDeclType
61+
[
62+
(ErrorUnionExpr)
63+
"enum"
64+
])
65+
(ContainerField (IDENTIFIER) @constant))
66+
67+
field_constant: (IDENTIFIER) @constant
68+
69+
(BUILTINIDENTIFIER) @function.builtin
70+
71+
((BUILTINIDENTIFIER) @include
72+
(#any-of? @include "@import" "@cImport"))
73+
74+
(INTEGER) @number
75+
(FLOAT) @number
76+
77+
[
78+
"true"
79+
"false"
80+
] @boolean
81+
82+
[
83+
(LINESTRING)
84+
(STRINGLITERALSINGLE)
85+
] @string @spell
86+
87+
(CHAR_LITERAL) @string
88+
(EscapeSequence) @string.escape
89+
(FormatSequence) @string.special
90+
91+
(BreakLabel (IDENTIFIER) @label)
92+
(BlockLabel (IDENTIFIER) @label)
93+
94+
[
95+
"asm"
96+
"defer"
97+
"errdefer"
98+
"test"
99+
"struct"
100+
"union"
101+
"enum"
102+
"opaque"
103+
"error"
104+
] @keyword
105+
106+
[
107+
"async"
108+
"await"
109+
"suspend"
110+
"nosuspend"
111+
"resume"
112+
] @keyword
113+
114+
[
115+
"fn"
116+
] @keyword
117+
118+
[
119+
"and"
120+
"or"
121+
"orelse"
122+
] @keyword
123+
124+
[
125+
"return"
126+
] @keyword
127+
128+
[
129+
"if"
130+
"else"
131+
"switch"
132+
] @conditional
133+
134+
[
135+
"for"
136+
"while"
137+
"break"
138+
"continue"
139+
] @repeat
140+
141+
[
142+
"usingnamespace"
143+
] @include
144+
145+
[
146+
"try"
147+
"catch"
148+
] @exception
149+
150+
[
151+
"anytype"
152+
(BuildinTypeExpr)
153+
] @keyword
154+
155+
[
156+
"const"
157+
"var"
158+
"volatile"
159+
"allowzero"
160+
"noalias"
161+
] @keyword
162+
163+
[
164+
"addrspace"
165+
"align"
166+
"callconv"
167+
"linksection"
168+
] @keyword
169+
170+
[
171+
"comptime"
172+
"export"
173+
"extern"
174+
"inline"
175+
"noinline"
176+
"packed"
177+
"pub"
178+
"threadlocal"
179+
] @keyword
180+
181+
[
182+
"null"
183+
"unreachable"
184+
"undefined"
185+
] @constant.builtin
186+
187+
[
188+
(CompareOp)
189+
(BitwiseOp)
190+
(BitShiftOp)
191+
(AdditionOp)
192+
(AssignOp)
193+
(MultiplyOp)
194+
(PrefixOp)
195+
"*"
196+
"**"
197+
"->"
198+
".?"
199+
".*"
200+
"?"
201+
] @operator
202+
203+
[
204+
";"
205+
"."
206+
","
207+
":"
208+
] @punctuation.delimiter
209+
210+
[
211+
".."
212+
"..."
213+
] @punctuation.special
214+
215+
[
216+
"["
217+
"]"
218+
"("
219+
")"
220+
"{"
221+
"}"
222+
(Payload "|")
223+
(PtrPayload "|")
224+
(PtrIndexPayload "|")
225+
] @punctuation.bracket
226+
227+
;; Error
228+
(ERROR) @error

0 commit comments

Comments
 (0)