diff options
| author | Nathan Reiner <nathan@nathanreiner.xyz> | 2025-05-21 19:44:11 +0200 |
|---|---|---|
| committer | Nathan Reiner <nathan@nathanreiner.xyz> | 2025-05-21 19:47:36 +0200 |
| commit | 2ee78f3c3884a315baffee7d5e9244f52c59c10b (patch) | |
| tree | 65919d8a6f54be7b67be9c12b108a47c645f3275 /src/recognizer.zig | |
| parent | e28bda801c1d7b9953298993b56408ce4202084f (diff) | |
fix unit tests
Diffstat (limited to 'src/recognizer.zig')
| -rw-r--r-- | src/recognizer.zig | 28 |
1 files changed, 17 insertions, 11 deletions
diff --git a/src/recognizer.zig b/src/recognizer.zig index 696a80a..a6fe721 100644 --- a/src/recognizer.zig +++ b/src/recognizer.zig @@ -55,7 +55,7 @@ const State = struct { const rule = grammar.non_terminal_by_id(self.id).rules()[self.rule_index]; std.debug.print("{*} state (", .{ self }); - for (rule, 0..) |char, index| { + for (rule.items, 0..) |char, index| { if (index == self.inner_position) { std.debug.print("○", .{}); } @@ -63,7 +63,7 @@ const State = struct { std.debug.print("{}", .{char}); } - if (rule.len == self.inner_position) { + if (rule.items.len == self.inner_position) { std.debug.print("○", .{}); } std.debug.print(")\n", .{}); @@ -72,25 +72,31 @@ const State = struct { pub fn reaches_end_of_entry(grammar: *Grammar, node: *gss.Node(State)) bool { const rule = grammar.non_terminal_by_id(node.state.id).rules()[node.state.rule_index]; - if (node.state.is_at_end_of_rule(rule)) { - for (node.parents.items) |parent| { - if (reaches_end_of_entry(grammar, parent)) { - return true; - } - } - return node.is_toplevel; + if (node.parents.items.len == 0) { + return true; } for (rule.items[node.state.inner_position..]) |character| { switch (character) { .terminal => return false, - .non_terminal => |n| return grammar.non_terminal_by_id(n).follows.is_set(Character.END), + .non_terminal => |n| { + if (!grammar.non_terminal_by_id(n).first.is_set(Character.EPSILON)) { + return false; + } + }, else => {} } } - return grammar.non_terminal_by_id(node.state.id).follows.is_set(Character.END); + for (node.parents.items) |parent| { + parent.state = parent.state.next(); + if (reaches_end_of_entry(grammar, parent)) { + return true; + } + } + + return false; } pub fn check(grammar: *Grammar, input: []const u8, inner_allocator: std.mem.Allocator) !bool { |