diff options
Diffstat (limited to 'src/recognizer.zig')
| -rw-r--r-- | src/recognizer.zig | 29 |
1 files changed, 18 insertions, 11 deletions
diff --git a/src/recognizer.zig b/src/recognizer.zig index 696a80a..4001e2c 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,32 @@ 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)) { + std.debug.print("HERE {}\n", .{n}); + 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 { |