aboutsummaryrefslogtreecommitdiff
path: root/src/recognizer.zig
diff options
context:
space:
mode:
authorNathan Reiner <nathan@nathanreiner.xyz>2025-05-21 19:44:11 +0200
committerNathan Reiner <nathan@nathanreiner.xyz>2025-05-21 19:44:11 +0200
commit79a5816b2643efef936651ba6384af616af9a2fb (patch)
tree3e7da1d791f0a7aff61f998babb9af06fcb582f0 /src/recognizer.zig
parente28bda801c1d7b9953298993b56408ce4202084f (diff)
fix unit tests
Diffstat (limited to 'src/recognizer.zig')
-rw-r--r--src/recognizer.zig29
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 {