summaryrefslogtreecommitdiff
path: root/src/main.zig
blob: 8964c3c73533258c848de047404db7ed44502e76 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
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 => {},
            }
        }
    }
}