diff options
Diffstat (limited to 'src/grammar.zig')
| -rw-r--r-- | src/grammar.zig | 27 |
1 files changed, 15 insertions, 12 deletions
diff --git a/src/grammar.zig b/src/grammar.zig index 9b794a0..eaea3d4 100644 --- a/src/grammar.zig +++ b/src/grammar.zig @@ -30,6 +30,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); init_rule[0] = Character { @@ -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; } |