diff options
Diffstat (limited to 'src/Syntax.zig')
| -rw-r--r-- | src/Syntax.zig | 39 |
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 @@ | |||
| 1 | pub const makefile = @import("Syntax/makefile.zig"); | 1 | pub const makefile = @import("Syntax/makefile.zig"); |
| 2 | pub const zig = @import("Syntax/zig.zig"); | 2 | pub const zig = @import("Syntax/zig.zig"); |
| 3 | 3 | ||
| 4 | const es = @import("root"); | ||
| 4 | const std = @import("std"); | 5 | const std = @import("std"); |
| 5 | 6 | ||
| 7 | const ComptimeStringMap = std.ComptimeStringMap; | ||
| 8 | const Highlight = es.Highlight; | ||
| 6 | const Syntax = @This(); | 9 | const Syntax = @This(); |
| 7 | 10 | ||
| 8 | pub const database = [_]Syntax{ | 11 | pub 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 | ||
| 13 | pub const Flags = struct { | 17 | pub 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 | ||
| 18 | name: []const u8, | 22 | name: []const u8, |
| 19 | // TODO: Make these into comptime StringSets, see std.ComptimeStringMap | 23 | keyword_classifier: fn([]const u8) ?Highlight, |
| 20 | filematch: []const []const u8, | ||
| 21 | keywords1: []const []const u8, | ||
| 22 | keywords2: []const []const u8, | ||
| 23 | singleline_comment_start: ?[]const u8, | 24 | singleline_comment_start: ?[]const u8, |
| 24 | multiline_comment_start: ?[]const u8, | 25 | multiline_comment_start: ?[]const u8, |
| 25 | multiline_comment_end: ?[]const u8, | 26 | multiline_comment_end: ?[]const u8, |
| @@ -29,3 +30,25 @@ flags: Flags, | |||
| 29 | pub fn isSeparator(self: Syntax, char: u8) bool { | 30 | pub 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 | |||
| 34 | pub 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 | |||
| 48 | fn KeyValue(comptime V: type) type { | ||
| 49 | return struct { | ||
| 50 | @"0": []const u8, | ||
| 51 | @"1": V, | ||
| 52 | }; | ||
| 53 | } | ||
| 54 | |||