diff options
author | Stefan Weigl-Bosker <stefan@s00.xyz> | 2024-12-14 18:10:39 -0500 |
---|---|---|
committer | Stefan Weigl-Bosker <stefan@s00.xyz> | 2024-12-14 18:10:39 -0500 |
commit | 94b86481395cb2d2a594bb98a1380b9ddc8aa900 (patch) | |
tree | fb73afee136f0895392e7cc7eee3528c242883a8 /src/main.zig | |
download | lg-94b86481395cb2d2a594bb98a1380b9ddc8aa900.tar.gz |
inital commit
Diffstat (limited to 'src/main.zig')
-rw-r--r-- | src/main.zig | 34 |
1 files changed, 34 insertions, 0 deletions
diff --git a/src/main.zig b/src/main.zig new file mode 100644 index 0000000..8964c3c --- /dev/null +++ b/src/main.zig @@ -0,0 +1,34 @@ +const std = @import("std"); +const Regex = @import("regex.zig"); + +pub fn main() !void { + const stdio = std.io.getStdIn().writer(); + var gpa = std.heap.GeneralPurposeAllocator(.{}){}; + var allocator = gpa.allocator(); + + 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 => {}, + } + } + } +} |