authorgravatar for hello@nektro.netMeghan Denny <hello@nektro.net> 2026-01-18 12:08:36 -08:00
committergravatar for hello@nektro.netMeghan Denny <hello@nektro.net> 2026-01-18 12:08:36 -08:00
logb2fbe35178db709c2d9e240c5315e6e137366397
treec06c8f5b4c341406546d58d6761e9be186be3142
parentc5781c41c29fab2503be89178519d6396d4066e7

centralize comment handling to _common


3 files changed, 9 insertions(+), 14 deletions(-)

scripts/Jamo.zig+2-3
......@@ -26,9 +26,8 @@ pub usingnamespace common.Main(struct {
2626 var it = std.mem.tokenizeAny(u8, line, "; ");
2727
2828 const first = it.next().?;
29 const next = it.next().?;
30 const actual = if (std.mem.eql(u8, next, "#")) "" else next;
29 const short = it.next() orelse "";
3130
32 try writer.print(" .{{ .code = 0x{s}, .short_name = \"{}\" }},\n", .{ first, std.zig.fmtEscapes(actual) });
31 try writer.print(" .{{ .code = 0x{s}, .short_name = \"{}\" }},\n", .{ first, std.zig.fmtEscapes(short) });
3332 }
3433});
scripts/ScriptExtensions.zig+2-6
......@@ -34,18 +34,14 @@ pub usingnamespace common.Main(struct {
3434 const end = try std.fmt.parseInt(u21, first[index + 2 ..], 16);
3535 var i = start;
3636 while (i <= end) : (i += 1) {
37 try writer.print(" .{{ .code = 0x{X}, .scripts = {} }},\n", .{ i, fmtScripts(untilComment(it.rest())) });
37 try writer.print(" .{{ .code = 0x{X}, .scripts = {} }},\n", .{ i, fmtScripts(it.rest()) });
3838 }
3939 } else {
40 try writer.print(" .{{ .code = 0x{s}, .scripts = {} }},\n", .{ first, fmtScripts(untilComment(it.rest())) });
40 try writer.print(" .{{ .code = 0x{s}, .scripts = {} }},\n", .{ first, fmtScripts(it.rest()) });
4141 }
4242 }
4343});
4444
45fn untilComment(input: []const u8) []const u8 {
46 return input[0..std.mem.indexOfScalar(u8, input, '#').?];
47}
48
4945fn fmtScripts(bytes: []const u8) std.fmt.Formatter(formatScripts) {
5046 return .{ .data = bytes };
5147}
scripts/_common.zig+5-5
......@@ -54,18 +54,18 @@ pub fn Main(comptime T: type) type {
5454 var arena = std.heap.ArenaAllocator.init(alloc);
5555 defer arena.deinit();
5656 while (true) {
57 const line = r.readUntilDelimiterAlloc(alloc, '\n', max_size) catch |err| switch (err) {
57 const line_raw = r.readUntilDelimiterAlloc(alloc, '\n', max_size) catch |err| switch (err) {
5858 error.EndOfStream => break,
5959 else => |e| return e,
6060 };
61 defer alloc.free(line);
61 defer alloc.free(line_raw);
62
63 var real = std.mem.splitScalar(u8, line_raw, '#');
64 const line = real.first();
6265
6366 if (line.len == 0) {
6467 continue;
6568 }
66 if (line[0] == '#') {
67 continue;
68 }
6969
7070 try T.exec(arena.allocator(), line, w);
7171