summaryrefslogtreecommitdiff
path: root/src/Syntax/zig.zig
blob: 4e8249613d265d770909b563f5eea01c35ce51db (plain) (blame)
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
// 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
    "addrspace", "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", "linksection", "noalias",
    "noinline", "nosuspend", "opaque", "or", "orelse", "packed", "pub", "resume", "return", "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_char",
    "c_short", "c_ushort", "c_int", "c_uint", "c_long", "c_ulong", "c_longlong", "c_ulonglong",
    "c_longdouble", "f16", "f32", "f64", "f80", "f128", "bool", "anyopaque", "void", "noreturn",
    "type", "anyerror", "comptime_int", "comptime_float",

    // former primitive types
    "c_void",

    // builtin functions
    "@addrSpaceCast", "@addWithOverflow", "@alignCast", "@alignOf", "@as", "@atomicLoad",
    "@atomicRmw", "@atomicStore", "@bitCast", "@bitOffsetOf", "@bitSizeOf", "@breakpoint", "@mulAdd",
    "@byteSwap", "@bitReverse", "@offsetOf", "@call", "@cDefine", "@cImport", "@cInclude", "@clz",
    "@cmpxchgStrong", "@cmpxchgWeak", "@compileError", "@compileLog", "@constCast", "@ctz",
    "@cUndef", "@cVaArg", "@cVaCopy", "@cVaEnd", "@cVaStart", "@divExact", "@divFloor", "@divTrunc",
    "@embedFile", "@enumFromInt", "@errorFromInt", "@errorName", "@errorReturnTrace", "@errorCast",
    "@export", "@extern", "@fence", "@field", "@fieldParentPtr", "@floatCast", "@floatFromInt",
    "@frameAddress", "@hasDecl", "@hasField", "@import", "@inComptime", "@intCast", "@intFromBool",
    "@intFromEnum", "@intFromError", "@intFromFloat", "@intFromPtr", "@max", "@memcpy", "@memset",
    "@min", "@wasmMemorySize", "@wasmMemoryGrow", "@mod", "@mulWithOverflow", "@panic", "@popCount",
    "@prefetch", "@ptrCast", "@ptrFromInt", "@rem", "@returnAddress", "@select", "@setAlignStack",
    "@setCold", "@setEvalBranchQuota", "@setFloatMode", "@setRuntimeSafety", "@shlExact",
    "@shlWithOverflow", "@shrExact", "@shuffle", "@sizeOf", "@splat", "@reduce", "@src", "@sqrt",
    "@sin", "@cos", "@tan", "@exp", "@exp2", "@log", "@log2", "@log10", "@abs", "@floor", "@ceil",
    "@trunc", "@round", "@subWithOverflow", "@tagName", "@This", "@trap", "@truncate", "@Type",
    "@typeInfo", "@typeName", "@TypeOf", "@unionInit", "@Vector", "@volatileCast", "@workGroupId",
    "@workGroupSize", "@workItemId",

    // former builtin functions
    "@asyncCall", "@boolToInt", "@enumToInt", "@errorToInt", "@errSetCast", "@floatToInt", "@frame",
    "@Frame", "@frameSize", "@intToEnum", "@intToError" , "@intToFloat", "@intToPtr", "@maximum",
    "@minimum", "@ptrToInt", "@fabs",
};