forked from ziglang/sublime-zig-language
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathsyntax_test.zig
547 lines (448 loc) · 13.7 KB
/
syntax_test.zig
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
// SYNTAX TEST "Packages/Zig Language/Syntaxes/Zig.sublime-syntax"
// this is a syntactically meaningless collection of sample
// keywords and constructs to use in testing.
const std = @import("std");
//^^^ storage.modifier.foo
// ^ keyword.operator.assignment.zig
// ^^^^^^^ keyword.control.import.zig
// ^ punctuation.section.parens.begin.zig
// ^^^^^ string.quoted.double.zig
// ^ punctuation.section.parens.end.zig
// ^ punctuation.terminator.zig
pub fn main() !void {
//^ storage.modifier.zig
// ^^ keyword.declaration.function.zig
// ^^^^ entity.name.function
// ^ punctuation.section.parens.begin.zig
// ^ punctuation.section.parens.end.zig
// ^ keyword.operator.zig
// ^^^^ storage.type.zig
// ^ punctuation.section.braces.begin.zig
// If this program is run without stdout attached, exit with an error.
// ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ comment.line.zig
const stdout_file = std.io.getStdOut();
// ^^^^^ storage.modifier.zig
// ^ keyword.operator.assignment.zig
// ^^^^^^^^^ variable.function.zig
// ^ punctuation.section.parens.begin.zig
// ^ punctuation.section.parens.end.zig
// ^ punctuation.terminator.zig
try stdout_file.writeAll("Hello, world!\n");
// ^^^ keyword.control.conditional.zig
// ^^^^^^^^ variable.function.zig
// ^ punctuation.section.parens.begin.zig
// ^^^^^^^^^^^^^^^^^ string.quoted.double.zig
// ^^ constant.character.escape.newline.zig
// ^ punctuation.section.parens.end.zig
}
const var extern packed export pub noalias inline comptime nakedcc stdcallcc volatile align linksection threadlocal
const as = 2;
// <- storage.modifier.zig
// ^ constant.numeric.integer.zig
// ^ punctuation.terminator.zig
union
struct
enum
error
asd {
.asd = asd,
}
fn dump(
// ^^ keyword.declaration.function.zig
// ^^^^ entity.name.function
// ^ punctuation.section.parens.begin.zig
value: var.asda.ad.asd,
// ^^^^^ variable.parameter.zig
// ^ punctuation.separator.zig
// ^^^^^^^^^^^^^^^ storage.type.zig
// NYI some arg
asdasd: Baddad
) void {
// <- punctuation.section.parens.end.zig
// ^^^ storage.type.zig
// ^ punctuation.section.braces.begin.zig
}
// <- punctuation.section.braces.end.zig
"for"
// ^^^^^ string.quoted.double.zig
break return continue asm defer errdefer unreachable
if else switch and or try catch orelse
async await suspend resume cancel noasync
while for
null undefined
fn usingnamespace test
bool f16 f32 f64 f128 void noreturn type anyerror anytype
promise anyframe
i2 u2 i3 u3 i4 u4 i5 u5 i6 u6 i7 u7 i8 u8 i16 u16 u29 i29 i32 u32 i64 u64 i128 u128 isize usize
.i368 .i686 .i23
c_short c_ushort c_int c_uint c_long c_ulong c_longlong c_ulonglong c_longdouble c_void
true false
a + b
//^ keyword.operator.arithmetic.zig
a += b
//^^ keyword.operator.assignment.zig
a +% b
//^^ keyword.operator.arithmetic.zig
a +%= b
//^^^ keyword.operator.assignment.zig
a - b
//^ keyword.operator.arithmetic.zig
a -= b
//^^ keyword.operator.assignment.zig
a -% b
a -%= b
-a
-%a
a * b
a *= b
a *% b
a *%= b
a / b
a /= b
a % b
a %= b
a << b
//^^ keyword.operator.logical.zig
a <<= b
//^^^ keyword.operator.assignment.zig
a & b
a &= b
//^^ keyword.operator.assignment.zig
a | b
a |= b
a ^ b
a ^= b
~a
a orelse b
a.?
a catch b
a catch |err| b
a and b
a or b
!a
a == b
a == null
a != b
a > b
a >= b
a < b
a <= b
a ++ b
a ** b
a.*
&a
a || b
test "tests" {
// ^^^^ keyword.declaration.test.zig
// ^^^^^^^^^^^^ entity.name.function.test.zig
// ^ punctuation.section.braces.begin.zig
}
// ^ punctuation.section.braces.end.zig
test "numbers" {
123
// ^^^ constant.numeric.integer.zig
123.123
// ^^^^^^^ constant.numeric.float.zig
123.123e123
// ^^^^^^^^^^^ constant.numeric.float.zig
123.123E123
// ^^^^^^^^^^^ constant.numeric.float.zig
1e3
// ^^^ constant.numeric.float.zig
0x123
// ^^^^^ constant.numeric.integer.hexadecimal.zig
0x123.123
// ^^^^^^^^^ constant.numeric.float.hexadecimal.zig
0x123.123p123
// ^^^^^^^^^^^^^ constant.numeric.float.hexadecimal.zig
0o123
// ^^^^^ constant.numeric.integer.octal.zig
0b1
// ^^^ constant.numeric.integer.binary.zig
1_234_567;
// ^^^^^^^^^ constant.numeric.integer.zig
0xff00_00ff;
// ^^^^^^^^^^^ constant.numeric.integer.hexadecimal.zig
0b10000000_10101010;
0b1000_0000_1010_1010;
0x123_190.109_038_018p102;
// ^^^^^^^^^^^^^^^^^^^^^^^^^ constant.numeric.float.hexadecimal.zig
3.14159_26535_89793;
// ^^^^^^^^^^^^^^^^^^^ constant.numeric.float.zig
123.i812;
// ^^^^^^^^ -constant.numeric
a.111;
var x: i123 = 0x7A;
// ^^^^ storage.type.zig
var x: usize = 0x7A;
// ^^^^^ storage.type.zig
}
slice[0..2]
// ^^ keyword.operator.other.zig
/// TODO blah blah
// ^^^^^^^^^^^^^^^ comment.line.documentation.zig
// TODO blah blah
// ^^^^^^^^^^^^^^^ comment.line.todo.zig
"adsfjioasdjfoiad"
c"adsfjioasdjfoiad"
// <- string.quoted.double.zig
// ^^^^^^^^^^^^^^^^ string.quoted.double.zig
'\a'
// ^^^^ string.quoted.single.zig
// ^^ string.quoted.single.zig invalid.illegal.character.zig
const \\ adsjfaf23n9
// <- storage.modifier.zig
// ^^^^^^^^^^^^^^^ string.quoted.other.zig
"ad//sd"
// ^^^^^ string.quoted.double.zig -comment
const v = fn(aas, 2342, 23) as;
fn foo(a:as) i32 {
// <- keyword.declaration.function.zig
// ^^^ entity.name.function
// ^ punctuation.section.parens.begin.zig
// ^ variable.parameter.zig
// ^ punctuation.separator.zig
// ^^ storage.type.zig
// ^ punctuation.section.parens.end.zig
// ^^^ storage.type.zig
// ^ punctuation.section.braces.begin.zig
}
// <- punctuation.section.braces.end.zig
fn foo() A![]Foo {
// ^ storage.type.zig
// ^ keyword.operator.zig
// ^^^ storage.type.zig
}
extern fn bar() as as void;
extern fn foobar() void;
errdefer |err| std.debug.assert(err == error.Overflow);
// <- keyword.control.zig
// ^ keyword.operator.bitwise.zig
// ^ keyword.operator.bitwise.zig
// ^ punctuation.section.parens.begin.zig
// ^^ keyword.operator.logical.zig
// ^^^^^ storage.type.error.zig
// ^ punctuation.accessor.zig
// ^^^^^^^^ constant.other.error.zig
// ^ punctuation.section.parens.end.zig
// ^ punctuation.terminator.zig
test "strings" {
c\\ adsjfafsdjkl \x11 \u1245 \U123456
extern fn bar() void;
c\\ adsjfafsdjkl \ \\ \ \xdeadbeef
extern fn foobar() void;
\\ adsjfafsdjkl
pub fn barfoo();
fn
\\ adsjfafsdjkl
}
"hello \x1 \n \t \\ \r 1m ' \\ \a \" \u{11}"
extern fn foobarfoo() void;
"\"hello\""
'a'
'ab'
'\''
'\a\naa'
'\a'
'\aaasas'
'\n'
// ^^ string.quoted.single.zig constant.character.escape.newline.zig
'💩';
}
fn(i13i,Foo) Bar;
// ^^ keyword.declaration.function.zig
// ^ punctuation.section.parens.begin.zig
// ^^^^ meta.function.parameters.zig storage.type.zig
// ^ meta.function.parameters.zig punctuation.separator.zig
// ^^^ meta.function.parameters.zig storage.type.zig
// ^ meta.function.parameters.zig punctuation.section.parens.end.zig
// ^^^ storage.type.zig
foo = bar;
@"overloaded" = 89;
// ^^^^^^^^^^^^ string.quoted.double.zig
// ^ keyword.operator.assignment.zig
@cImport
// <- keyword.control.import.zig
@cInclude
@import
@exampleBuiltin
// <- support.function.zig
typo@cImport
// ^^^^^^^^ keyword.control.import.zig
*const asasd
// <- keyword.operator.arithmetic.zig
//^^^^ storage.modifier.zig
*const [N:0]u8
?[]T and *[N]T
.{
.x = 13,
.y = 67,
}
var i: Number = .{.int = 42};
pub extern "hellas" export fn @"eeeasla"(as: FN) userdata;
pub extern "hellas" export fn hello(as: as) AA!OO {
anyframe->U
}
pub extern "ole32" stdcallcc fn CoTaskMemFree(pv: *const LPVOID, asda: asdsad, sacz: @"zxc", asd: asd) oop!asd;
pub stdcallcc fn CoUninitialize() A![];
ident
pub const Foo = extern struct {
fn_call()
};
asda: extern struct {
};
const Err = error {
};
{
: Bar,
}
(asdasd)
const Bar = struct {
field: Foo = 234"asas",
comptime field: Bad = Fasd {},
field: var
};
const Boof = union(enum) {
};
const Bad = enum(u8) {
Dummy,
_
};
var as: Bad = Bad(u8) {
pub stdcallcc fn CoUninitialize() void;
};
blk: {
// <- entity.name.label.zig
break :blk val1;
// ^^^^^ keyword.control.zig
// ^^^ entity.name.label.zig
// ^ punctuation.terminator.zig
var f = Bar {
// ^^^ storage.modifier.zig
// ^ keyword.operator.assignment.zig
// ^^^ storage.type.zig
// ^ punctuation.section.braces.begin.zig
.val = 9
}
}
extern fn f2(s: *const *volatile u8) Error!GenericType(s) {
}
var asd: *const asd!asdads = 0;
var ba = 0;
blk: while () : (sas) {
error.asdasd;
}
const asas: u8asd;
addsaad
const alignment = blk: {
const a = comptime meta.alignment(P);
const b: a = fn() A!A;
a = 23;
if (a > 0) break :blk a;
break :blk 1;
};
std.debug.warn(run_qemu.getEnvMap() .get("PATH"));
///Given a pointer to a single item, returns a slice of the underlying bytes, preserving constness.
pub fn asBytes(ptr: var) asdsa!AsBytesReturnType(@typeOf(ptr)) {
const P = @typeOf(ptr);
return @ptrCast(AsBytesReturnType(P), ptr);
}
pub const LARGE_INTEGER = extern struct {
// <- storage.modifier.zig
// ^^^^^ storage.modifier.zig
// ^^^^^^^^^^^^^ entity.name.class.struct.zig
// ^ keyword.operator.assignment.zig
// ^^^^^^ storage.modifier.zig
// ^^^^^^ keyword.declaration.struct.zig
// ^ punctuation.section.braces.begin.zig
_u2: extern struct {
// ^^^ variable.other.member.zig
// ^ punctuation.separator.zig
// ^^^^^^ storage.modifier.zig
// ^^^^^^ keyword.declaration.struct.zig
// ^ punctuation.section.braces.begin.zig
LowPart: fn(a, b, c)d,
// ^^^^^^^ variable.other.member.zig
// ^ punctuation.separator.zig
// ^^ keyword.declaration.function.zig
// ^ punctuation.section.parens.begin.zig
// ^ meta.function.parameters.zig storage.type.zig
// ^ meta.function.parameters.zig punctuation.separator.zig
// ^ meta.function.parameters.zig storage.type.zig
// ^ meta.function.parameters.zig punctuation.separator.zig
// ^ meta.function.parameters.zig storage.type.zig
// ^ meta.function.parameters.zig punctuation.section.parens.end.zig
// ^ storage.type.zig
// ^ punctuation.separator.zig
HighPart: LONG,
// ^^^^^^^^ variable.other.member.zig
// ^ punctuation.separator.zig
// ^^^^ storage.type.zig
// ^ punctuation.separator.zig
},
// ^ punctuation.section.braces.end.zig
// ^ punctuation.separator.zig
QuadPart: LONGLONG,
// ^^^^^^^^ variable.other.member.zig
// ^ punctuation.separator.zig
// ^^^^^^^^ storage.type.zig
};
pub const GUID = extern struct {
// ^^^^^ storage.modifier.zig
// ^^^^ entity.name.class.struct.zig
// ^ keyword.operator.assignment.zig
// ^^^^^^ storage.modifier.zig
// ^^^^^^ keyword.declaration.struct.zig
// ^ punctuation.section.braces.begin.zig
Data1: c_ulong,
// ^^^^^ variable.other.member.zig
// ^ punctuation.separator.zig
// ^^^^^^^ storage.type.zig
// ^ punctuation.separator.zig
Data2: c_ushort,
Data3: c_ushort,
Data4: [8]u8,
// ^^^^^ variable.other.member.zig
// ^ punctuation.separator.zig
// ^ punctuation.separator.zig
};
pub async fn function() Error!ReturnType {
// ^^^^^ keyword.control.async.zig
// ^^ keyword.declaration.function.zig
// ^^^^^^^^ entity.name.function
}
pub async fn function(arg: Int, arg: I) !ReturnType {
}
test "enum literals" {
const color1: Color = .Auto;
// ^^^^^ storage.modifier.zig
// ^^^^^^ variable.other.member.zig
// ^ punctuation.separator.zig
// ^^^^^ storage.type.zig
// ^ keyword.operator.assignment.zig
// ^^^^^ constant.language.enum
const color2 = Color.Auto;
// ^^^^ -constant.language.enum
const color2 = .{x}.Auto;
// ^^^^ -constant.language.enum
assert(color1 == color2);
const color = Color.On;
const result = switch (color) {
.Auto => false,
// ^^^^^ constant.language.enum
// ^^ keyword.operator.assignment.zig
// ^^^^^ constant.language.zig
.On => true,
// ^^^ constant.language.enum
.Off => false,
// ^^^^ constant.language.enum
};
assert(result);
}
test "fully anonymous list literal" {
const args = .{ @as(u32, 1234), @as(f64, 12.34)});
assert(args.@"0" == 1234);
// ^^^ string.quoted.double.zig
assert(args.@"1" == 12.34);
// ^^^ string.quoted.double.zig
}