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
|
// zig fmt: off
const es = @import("root");
const std = @import("std");
const ComptimeStringMap = std.ComptimeStringMap;
const Highlight = es.Highlight;
const Syntax = es.Syntax;
pub const filematch = [_][]const u8{
".zig",
};
// TODO: Add support for the multiline string \\
pub const syntax = Syntax{
.name = "Zig",
.keyword_classifier = ComptimeStringMap(
Highlight,
Syntax.pairWith(&keywords1, .keyword1) ++ Syntax.pairWith(&keywords2, .keyword2),
).get,
.singleline_comment_start = "//",
.multiline_comment_start = null,
.multiline_comment_end = null,
.separators = "&*^:,.=!<{[(-%|+?>}]);/~",
.flags = .{ .hl_numbers = true, .hl_strings = true },
};
const keywords1 = [_][]const u8 {
// keywords
"align", "allowzero", "and", "anyframe", "anytype", "asm", "async", "await", "break", "callconv",
"catch", "comptime", "const", "continue", "defer", "else", "enum", "errdefer", "error", "export",
"extern", "fn", "for", "if", "inline", "noalias", "nosuspend", "noinline", "opaque", "or",
"orelse", "packed", "pub", "resume", "return", "linksection", "struct", "suspend", "switch",
"test", "threadlocal", "try", "union", "unreachable", "usingnamespace", "var", "volatile",
"while",
// primitive values
"false", "null", "true", "undefined",
};
const keywords2 = [_][]const u8 {
// primitive types
// TODO: generate all the integer types
"i8", "u8", "i16", "u16", "i32", "u32", "i64", "u64", "i128", "u128", "isize", "usize",
"c_short", "c_ushort", "c_int", "c_uint", "c_long", "c_ulong", "c_longlong", "c_ulonglong",
"c_longdouble", "f16", "f32", "f64", "f128", "bool", "anyopaque", "void", "noreturn", "type",
"anyerror", "comptime_int", "comptime_float",
// former primitive types
"c_void",
// builtin functions
"@addWithOverflow", "@alignCast", "@alignOf", "@as", "@asyncCall", "@atomicLoad", "@atomicRmw",
"@atomicStore", "@bitCast", "@bitOffsetOf", "@boolToInt", "@bitSizeOf", "@breakpoint", "@mulAdd",
"@byteSwap", "@bitReverse", "@offsetOf", "@call", "@cDefine", "@cImport", "@cInclude", "@clz",
"@cmpxchgStrong", "@cmpxchgWeak", "@compileError", "@compileLog", "@ctz", "@cUndef", "@divExact",
"@divFloor", "@divTrunc", "@embedFile", "@enumToInt", "@errorName", "@errorReturnTrace",
"@errorToInt", "@errSetCast", "@export", "@extern", "@fence", "@field", "@fieldParentPtr",
"@floatCast", "@floatToInt", "@frame", "@Frame", "@frameAddress", "@frameSize", "@hasDecl",
"@hasField", "@import", "@intCast", "@intToEnum", "@intToError" , "@intToFloat", "@intToPtr",
"@maximum", "@memcpy", "@memset", "@minimum", "@wasmMemorySize", "@wasmMemoryGrow", "@mod",
"@mulWithOverflow", "@panic", "@popCount", "@prefetch", "@ptrCast", "@ptrToInt", "@rem",
"@returnAddress", "@select", "@setAlignStack", "@setCold", "@setEvalBranchQuota",
"@setFloatMode", "@setRuntimeSafety", "@shlExact", "@shlWithOverflow", "@shrExact", "@shuffle",
"@sizeOf", "@splat", "@reduce", "@src", "@sqrt", "@sin", "@cos", "@exp", "@exp2", "@log",
"@log2", "@log10", "@fabs", "@floor", "@ceil", "@trunc", "@round", "@subWithOverflow",
"@tagName", "@This", "@truncate", "@Type", "@typeInfo", "@typeName", "@TypeOf", "@unionInit",
};
|