diff options
Diffstat (limited to 'src/jq/parse.zig')
| -rw-r--r-- | src/jq/parse.zig | 33 |
1 files changed, 33 insertions, 0 deletions
diff --git a/src/jq/parse.zig b/src/jq/parse.zig new file mode 100644 index 0000000..0554dca --- /dev/null +++ b/src/jq/parse.zig @@ -0,0 +1,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; +} |
