Skip to content

Commit 8f4cf56

Browse files
authored
fix(zig): add rule for function calls (#1075)
Adds a simple highlighting rule for function calls in Zig's lexer ## Before ![image](https://github.com/user-attachments/assets/bc9f17af-4d10-4746-9290-a614f732a134) ## After ![image](https://github.com/user-attachments/assets/f1ebf0e5-ea82-49a1-8807-fca36945f9d0)
1 parent abf98e0 commit 8f4cf56

File tree

2 files changed

+23
-20
lines changed

2 files changed

+23
-20
lines changed

lexers/embedded/zig.xml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,9 @@
7676
<rule pattern="(?:_?[0-9])+">
7777
<token type="LiteralNumberInteger"/>
7878
</rule>
79+
<rule pattern="\b[A-Za-z_]\w*(?=\s*\()">
80+
<token type="NameFunction"/>
81+
</rule>
7982
<rule pattern="@[a-zA-Z_]\w*">
8083
<token type="NameBuiltin"/>
8184
</rule>

lexers/testdata/zig.expected

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@
3636
{"type":"TextWhitespace","value":" "},
3737
{"type":"Keyword","value":"fn"},
3838
{"type":"TextWhitespace","value":" "},
39-
{"type":"Name","value":"once"},
39+
{"type":"NameFunction","value":"once"},
4040
{"type":"Punctuation","value":"("},
4141
{"type":"KeywordReserved","value":"comptime"},
4242
{"type":"TextWhitespace","value":" "},
@@ -50,7 +50,7 @@
5050
{"type":"KeywordType","value":"void"},
5151
{"type":"Punctuation","value":")"},
5252
{"type":"TextWhitespace","value":" "},
53-
{"type":"Name","value":"Once"},
53+
{"type":"NameFunction","value":"Once"},
5454
{"type":"Punctuation","value":"("},
5555
{"type":"Name","value":"f"},
5656
{"type":"Punctuation","value":")"},
@@ -59,7 +59,7 @@
5959
{"type":"TextWhitespace","value":"\n "},
6060
{"type":"Keyword","value":"return"},
6161
{"type":"TextWhitespace","value":" "},
62-
{"type":"Name","value":"Once"},
62+
{"type":"NameFunction","value":"Once"},
6363
{"type":"Punctuation","value":"("},
6464
{"type":"Name","value":"f"},
6565
{"type":"Punctuation","value":"){};"},
@@ -71,7 +71,7 @@
7171
{"type":"TextWhitespace","value":" "},
7272
{"type":"Keyword","value":"fn"},
7373
{"type":"TextWhitespace","value":" "},
74-
{"type":"Name","value":"Once"},
74+
{"type":"NameFunction","value":"Once"},
7575
{"type":"Punctuation","value":"("},
7676
{"type":"KeywordReserved","value":"comptime"},
7777
{"type":"TextWhitespace","value":" "},
@@ -118,7 +118,7 @@
118118
{"type":"Punctuation","value":"."},
119119
{"type":"Name","value":"Mutex"},
120120
{"type":"Punctuation","value":"."},
121-
{"type":"Name","value":"init"},
121+
{"type":"NameFunction","value":"init"},
122122
{"type":"Punctuation","value":"(),"},
123123
{"type":"TextWhitespace","value":"\n\n "},
124124
{"type":"CommentSingle","value":"/// Call the function `f`.\n"},
@@ -133,7 +133,7 @@
133133
{"type":"TextWhitespace","value":" "},
134134
{"type":"Keyword","value":"fn"},
135135
{"type":"TextWhitespace","value":" "},
136-
{"type":"Name","value":"call"},
136+
{"type":"NameFunction","value":"call"},
137137
{"type":"Punctuation","value":"("},
138138
{"type":"Name","value":"self"},
139139
{"type":"Operator","value":":"},
@@ -171,14 +171,14 @@
171171
{"type":"TextWhitespace","value":" "},
172172
{"type":"Name","value":"self"},
173173
{"type":"Punctuation","value":"."},
174-
{"type":"Name","value":"callSlow"},
174+
{"type":"NameFunction","value":"callSlow"},
175175
{"type":"Punctuation","value":"();"},
176176
{"type":"TextWhitespace","value":"\n "},
177177
{"type":"Punctuation","value":"}"},
178178
{"type":"TextWhitespace","value":"\n\n "},
179179
{"type":"Keyword","value":"fn"},
180180
{"type":"TextWhitespace","value":" "},
181-
{"type":"Name","value":"callSlow"},
181+
{"type":"NameFunction","value":"callSlow"},
182182
{"type":"Punctuation","value":"("},
183183
{"type":"Name","value":"self"},
184184
{"type":"Operator","value":":"},
@@ -206,14 +206,14 @@
206206
{"type":"Punctuation","value":"."},
207207
{"type":"Name","value":"mutex"},
208208
{"type":"Punctuation","value":"."},
209-
{"type":"Name","value":"acquire"},
209+
{"type":"NameFunction","value":"acquire"},
210210
{"type":"Punctuation","value":"();"},
211211
{"type":"TextWhitespace","value":"\n "},
212212
{"type":"Keyword","value":"defer"},
213213
{"type":"TextWhitespace","value":" "},
214214
{"type":"Name","value":"T"},
215215
{"type":"Punctuation","value":"."},
216-
{"type":"Name","value":"release"},
216+
{"type":"NameFunction","value":"release"},
217217
{"type":"Punctuation","value":"();"},
218218
{"type":"TextWhitespace","value":"\n\n "},
219219
{"type":"CommentSingle","value":"// The first thread to acquire the mutex gets to run the initializer\n"},
@@ -229,7 +229,7 @@
229229
{"type":"TextWhitespace","value":" "},
230230
{"type":"Punctuation","value":"{"},
231231
{"type":"TextWhitespace","value":"\n "},
232-
{"type":"Name","value":"f"},
232+
{"type":"NameFunction","value":"f"},
233233
{"type":"Punctuation","value":"();"},
234234
{"type":"TextWhitespace","value":"\n "},
235235
{"type":"NameBuiltin","value":"@atomicStore"},
@@ -276,14 +276,14 @@
276276
{"type":"TextWhitespace","value":" "},
277277
{"type":"Operator","value":"="},
278278
{"type":"TextWhitespace","value":" "},
279-
{"type":"Name","value":"once"},
279+
{"type":"NameFunction","value":"once"},
280280
{"type":"Punctuation","value":"("},
281281
{"type":"Name","value":"incr"},
282282
{"type":"Punctuation","value":");"},
283283
{"type":"TextWhitespace","value":"\n\n"},
284284
{"type":"Keyword","value":"fn"},
285285
{"type":"TextWhitespace","value":" "},
286-
{"type":"Name","value":"incr"},
286+
{"type":"NameFunction","value":"incr"},
287287
{"type":"Punctuation","value":"()"},
288288
{"type":"TextWhitespace","value":" "},
289289
{"type":"KeywordType","value":"void"},
@@ -317,12 +317,12 @@
317317
{"type":"TextWhitespace","value":"\n "},
318318
{"type":"Name","value":"global_once"},
319319
{"type":"Punctuation","value":"."},
320-
{"type":"Name","value":"call"},
320+
{"type":"NameFunction","value":"call"},
321321
{"type":"Punctuation","value":"();"},
322322
{"type":"TextWhitespace","value":"\n "},
323323
{"type":"Name","value":"global_once"},
324324
{"type":"Punctuation","value":"."},
325-
{"type":"Name","value":"call"},
325+
{"type":"NameFunction","value":"call"},
326326
{"type":"Punctuation","value":"();"},
327327
{"type":"TextWhitespace","value":"\n "},
328328
{"type":"Punctuation","value":"}"},
@@ -363,7 +363,7 @@
363363
{"type":"TextWhitespace","value":" "},
364364
{"type":"Name","value":"handle"},
365365
{"type":"Punctuation","value":"."},
366-
{"type":"Name","value":"wait"},
366+
{"type":"NameFunction","value":"wait"},
367367
{"type":"Punctuation","value":"();"},
368368
{"type":"TextWhitespace","value":"\n\n "},
369369
{"type":"Keyword","value":"for"},
@@ -390,7 +390,7 @@
390390
{"type":"Punctuation","value":"."},
391391
{"type":"Name","value":"Thread"},
392392
{"type":"Punctuation","value":"."},
393-
{"type":"Name","value":"spawn"},
393+
{"type":"NameFunction","value":"spawn"},
394394
{"type":"Punctuation","value":"("},
395395
{"type":"NameBuiltin","value":"@as"},
396396
{"type":"Punctuation","value":"("},
@@ -406,7 +406,7 @@
406406
{"type":"TextWhitespace","value":"\n "},
407407
{"type":"Keyword","value":"fn"},
408408
{"type":"TextWhitespace","value":" "},
409-
{"type":"Name","value":"thread_fn"},
409+
{"type":"NameFunction","value":"thread_fn"},
410410
{"type":"Punctuation","value":"("},
411411
{"type":"Name","value":"x"},
412412
{"type":"Operator","value":":"},
@@ -420,7 +420,7 @@
420420
{"type":"TextWhitespace","value":"\n "},
421421
{"type":"Name","value":"global_once"},
422422
{"type":"Punctuation","value":"."},
423-
{"type":"Name","value":"call"},
423+
{"type":"NameFunction","value":"call"},
424424
{"type":"Punctuation","value":"();"},
425425
{"type":"TextWhitespace","value":"\n "},
426426
{"type":"Punctuation","value":"}"},
@@ -435,7 +435,7 @@
435435
{"type":"TextWhitespace","value":"\n\n "},
436436
{"type":"Name","value":"testing"},
437437
{"type":"Punctuation","value":"."},
438-
{"type":"Name","value":"expectEqual"},
438+
{"type":"NameFunction","value":"expectEqual"},
439439
{"type":"Punctuation","value":"("},
440440
{"type":"NameBuiltin","value":"@as"},
441441
{"type":"Punctuation","value":"("},

0 commit comments

Comments
 (0)