blob: 0554dca64eafe57b0ecab8eadd2845ecf82c1708 (
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
|
const std = @import("std");
const Token = @import("./tokenize.zig").Token;
pub const ParseError = error{
UnexpectedEnd,
InvalidQuery,
};
pub const AstKind = enum {
identity,
};
pub const Ast = struct {
kind: AstKind,
};
pub fn parse(allocator: std.mem.Allocator, tokens: []const Token) !*Ast {
if (tokens.len != 2) {
return ParseError.InvalidQuery;
}
const t1 = tokens[0];
const t2 = tokens[1];
if (t1.kind != .identity) {
return ParseError.InvalidQuery;
}
if (t2.kind != .end) {
return ParseError.UnexpectedEnd;
}
const root = try allocator.create(Ast);
root.kind = .identity;
return root;
}
|