1const std = @import("std");
2const common = @import("./_common.zig");
3
4pub usingnamespace common.Main(struct {
5 pub const source_file = "DerivedAge";
6
7 pub const dest_file = "src/derived_age.zig";
8
9 pub const dest_header =
10 \\pub const Age = struct {
11 \\ from: u21,
12 \\ to: u21,
13 \\ since: [2]u8,
14 \\};
15 \\
16 \\pub const data = [_]Age{
17 \\
18 ;
19
20 pub const dest_footer =
21 \\};
22 \\
23 ;
24
25 pub fn exec(alloc: std.mem.Allocator, line: []const u8, writer: anytype) !void {
26 _ = alloc;
27 var it = std.mem.tokenizeAny(u8, line, "; ");
28
29 {
30 const range = it.next().?;
31 if (std.mem.indexOf(u8, range, "..")) |index| {
32 try writer.print(" .{{ .from = 0x{s}, .to = 0x{s},", .{ range[0..index], range[index + 2 ..] });
33 } else {
34 try writer.print(" .{{ .from = 0x{s}, .to = 0x{s},", .{ range, range });
35 }
36 }
37 {
38 const added = it.next().?;
39 var jt = std.mem.splitScalar(u8, added, '.');
40 const major = jt.next().?;
41 const minor = jt.next().?;
42 try writer.print(" .since = .{{ {s},{s} }} }},\n", .{ major, minor });
43 }
44 }
45});