diff options
Diffstat (limited to 'src/non-terminal.zig')
| -rw-r--r-- | src/non-terminal.zig | 12 |
1 files changed, 6 insertions, 6 deletions
diff --git a/src/non-terminal.zig b/src/non-terminal.zig index 1665a80..f5ecf09 100644 --- a/src/non-terminal.zig +++ b/src/non-terminal.zig @@ -2,9 +2,9 @@ const std = @import("std"); const CharSet = @import("char-set.zig"); const Character = @import("character.zig").Character; const string = @import("string.zig"); +const Rule = @import("rule.zig"); const Self = @This(); -pub const Rule = []Character; id: usize, name: []const u8, @@ -26,7 +26,7 @@ pub fn init(name: []const u8, id: usize, allocator: std.mem.Allocator) !Self { pub fn deinit(self: *Self) void { for (self.rules()) |rule| { - self.allocator.free(rule); + self.allocator.free(rule.items); } self.rule_list.deinit(); @@ -69,7 +69,7 @@ pub fn parse_and_add_variants( head = std.mem.trimLeft(u8, head, &std.ascii.whitespace); while (head.len > 0) { if (head[0] == '|') { - try self.rule_list.append(try rule.toOwnedSlice()); + try self.rule_list.append(Rule { .items = try rule.toOwnedSlice() }); rule = std.ArrayList(Character).init(self.allocator); head = head[1..]; } else if (head[0] == '\'') { @@ -112,7 +112,7 @@ pub fn parse_and_add_variants( return error.EmptyVariant; } - try self.rule_list.append(try rule.toOwnedSlice()); + try self.rule_list.append(Rule { .items = try rule.toOwnedSlice() }); } pub inline fn is_empty(self: *const Self) bool { @@ -131,13 +131,13 @@ pub fn format( try writer.print("{s} ->", .{ self.name }); if (self.rule_list.items.len > 0) { - for (self.rule_list.items[0]) |c| { + for (self.rule_list.items[0].items) |c| { try writer.print(" {}", .{c}); } for (self.rule_list.items[1..]) |r| { try writer.print(" |", .{}); - for (r) |c| { + for (r.items) |c| { try writer.print(" {}", .{c}); } } |