summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--src/Buffer.zig18
-rw-r--r--src/Row.zig54
-rw-r--r--src/Syntax.zig39
-rw-r--r--src/Syntax/makefile.zig133
-rw-r--r--src/Syntax/zig.zig95
5 files changed, 183 insertions, 156 deletions
diff --git a/src/Buffer.zig b/src/Buffer.zig
index 7afdb05..ce2212c 100644
--- a/src/Buffer.zig
+++ b/src/Buffer.zig
@@ -529,20 +529,10 @@ pub fn selectSyntaxHighlighting(self: *Buffer) !void {
529 else 529 else
530 self.short_name; 530 self.short_name;
531 531
532 const ext = if (std.mem.lastIndexOfScalar(u8, name, '.')) |idx| name[idx..] else null; 532 self.syntax = Syntax.chooseSyntax(name);
533 for (Syntax.database) |syntax| { 533 if (self.syntax == null) {
534 for (syntax.filematch) |filematch| { 534 if (std.mem.lastIndexOfScalar(u8, name, '.')) |idx| {
535 const is_ext = filematch[0] == '.'; 535 self.syntax = Syntax.chooseSyntax(name[idx..]);
536 if ((is_ext and ext != null and std.mem.eql(u8, ext.?, filematch))
537 or (!is_ext and std.mem.eql(u8, name, filematch))) {
538 self.syntax = syntax;
539
540 for (self.rows.items) |*row| {
541 try row.updateSyntax(self);
542 }
543
544 return;
545 }
546 } 536 }
547 } 537 }
548} 538}
diff --git a/src/Row.zig b/src/Row.zig
index 38fb72b..a47be6a 100644
--- a/src/Row.zig
+++ b/src/Row.zig
@@ -149,14 +149,12 @@ pub fn updateSyntax(self: *Row, buf: *Buffer) UpdateSyntaxError!void {
149 } 149 }
150 150
151 const syntax = buf.syntax.?; 151 const syntax = buf.syntax.?;
152 const kw1 = syntax.keywords1;
153 const kw2 = syntax.keywords2;
154 152
155 var after_sep = true;
156 var in_comment = if (self.idx > 0) buf.rows.items[self.idx - 1].ends_with_open_comment else false; 153 var in_comment = if (self.idx > 0) buf.rows.items[self.idx - 1].ends_with_open_comment else false;
157 var curr_str_quote: ?u8 = null; 154 var curr_str_quote: ?u8 = null;
158 155
159 var i: usize = 0; 156 var i: usize = 0;
157 var last_sep: usize = 0;
160 main_loop: while (i < self.rdata.items.len) { 158 main_loop: while (i < self.rdata.items.len) {
161 const prev_hl = if (i > 0) self.hldata.items[i - 1] else .normal; 159 const prev_hl = if (i > 0) self.hldata.items[i - 1] else .normal;
162 160
@@ -165,7 +163,7 @@ pub fn updateSyntax(self: *Row, buf: *Buffer) UpdateSyntaxError!void {
165 if (curr_str_quote == null and !in_comment and scs.len + i <= self.rdata.items.len) { 163 if (curr_str_quote == null and !in_comment and scs.len + i <= self.rdata.items.len) {
166 if (std.mem.eql(u8, scs, self.rdata.items[i..(i + scs.len)])) { 164 if (std.mem.eql(u8, scs, self.rdata.items[i..(i + scs.len)])) {
167 std.mem.set(Highlight, self.hldata.items[i..], .comment); 165 std.mem.set(Highlight, self.hldata.items[i..], .comment);
168 break; 166 break :main_loop;
169 } 167 }
170 } 168 }
171 } 169 }
@@ -181,16 +179,16 @@ pub fn updateSyntax(self: *Row, buf: *Buffer) UpdateSyntaxError!void {
181 std.mem.set(Highlight, self.hldata.items[i..(i + mce.len)], .comment_ml); 179 std.mem.set(Highlight, self.hldata.items[i..(i + mce.len)], .comment_ml);
182 i += mce.len; 180 i += mce.len;
183 in_comment = false; 181 in_comment = false;
184 after_sep = true; 182 last_sep = i;
185 } else { 183 } else {
186 i += 1; 184 i += 1;
187 continue; 185 continue :main_loop;
188 } 186 }
189 } else if (mcs.len + i <= self.rdata.items.len and std.mem.eql(u8, mcs, self.rdata.items[i..(i + mcs.len)])) { 187 } else if (mcs.len + i <= self.rdata.items.len and std.mem.eql(u8, mcs, self.rdata.items[i..(i + mcs.len)])) {
190 std.mem.set(Highlight, self.hldata.items[i..(i + mcs.len)], .comment_ml); 188 std.mem.set(Highlight, self.hldata.items[i..(i + mcs.len)], .comment_ml);
191 i += mcs.len; 189 i += mcs.len;
192 in_comment = true; 190 in_comment = true;
193 continue; 191 continue :main_loop;
194 } 192 }
195 } 193 }
196 } 194 }
@@ -208,54 +206,50 @@ pub fn updateSyntax(self: *Row, buf: *Buffer) UpdateSyntaxError!void {
208 i += 1; 206 i += 1;
209 } else if (c == quote) { 207 } else if (c == quote) {
210 curr_str_quote = null; 208 curr_str_quote = null;
211 after_sep = true; 209 last_sep = i;
212 } 210 }
213 211
214 continue; 212 continue :main_loop;
215 } else { 213 } else {
216 // TODO: Move this to syntax struct 214 // TODO: Move this to syntax struct
217 if (c == '"' or c == '\'') { 215 if (c == '"' or c == '\'') {
218 curr_str_quote = c; 216 curr_str_quote = c;
219 self.hldata.items[i] = .string; 217 self.hldata.items[i] = .string;
220 i += 1; 218 i += 1;
221 continue; 219 continue :main_loop;
222 } 220 }
223 } 221 }
224 } 222 }
225 223
226 if (syntax.flags.hl_numbers) { 224 if (syntax.flags.hl_numbers) {
227 if ((std.ascii.isDigit(c) and (after_sep or prev_hl == .number)) or (c == '.' and prev_hl == .number)) { 225 if ((std.ascii.isDigit(c) and (last_sep == i or prev_hl == .number))
228 after_sep = false; 226 or (c == '.' and prev_hl == .number)
227 ) {
229 self.hldata.items[i] = .number; 228 self.hldata.items[i] = .number;
230 i += 1; 229 i += 1;
231 continue; 230 continue :main_loop;
232 } 231 }
233 } 232 }
234 233
235 if (after_sep) { 234 if (syntax.isSeparator(c)) {
236 for (kw1) |kw| { 235 const id = self.rdata.items[last_sep..i];
237 if (i + kw.len <= self.rdata.items.len and std.mem.eql(u8, kw, self.rdata.items[i..(i + kw.len)]) and (i + kw.len == self.rdata.items.len or syntax.isSeparator(self.rdata.items[i + kw.len]))) { 236 if (syntax.keyword_classifier(id)) |hl| {
238 std.mem.set(Highlight, self.hldata.items[i..(i + kw.len)], .keyword1); 237 std.mem.set(Highlight, self.hldata.items[last_sep..i], hl);
239 i += kw.len;
240 after_sep = false;
241 continue :main_loop;
242 }
243 } 238 }
244 239
245 for (kw2) |kw| { 240 last_sep = i + 1;
246 if (i + kw.len <= self.rdata.items.len and std.mem.eql(u8, kw, self.rdata.items[i..(i + kw.len)]) and (i + kw.len == self.rdata.items.len or syntax.isSeparator(self.rdata.items[i + kw.len]))) {
247 std.mem.set(Highlight, self.hldata.items[i..(i + kw.len)], .keyword2);
248 i += kw.len;
249 after_sep = false;
250 continue :main_loop;
251 }
252 }
253 } 241 }
254 242
255 after_sep = syntax.isSeparator(c);
256 i += 1; 243 i += 1;
257 } 244 }
258 245
246 if (!in_comment) {
247 const id = self.rdata.items[last_sep..self.rdata.items.len];
248 if (syntax.keyword_classifier(id)) |hl| {
249 std.mem.set(Highlight, self.hldata.items[last_sep..self.rdata.items.len], hl);
250 }
251 }
252
259 if (in_comment != self.ends_with_open_comment) { 253 if (in_comment != self.ends_with_open_comment) {
260 self.ends_with_open_comment = in_comment; 254 self.ends_with_open_comment = in_comment;
261 if (self.idx + 1 < buf.rows.items.len) { 255 if (self.idx + 1 < buf.rows.items.len) {
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
diff --git a/src/Syntax/makefile.zig b/src/Syntax/makefile.zig
index 5c93df4..6ae7386 100644
--- a/src/Syntax/makefile.zig
+++ b/src/Syntax/makefile.zig
@@ -1,78 +1,89 @@
1// zig fmt: off 1// zig fmt: off
2 2
3const es = @import("root"); 3const es = @import("root");
4const std = @import("std");
4 5
6const ComptimeStringMap = std.ComptimeStringMap;
7const Highlight = es.Highlight;
5const Syntax = es.Syntax; 8const Syntax = es.Syntax;
6 9
10pub const filematch = [_][]const u8{
11 "GNUmakefile", "makefile", "Makefile",
12
13 ".mk",
14};
15
7pub const syntax = Syntax{ 16pub const syntax = Syntax{
8 .name = "Makefile", 17 .name = "Makefile",
9 .filematch = &[_][]const u8{ "GNUmakefile", "makefile", "Makefile", ".mk" }, 18 .keyword_classifier = ComptimeStringMap(
10 .keywords1 = &[_][]const u8{ 19 Highlight,
11 "$@", "$(@D)", "$(@F)", 20 Syntax.pairWith(&keywords1, .keyword1) ++ Syntax.pairWith(&keywords2, .keyword2),
12 "$%", "$(%D)", "$(%F)", 21 ).get,
13 "$<", "$(<D)", "$(<F)", 22 .singleline_comment_start = "#",
14 "$?", "$(?D)", "$(?F)", 23 .multiline_comment_start = null,
15 "$^", "$(^D)", "$(^F)", 24 .multiline_comment_end = null,
16 "$+", "$(+D)", "$(+F)", 25 .separators = "(){};:-@+",
17 "$|", 26 .flags = .{},
18 "$*", "$(*D)", "$(*F)", 27};
19 28
20 ".DEFAULT", ".DEFAULT_GOAL", ".DELETE_ON_ERROR", ".EXPORT_ALL_VARIABLES", ".EXTRA_PREREQS", 29const keywords1 = [_][]const u8{
21 ".FEATURES", ".IGNORE", ".INCLUDE_DIRS", ".INTERMEDIATE", ".LIBPATTERNS", ".LOADED", 30 "$@", "$(@D)", "$(@F)",
22 ".LOW_RESOLUTION_TIME", ".NOTPARALLEL", ".ONESHELL", ".PHONY", ".POSIX", ".PRECIOUS", 31 "$%", "$(%D)", "$(%F)",
23 ".RECIPEPREFIX", ".SECONDARY", ".SECONDEXPANSION", ".SHELLFLAGS", ".SHELLSTATUS", ".SILENT", 32 "$<", "$(<D)", "$(<F)",
24 ".SUFFIXES", ".VARIABLES", 33 "$?", "$(?D)", "$(?F)",
34 "$^", "$(^D)", "$(^F)",
35 "$+", "$(+D)", "$(+F)",
36 "$*", "$(*D)", "$(*F)",
37 "$|",
25 38
26 "abspath", "addprefix", "addsuffix", "and", "basename", "call", "define", "dir", "else", 39 ".DEFAULT", ".DEFAULT_GOAL", ".DELETE_ON_ERROR", ".EXPORT_ALL_VARIABLES", ".EXTRA_PREREQS",
27 "endef", "endif", "error", "eval", "export", "file", "filter", "filter-out", "findstring", 40 ".FEATURES", ".IGNORE", ".INCLUDE_DIRS", ".INTERMEDIATE", ".LIBPATTERNS", ".LOADED",
28 "firstword", "flavor", "foreach", "gmk-eval", "gmk-expand", "guile", "if", "ifdef", "ifeq", 41 ".LOW_RESOLUTION_TIME", ".NOTPARALLEL", ".ONESHELL", ".PHONY", ".POSIX", ".PRECIOUS",
29 "ifndef", "ifneq", "include", "info", "join", "lastword", "load", "notdir", "or", "origin", 42 ".RECIPEPREFIX", ".SECONDARY", ".SECONDEXPANSION", ".SHELLFLAGS", ".SHELLSTATUS", ".SILENT",
30 "override", "patsubst", "private", "realpath", "shell", "sort", "strip", "subst", "suffix", 43 ".SUFFIXES", ".VARIABLES",
31 "undefined", "unexport", "value", "vpath", "warning", "wildcard", "word", "wordlist",
32 "words",
33 44
34 "ar", "as", "awk", "bison", "c99", "cat", "cc", "chgrp", "chmod", "chown", "cmp", "co", "cp", 45 "abspath", "addprefix", "addsuffix", "and", "basename", "call", "define", "dir", "else", "endef",
35 "ctangle", "cweave", "diff", "do", "done", "echo", "elif", "else", "egrep", "expr", "fc", 46 "endif", "error", "eval", "export", "file", "filter", "filter-out", "findstring", "firstword",
36 "for", "f77", "false", "fi", "find", "flex", "g++", "get", "grep", "gzip", "if", "in", 47 "flavor", "foreach", "gmk-eval", "gmk-expand", "guile", "if", "ifdef", "ifeq", "ifndef", "ifneq",
37 "install", "install-info", "ld", "ldconfig", "lex", "lint", "ln", "ls", "m2c", "make", 48 "include", "info", "join", "lastword", "load", "notdir", "or", "origin", "override", "patsubst",
38 "makeinfo", "mkdir", "mknod", "mv", "pc", "printf", "pwd", "ranlib", "rm", "rmdir", "sed", 49 "private", "realpath", "shell", "sort", "strip", "subst", "suffix", "undefined", "unexport",
39 "sleep", "sort", "tangle", "tar", "test", "tex", "texi2dvi", "then", "tr", "true", "touch", 50 "value", "vpath", "warning", "wildcard", "word", "wordlist", "words",
40 "weave", "yacc",
41 },
42 .keywords2 = &[_][]const u8{
43 "AR", "AS", "AWK", "BISON", "CAT", "CC", "CHGRP", "CHMOD", "CHOWN", "CMP", "CO", "CP", "CPP",
44 "CTANGLE", "CWEAVE", "CXX", "DIFF", "ECHO", "EGREP", "EXPR", "FALSE", "FC", "FIND", "FLEX",
45 "GET", "GREP", "GZIP", "INSTALL", "INSTALL_DATA", "INSTALL_INFO", "INSTALL_PROGRAM", "LD",
46 "LDCONFIG", "LEX", "LINT", "LN", "LS", "M2C", "MAKE", "MAKEINFO", "MKDIR", "MKNOD", "MV",
47 "RM", "PC", "PRINTF", "PWD", "RANLIB", "RMDIR", "SED", "SLEEP", "SORT", "TANGLE", "TAR",
48 "TEST", "TEX", "TEXI2DVI", "TOUCH", "TR", "TRUE", "WEAVE", "YACC",
49 51
50 "ARFLAGS", "BISONFLAGS", "ASFLAGS", "CFLAGS", "COFLAGS", "CPPFLAGS", "CXXFLAGS", "FFLAGS", 52 "ar", "as", "awk", "bison", "c99", "cat", "cc", "chgrp", "chmod", "chown", "cmp", "co", "cp",
51 "GFLAGS", "LDFLAGS", "LDLIBS", "LFLAGS", "LINTFLAGS", "MAKEFLAGS", "MFLAGS", "PFLAGS", 53 "ctangle", "cweave", "diff", "do", "done", "echo", "elif", "else", "egrep", "expr", "fc", "for",
52 "REALFLAGS", "YFLAGS", 54 "f77", "false", "fi", "find", "flex", "g++", "get", "grep", "gzip", "if", "in", "install",
55 "install-info", "ld", "ldconfig", "lex", "lint", "ln", "ls", "m2c", "make", "makeinfo", "mkdir",
56 "mknod", "mv", "pc", "printf", "pwd", "ranlib", "rm", "rmdir", "sed", "sleep", "sort", "tangle",
57 "tar", "test", "tex", "texi2dvi", "then", "tr", "true", "touch", "weave", "yacc",
58};
53 59
54 "COMSPEC", "CURDIR", "DESTDIR", "GPATH", "LOADLIBES", "MAKECMDGOALS", "MAKEFILES", 60const keywords2 = [_][]const u8{
55 "MAKEFILE_LIST", "MAKELEVEL", "MAKEOVERRIDES", "MAKESHELL", "MAKE_HOST", "MAKE_RESTARTS", 61 "AR", "AS", "AWK", "BISON", "CAT", "CC", "CHGRP", "CHMOD", "CHOWN", "CMP", "CO", "CP", "CPP",
56 "MAKE_TERMERR", "MAKE_TERMOUT", "MAKE_VERSION", "OUTPUT_OPTION", "SHELL", "SUFFIXES", 62 "CTANGLE", "CWEAVE", "CXX", "DIFF", "ECHO", "EGREP", "EXPR", "FALSE", "FC", "FIND", "FLEX",
57 "VPATH", 63 "GET", "GREP", "GZIP", "INSTALL", "INSTALL_DATA", "INSTALL_INFO", "INSTALL_PROGRAM", "LD",
64 "LDCONFIG", "LEX", "LINT", "LN", "LS", "M2C", "MAKE", "MAKEINFO", "MKDIR", "MKNOD", "MV", "RM",
65 "PC", "PRINTF", "PWD", "RANLIB", "RMDIR", "SED", "SLEEP", "SORT", "TANGLE", "TAR", "TEST", "TEX",
66 "TEXI2DVI", "TOUCH", "TR", "TRUE", "WEAVE", "YACC",
58 67
59 "bindir", "datadir", "datarootdir", "docdir", "dvidir", "exec_prefix", "htmldir", 68 "ARFLAGS", "BISONFLAGS", "ASFLAGS", "CFLAGS", "COFLAGS", "CPPFLAGS", "CXXFLAGS", "FFLAGS",
60 "includedir", "infodir", "libexecdir", "libdir", "lispdir", "localedir", "localstatedir", 69 "GFLAGS", "LDFLAGS", "LDLIBS", "LFLAGS", "LINTFLAGS", "MAKEFLAGS", "MFLAGS", "PFLAGS",
61 "mandir", "manext", "man1dir", "man1ext", "man2dir", "man2ext", "man3dir", "man3ext", 70 "REALFLAGS", "YFLAGS",
62 "man4dir", "man4ext", "man5dir", "man5ext", "man6dir", "man6ext", "man7dir", "man7ext",
63 "man8dir", "man8ext", "manndir", "mannext", "oldincludedir", "pdfdir", "psdir", "prefix",
64 "runstatedir", "sbindir", "srcdir", "sharedstatedir", "sysconfdir",
65 71
66 "all", "check", "clean", "dist", "distclean", "dvi", "html", "info", "install", 72 "COMSPEC", "CURDIR", "DESTDIR", "GPATH", "LOADLIBES", "MAKECMDGOALS", "MAKEFILES",
67 "install-dvi", "install-html", "install-pdf", "install-ps", "install-strip", "installcheck", 73 "MAKEFILE_LIST", "MAKELEVEL", "MAKEOVERRIDES", "MAKESHELL", "MAKE_HOST", "MAKE_RESTARTS",
68 "installdirs", "maintainer-clean", "mostlyclean", "pdf", "ps", "uninstall", "TAGS", 74 "MAKE_TERMERR", "MAKE_TERMOUT", "MAKE_VERSION", "OUTPUT_OPTION", "SHELL", "SUFFIXES", "VPATH",
69 75
70 "NORMAL_INSTALL", "NORMAL_UNINSTALL", "POST_INSTALL", "POST_UNINSTALL", "PRE_INSTALL", 76 "bindir", "datadir", "datarootdir", "docdir", "dvidir", "exec_prefix", "htmldir", "includedir",
71 "PRE_UNINSTALL" 77 "infodir", "libexecdir", "libdir", "lispdir", "localedir", "localstatedir", "mandir", "manext",
72 }, 78 "man1dir", "man1ext", "man2dir", "man2ext", "man3dir", "man3ext", "man4dir", "man4ext",
73 .singleline_comment_start = "#", 79 "man5dir", "man5ext", "man6dir", "man6ext", "man7dir", "man7ext", "man8dir", "man8ext",
74 .multiline_comment_start = null, 80 "manndir", "mannext", "oldincludedir", "pdfdir", "psdir", "prefix", "runstatedir", "sbindir",
75 .multiline_comment_end = null, 81 "srcdir", "sharedstatedir", "sysconfdir",
76 .separators = "(){};:-@+", 82
77 .flags = .{}, 83 "all", "check", "clean", "dist", "distclean", "dvi", "html", "info", "install", "install-dvi",
84 "install-html", "install-pdf", "install-ps", "install-strip", "installcheck", "installdirs",
85 "maintainer-clean", "mostlyclean", "pdf", "ps", "uninstall", "TAGS",
86
87 "NORMAL_INSTALL", "NORMAL_UNINSTALL", "POST_INSTALL", "POST_UNINSTALL", "PRE_INSTALL",
88 "PRE_UNINSTALL",
78}; 89};
diff --git a/src/Syntax/zig.zig b/src/Syntax/zig.zig
index 4826bfb..c8bc225 100644
--- a/src/Syntax/zig.zig
+++ b/src/Syntax/zig.zig
@@ -3,57 +3,66 @@
3const es = @import("root"); 3const es = @import("root");
4const std = @import("std"); 4const std = @import("std");
5 5
6const ComptimeStringMap = std.ComptimeStringMap;
7const Highlight = es.Highlight;
6const Syntax = es.Syntax; 8const Syntax = es.Syntax;
7 9
10pub const filematch = [_][]const u8{
11 ".zig",
12};
13
8// TODO: Add support for the multiline string \\ 14// TODO: Add support for the multiline string \\
9pub const syntax = Syntax{ 15pub const syntax = Syntax{
10 .name = "Zig", 16 .name = "Zig",
11 .filematch = &[_][]const u8{ ".zig" }, 17 .keyword_classifier = ComptimeStringMap(
12 .keywords1 = &[_][]const u8{ 18 Highlight,
13 // keywords 19 Syntax.pairWith(&keywords1, .keyword1) ++ Syntax.pairWith(&keywords2, .keyword2),
14 "align", "allowzero", "and", "anyframe", "anytype", "asm", "async", "await", "break", 20 ).get,
15 "callconv", "catch", "comptime", "const", "continue", "defer", "else", "enum", "errdefer",
16 "error", "export", "extern", "fn", "for", "if", "inline", "noalias", "nosuspend", "noinline",
17 "opaque", "or", "orelse", "packed", "pub", "resume", "return", "linksection", "struct",
18 "suspend", "switch", "test", "threadlocal", "try", "union", "unreachable", "usingnamespace",
19 "var", "volatile", "while",
20
21 // primitive values
22 "false", "null", "true", "undefined",
23 },
24 .keywords2 = &[_][]const u8{
25 // primitive types
26 "i8", "u8", "i16", "u16", "i32", "u32", "i64", "u64", "i128", "u128", "isize", "usize",
27 "c_short", "c_ushort", "c_int", "c_uint", "c_long", "c_ulong", "c_longlong", "c_ulonglong",
28 "c_longdouble", "f16", "f32", "f64", "f128", "bool", "anyopaque", "void", "noreturn", "type",
29 "anyerror", "comptime_int", "comptime_float",
30
31 // removed types
32 "c_void",
33
34 // TODO: Generate all integer types
35
36 // builtin functions
37 "@addWithOverflow", "@alignCast", "@alignOf", "@as", "@asyncCall", "@atomicLoad",
38 "@atomicRmw", "@atomicStore", "@bitCast", "@bitOffsetOf", "@boolToInt", "@bitSizeOf",
39 "@breakpoint", "@mulAdd", "@byteSwap", "@bitReverse", "@offsetOf", "@call", "@cDefine",
40 "@cImport", "@cInclude", "@clz", "@cmpxchgStrong", "@cmpxchgWeak", "@compileError",
41 "@compileLog", "@ctz", "@cUndef", "@divExact", "@divFloor", "@divTrunc", "@embedFile",
42 "@enumToInt", "@errorName", "@errorReturnTrace", "@errorToInt", "@errSetCast", "@export",
43 "@extern", "@fence", "@field", "@fieldParentPtr", "@floatCast", "@floatToInt", "@frame",
44 "@Frame", "@frameAddress", "@frameSize", "@hasDecl", "@hasField", "@import", "@intCast",
45 "@intToEnum", "@intToError" , "@intToFloat", "@intToPtr", "@maximum", "@memcpy", "@memset",
46 "@minimum", "@wasmMemorySize", "@wasmMemoryGrow", "@mod", "@mulWithOverflow", "@panic",
47 "@popCount", "@prefetch", "@ptrCast", "@ptrToInt", "@rem", "@returnAddress", "@select",
48 "@setAlignStack", "@setCold", "@setEvalBranchQuota", "@setFloatMode", "@setRuntimeSafety",
49 "@shlExact", "@shlWithOverflow", "@shrExact", "@shuffle", "@sizeOf", "@splat", "@reduce",
50 "@src", "@sqrt", "@sin", "@cos", "@exp", "@exp2", "@log", "@log2", "@log10", "@fabs",
51 "@floor", "@ceil", "@trunc", "@round", "@subWithOverflow", "@tagName", "@This", "@truncate",
52 "@Type", "@typeInfo", "@typeName", "@TypeOf", "@unionInit",
53 },
54 .singleline_comment_start = "//", 21 .singleline_comment_start = "//",
55 .multiline_comment_start = null, 22 .multiline_comment_start = null,
56 .multiline_comment_end = null, 23 .multiline_comment_end = null,
57 .separators = "&*^:,.=!<{[(-%|+?>}]);/~", 24 .separators = "&*^:,.=!<{[(-%|+?>}]);/~",
58 .flags = .{ .hl_numbers = true, .hl_strings = true }, 25 .flags = .{ .hl_numbers = true, .hl_strings = true },
59}; 26};
27
28const keywords1 = [_][]const u8 {
29 // keywords
30 "align", "allowzero", "and", "anyframe", "anytype", "asm", "async", "await", "break", "callconv",
31 "catch", "comptime", "const", "continue", "defer", "else", "enum", "errdefer", "error", "export",
32 "extern", "fn", "for", "if", "inline", "noalias", "nosuspend", "noinline", "opaque", "or",
33 "orelse", "packed", "pub", "resume", "return", "linksection", "struct", "suspend", "switch",
34 "test", "threadlocal", "try", "union", "unreachable", "usingnamespace", "var", "volatile",
35 "while",
36
37 // primitive values
38 "false", "null", "true", "undefined",
39};
40
41const keywords2 = [_][]const u8 {
42 // primitive types
43 // TODO: generate all the integer types
44 "i8", "u8", "i16", "u16", "i32", "u32", "i64", "u64", "i128", "u128", "isize", "usize",
45 "c_short", "c_ushort", "c_int", "c_uint", "c_long", "c_ulong", "c_longlong", "c_ulonglong",
46 "c_longdouble", "f16", "f32", "f64", "f128", "bool", "anyopaque", "void", "noreturn", "type",
47 "anyerror", "comptime_int", "comptime_float",
48
49 // former primitive types
50 "c_void",
51
52 // builtin functions
53 "@addWithOverflow", "@alignCast", "@alignOf", "@as", "@asyncCall", "@atomicLoad", "@atomicRmw",
54 "@atomicStore", "@bitCast", "@bitOffsetOf", "@boolToInt", "@bitSizeOf", "@breakpoint", "@mulAdd",
55 "@byteSwap", "@bitReverse", "@offsetOf", "@call", "@cDefine", "@cImport", "@cInclude", "@clz",
56 "@cmpxchgStrong", "@cmpxchgWeak", "@compileError", "@compileLog", "@ctz", "@cUndef", "@divExact",
57 "@divFloor", "@divTrunc", "@embedFile", "@enumToInt", "@errorName", "@errorReturnTrace",
58 "@errorToInt", "@errSetCast", "@export", "@extern", "@fence", "@field", "@fieldParentPtr",
59 "@floatCast", "@floatToInt", "@frame", "@Frame", "@frameAddress", "@frameSize", "@hasDecl",
60 "@hasField", "@import", "@intCast", "@intToEnum", "@intToError" , "@intToFloat", "@intToPtr",
61 "@maximum", "@memcpy", "@memset", "@minimum", "@wasmMemorySize", "@wasmMemoryGrow", "@mod",
62 "@mulWithOverflow", "@panic", "@popCount", "@prefetch", "@ptrCast", "@ptrToInt", "@rem",
63 "@returnAddress", "@select", "@setAlignStack", "@setCold", "@setEvalBranchQuota",
64 "@setFloatMode", "@setRuntimeSafety", "@shlExact", "@shlWithOverflow", "@shrExact", "@shuffle",
65 "@sizeOf", "@splat", "@reduce", "@src", "@sqrt", "@sin", "@cos", "@exp", "@exp2", "@log",
66 "@log2", "@log10", "@fabs", "@floor", "@ceil", "@trunc", "@round", "@subWithOverflow",
67 "@tagName", "@This", "@truncate", "@Type", "@typeInfo", "@typeName", "@TypeOf", "@unionInit",
68};