authorgravatar for hello@nektro.netMeghan Denny <hello@nektro.net> 2021-05-31 12:32:07 -07:00
committergravatar for hello@nektro.netMeghan Denny <hello@nektro.net> 2021-05-31 12:32:07 -07:00
log30ff725e47a66dbfeae96e64257c161bae181bf8
treead18108b5db1484d3cfb333e9defdc3ed82fa195
parent5315f98e71b7ee82fea0a83844263d701419ef1a

gen- move blocks into its own file


2 files changed, 41 insertions(+), 34 deletions(-)

generate.zig+6-34
...@@ -1,39 +1,11 @@...@@ -1,39 +1,11 @@
1const std = @import("std");1const std = @import("std");
22
3const common = @import("scripts/_common.zig");3const files = &[_]type{
4 @import("scripts/blocks.zig"),
5};
46
5pub fn main() !void {7pub fn main() !void {
6 // Blocks8 inline for (files) |f| {
7 try common.Main(struct {9 try f.default.do();
8 pub const source_url = "https://unicode.org/Public/UCD/latest/ucd/Blocks.txt";10 }
9
10 pub const dest_file = "src/blocks.zig";
11
12 pub const dest_header =
13 \\pub const Block = struct {
14 \\ from: u21,
15 \\ to: u21,
16 \\ name: []const u8,
17 \\};
18 \\
19 \\pub const blocks: []Block = &.{
20 \\
21 ;
22
23 pub const dest_footer =
24 \\};
25 \\
26 ;
27
28 pub fn exec(alloc: *std.mem.Allocator, line: []const u8, writer: anytype) !bool {
29 var it1 = std.mem.split(line, "; ");
30 var it2 = std.mem.split(it1.next().?, "..");
31 const from = it2.next().?;
32 const to = it2.next().?;
33 const name = it1.next().?;
34
35 try writer.print(" .{{ 0x{s}, 0x{s}, \"{s}\" }},\n", .{ from, to, name });
36 return true;
37 }
38 }).do();
39}11}
scripts/blocks.zig created+35
...@@ -0,0 +1,35 @@
1const std = @import("std");
2const common = @import("./_common.zig");
3
4pub const default = common.Main(struct {
5 pub const source_url = "https://unicode.org/Public/UCD/latest/ucd/Blocks.txt";
6
7 pub const dest_file = "src/blocks.zig";
8
9 pub const dest_header =
10 \\pub const Block = struct {
11 \\ from: u21,
12 \\ to: u21,
13 \\ name: []const u8,
14 \\};
15 \\
16 \\pub const blocks: []Block = &.{
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) !bool {
26 var it1 = std.mem.split(line, "; ");
27 var it2 = std.mem.split(it1.next().?, "..");
28 const from = it2.next().?;
29 const to = it2.next().?;
30 const name = it1.next().?;
31
32 try writer.print(" .{{ 0x{s}, 0x{s}, \"{s}\" }},\n", .{ from, to, name });
33 return true;
34 }
35});