summaryrefslogtreecommitdiff
path: root/src/main.zig
blob: f28ab18895162f4984b0f317701cb69f62301881 (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
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);

    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);
}