aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorNathan Reiner <nathan@nathanreiner.xyz>2025-05-14 08:30:28 +0200
committerNathan Reiner <nathan@nathanreiner.xyz>2025-05-14 08:30:28 +0200
commit3fa83926b88a8000c3183377c0ddfe3222503c76 (patch)
treee20d232a874f4bd436e87ea505297105bb992c7c /src
parent76f808ea98313dc847f634b2d8e31066b7a1c68d (diff)
recognizer: fix next_char check bug
Diffstat (limited to 'src')
-rw-r--r--src/grammar.zig4
-rw-r--r--src/recognizer.zig25
2 files changed, 7 insertions, 22 deletions
diff --git a/src/grammar.zig b/src/grammar.zig
index b3785ba..ab51275 100644
--- a/src/grammar.zig
+++ b/src/grammar.zig
@@ -51,10 +51,6 @@ pub fn parse(entry: []const u8, buffer: []const u8, allocator: std.mem.Allocator
self.generate_first();
self.generate_follows();
- for (self.non_terminals) |non_terminal| {
- std.debug.print("{s} := {}\n", .{non_terminal.name, non_terminal.follows});
- }
-
std.debug.print("{}\n", .{self});
return self;
diff --git a/src/recognizer.zig b/src/recognizer.zig
index 4a266a2..3c284d1 100644
--- a/src/recognizer.zig
+++ b/src/recognizer.zig
@@ -100,12 +100,13 @@ pub fn forward_and_consume(
.terminal => |t| if (t == terminal) try queue.append(try graph.clone(node, node.state.next())),
.non_terminal => |n| {
const non_terminal = grammar.non_terminal_by_id(n);
- if (grammar.is_next_char(
- non_terminal.rules()[node.state.rule_index][node.state.inner_position..],
- node.state.id,
- terminal,
- )) {
- for (0..grammar.non_terminal_by_id(n).rules().len) |rule_index| {
+ for (0..grammar.non_terminal_by_id(n).rules().len) |rule_index| {
+ if (grammar.is_next_char(
+ non_terminal.rules()[rule_index],
+ n,
+ terminal,
+ )) {
+
const state = State {
.id = n,
.rule_index = rule_index,
@@ -118,7 +119,6 @@ pub fn forward_and_consume(
result.value_ptr.* = try graph.push(node, state);
try forward_and_consume(grammar, result.value_ptr.*, graph, terminal, queue, node_cache);
} else {
- std.debug.print("HERE {}{*} <- {}{*}\n", .{node, node, result.value_ptr.*, result.value_ptr.*});
try result.value_ptr.*.parents.append(node);
}
}
@@ -140,8 +140,6 @@ pub fn reaches_end_of_entry(grammar: *Grammar, node: *gss.Node(State)) bool {
}
}
- std.debug.print("HERE {}\n", .{ node.is_toplevel });
-
return node.is_toplevel;
}
@@ -187,12 +185,7 @@ pub fn check(grammar: *Grammar, input: []const u8, inner_allocator: std.mem.Allo
defer node_cache.deinit();
for (input) |character| {
- std.debug.print("=============\n", .{});
for (processing_queue.items) |node| {
- node.state.debug(grammar);
- std.debug.print("PARENT:\n", .{});
- for (node.parents.items) |parent| { parent.state.debug(grammar); }
- std.debug.print("-------------\n", .{});
try forward_and_consume(
grammar,
node,
@@ -211,11 +204,7 @@ pub fn check(grammar: *Grammar, input: []const u8, inner_allocator: std.mem.Allo
next_processing_queue.clearRetainingCapacity();
}
- std.debug.print("==== END ====\n", .{});
-
for (processing_queue.items) |node| {
- node.state.debug(grammar);
- std.debug.print("parent = {any}\n", .{node.parents.items});
if (reaches_end_of_entry(grammar, node)) {
return true;
}