summaryrefslogtreecommitdiff
path: root/src/Syntax.zig
diff options
context:
space:
mode:
Diffstat (limited to 'src/Syntax.zig')
-rw-r--r--src/Syntax.zig39
1 files changed, 31 insertions, 8 deletions
diff --git a/src/Syntax.zig b/src/Syntax.zig
index f29c7fc..6858027 100644
--- a/src/Syntax.zig
+++ b/src/Syntax.zig
@@ -1,14 +1,18 @@
1pub const makefile = @import("Syntax/makefile.zig"); 1pub const makefile = @import("Syntax/makefile.zig");
2pub const zig = @import("Syntax/zig.zig"); 2pub const zig = @import("Syntax/zig.zig");
3 3
4const es = @import("root");
4const std = @import("std"); 5const std = @import("std");
5 6
7const ComptimeStringMap = std.ComptimeStringMap;
8const Highlight = es.Highlight;
6const Syntax = @This(); 9const Syntax = @This();
7 10
8pub const database = [_]Syntax{ 11pub const chooseSyntax = ComptimeStringMap(
9 makefile.syntax, 12 Syntax,
10 zig.syntax, 13 pairWith(&makefile.filematch, makefile.syntax)
11}; 14 ++ pairWith(&zig.filematch, zig.syntax),
15).get;
12 16
13pub const Flags = struct { 17pub const Flags = struct {
14 hl_numbers: bool = false, 18 hl_numbers: bool = false,
@@ -16,10 +20,7 @@ pub const Flags = struct {
16}; 20};
17 21
18name: []const u8, 22name: []const u8,
19// TODO: Make these into comptime StringSets, see std.ComptimeStringMap 23keyword_classifier: fn([]const u8) ?Highlight,
20filematch: []const []const u8,
21keywords1: []const []const u8,
22keywords2: []const []const u8,
23singleline_comment_start: ?[]const u8, 24singleline_comment_start: ?[]const u8,
24multiline_comment_start: ?[]const u8, 25multiline_comment_start: ?[]const u8,
25multiline_comment_end: ?[]const u8, 26multiline_comment_end: ?[]const u8,
@@ -29,3 +30,25 @@ flags: Flags,
29pub fn isSeparator(self: Syntax, char: u8) bool { 30pub fn isSeparator(self: Syntax, char: u8) bool {
30 return std.ascii.isSpace(char) or std.mem.indexOfScalar(u8, self.separators, char) != null; 31 return std.ascii.isSpace(char) or std.mem.indexOfScalar(u8, self.separators, char) != null;
31} 32}
33
34pub fn pairWith(
35 comptime keys: []const []const u8,
36 comptime value: anytype,
37) [keys.len]KeyValue(@TypeOf(value)) {
38 @setEvalBranchQuota(20000);
39
40 var pairs = [_]KeyValue(@TypeOf(value)) {undefined} ** keys.len;
41 for (keys) |key, i| {
42 pairs[i] = .{ .@"0" = key, .@"1" = value };
43 }
44
45 return pairs;
46}
47
48fn KeyValue(comptime V: type) type {
49 return struct {
50 @"0": []const u8,
51 @"1": V,
52 };
53}
54