Skip to content

Commit 546a929

Browse files
author
Antigravity Agent
committed
fix(reader): add enum parsing support
- Parse "enum:" at indent 2: extract "[Red, Black]" - Store in TypeDef.enum_values - Output as "pub const Color = enum { Red, Black };" Tested: rb_tree.tri generates correct Color enum. Note: skip_list MAX_LEVEL still unsupported (constants not parsed).
1 parent 32d297e commit 546a929

1 file changed

Lines changed: 23 additions & 0 deletions

File tree

tools/gen/tri_reader.zig

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1084,6 +1084,29 @@ const Parser = struct {
10841084
continue;
10851085
}
10861086

1087+
// "enum:" property at indent 2 (4 spaces)
1088+
if (indent == 2 and std.mem.startsWith(u8, trimmed, "enum:")) {
1089+
if (current_type) |*t| {
1090+
const enum_line = trimmed["enum:".len..];
1091+
const enum_val = std.mem.trim(u8, enum_line, " \t\r");
1092+
// Parse "[Red, Black]" -> ["Red", "Black"]
1093+
if (enum_val.len > 2 and enum_val[0] == '[' and enum_val[enum_val.len - 1] == ']') {
1094+
const values_str = enum_val[1 .. enum_val.len - 1];
1095+
var values = try std.ArrayList([]const u8).initCapacity(self.allocator, 0);
1096+
var iter = std.mem.splitScalar(u8, values_str, ',');
1097+
while (iter.next()) |v| {
1098+
const trimmed_val = std.mem.trim(u8, v, " \t");
1099+
if (trimmed_val.len > 0) {
1100+
try values.append(self.allocator, try self.allocator.dupe(u8, trimmed_val));
1101+
}
1102+
}
1103+
t.enum_values = try values.toOwnedSlice(self.allocator);
1104+
t.variant = .enum_type;
1105+
}
1106+
}
1107+
continue;
1108+
}
1109+
10871110
// Field definition at indent 3 (6 spaces): "- name: key"
10881111
if (indent == 3 and in_fields_section and current_fields != null and std.mem.startsWith(u8, trimmed, "-")) {
10891112
var field_line = trimmed[1..]; // Skip "-"

0 commit comments

Comments
 (0)