| 1 | const std = @import("std"); |
| 2 | const common = @import("./_common.zig"); |
| 3 | const extras = @import("extras"); |
| 4 | |
| 5 | pub usingnamespace common.Main(struct { |
| 6 | pub const source_file = "PropertyValueAliases"; |
| 7 | |
| 8 | pub const dest_file = "src/property_value_aliases.zig"; |
| 9 | |
| 10 | pub const dest_header = |
| 11 | \\const std = @import("std"); |
| 12 | \\ |
| 13 | \\pub const data = [_][3][:0]const u8{ |
| 14 | \\ |
| 15 | ; |
| 16 | |
| 17 | pub const dest_footer = |
| 18 | \\}; |
| 19 | ; |
| 20 | |
| 21 | pub fn exec(alloc: std.mem.Allocator, line: []const u8, writer: anytype) !void { |
| 22 | _ = alloc; |
| 23 | const end = std.mem.indexOfScalar(u8, line, '#') orelse line.len; |
| 24 | var it = std.mem.tokenizeAny(u8, line[0..end], "; "); |
| 25 | |
| 26 | var vals = [_][]const u8{ |
| 27 | it.next().?, |
| 28 | it.next().?, |
| 29 | it.next().?, |
| 30 | }; |
| 31 | flip(std.fmt.parseInt(u32, vals[1], 10)) catch { |
| 32 | vals[1] = vals[2]; |
| 33 | vals[2] = it.next().?; |
| 34 | }; |
| 35 | |
| 36 | try writer.print(" .{{ \"{}\", \"{}\", \"{}\" }},\n", .{ |
| 37 | std.zig.fmtEscapes(vals[0]), |
| 38 | std.zig.fmtEscapes(vals[1]), |
| 39 | std.zig.fmtEscapes(vals[2]), |
| 40 | }); |
| 41 | |
| 42 | while (it.next()) |more| { |
| 43 | try writer.print(" .{{ \"{}\", \"{}\", \"{}\" }},\n", .{ |
| 44 | std.zig.fmtEscapes(vals[0]), |
| 45 | std.zig.fmtEscapes(more), |
| 46 | std.zig.fmtEscapes(vals[2]), |
| 47 | }); |
| 48 | } |
| 49 | } |
| 50 | }); |
| 51 | |
| 52 | fn flip(foo: anytype) !void { |
| 53 | _ = foo catch return; |
| 54 | return error.ExpectedError; |
| 55 | } |