From 32d0ac56c27719c6fcde70c51238f11cf5f44141 Mon Sep 17 00:00:00 2001 From: Stefan Weigl-Bosker Date: Fri, 20 Dec 2024 17:22:33 -0500 Subject: regex parsing --- src/main.zig | 37 +++++++++++++++++-------------------- 1 file changed, 17 insertions(+), 20 deletions(-) (limited to 'src/main.zig') diff --git a/src/main.zig b/src/main.zig index 8964c3c..f28ab18 100644 --- a/src/main.zig +++ b/src/main.zig @@ -9,26 +9,23 @@ pub fn main() !void { defer _ = gpa.deinit(); const lexer = try allocator.create(Regex.Lexer); + lexer.* = Regex.Lexer.init("abc|123[a-Z]()+", &allocator); - defer allocator.destroy(lexer); - - while (true) { - const token = lexer.advance() catch |err| switch (err) { - Regex.Lexer.Error.EndOfBuffer => { - break; - }, - else => { - return err; - }, - }; - - try stdio.print("{}\n", .{token}); - - if (token.value) |v| { - switch (v) { - .Class => |*rl| rl.deinit(), - else => {}, - } - } + + const tl = try lexer.scan(); + + var it = tl.first; + while (it) |node| : (it = node.next) { + try stdio.print("{}\n", .{&(node.data)}); } + + const parser = try allocator.create(Regex.Parser); + + parser.* = Regex.Parser.init(&lexer.tokens, &allocator); + + _ = try parser.parseRe(); + + lexer.deinit(); + allocator.destroy(lexer); + allocator.destroy(parser); } -- cgit v1.2.3