From f49a8e54eeaa5bca332fc7cc977d47583e8fe297 Mon Sep 17 00:00:00 2001 From: Nathan Reiner Date: Thu, 22 May 2025 14:32:53 +0200 Subject: grammar: fix invalid grammar loading error --- src/grammar.zig | 27 +++++++++++++++------------ 1 file changed, 15 insertions(+), 12 deletions(-) (limited to 'src/grammar.zig') diff --git a/src/grammar.zig b/src/grammar.zig index 9b794a0..eaea3d4 100644 --- a/src/grammar.zig +++ b/src/grammar.zig @@ -29,6 +29,17 @@ pub fn parse(entry: []const u8, buffer: []const u8, allocator: std.mem.Allocator }; errdefer self.deinit(); + { + var iterator = names.iterator(); + while (iterator.next()) |name_entry| { + self.non_terminals[name_entry.value_ptr.*] = try NonTerminal.init( + name_entry.key_ptr.*, + name_entry.value_ptr.*, + allocator + ); + } + } + { self.non_terminals[0] = try NonTerminal.init("_start", 0, allocator); const init_rule = try allocator.alloc(Character, 1); @@ -41,17 +52,6 @@ pub fn parse(entry: []const u8, buffer: []const u8, allocator: std.mem.Allocator }); } - { - var iterator = names.iterator(); - while (iterator.next()) |name_entry| { - self.non_terminals[name_entry.value_ptr.*] = try NonTerminal.init( - name_entry.key_ptr.*, - name_entry.value_ptr.*, - allocator - ); - } - } - while (lines.next()) |line| { const name = try NonTerminal.parse_name(line); try self.non_terminal_by_id( @@ -230,7 +230,10 @@ pub fn is_next_char(self: *const Self, rule_slice: []Character, current: usize, } } - const result = is_char_in_first or (is_epsilon_in_first and self.non_terminals[current].follows.is_set(char)); + const result = is_char_in_first or ( + is_epsilon_in_first and + self.non_terminals[current].follows.is_set(char) + ); return result; } -- cgit v1.2.3-70-g09d2