aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/parse.zig19
1 files changed, 19 insertions, 0 deletions
diff --git a/src/parse.zig b/src/parse.zig
index 24d6e42..7daa3f8 100644
--- a/src/parse.zig
+++ b/src/parse.zig
@@ -24,9 +24,28 @@ pub const Expr = struct {
const Op = enum {
plus,
minus,
+
+ pub fn format(self: Op, comptime fmt: []const u8, options: std.fmt.FormatOptions, writer: anytype) !void {
+ _ = fmt;
+ _ = options;
+ try writer.writeByte(switch (self) {
+ .plus => '+',
+ .minus => '-',
+ });
+ }
};
};
};
+
+ pub fn format(self: Expr, comptime fmt: []const u8, options: std.fmt.FormatOptions, writer: anytype) !void {
+ _ = fmt;
+ _ = options;
+ switch (self.type) {
+ .integer_literal => try writer.print("<int>", .{}),
+ .bin_op => |bin_op| try writer.print("({} {} {})", .{ bin_op.lhs, bin_op.op, bin_op.rhs }),
+ .invalid => try writer.print("<invalid>", .{}),
+ }
+ }
};
pub fn expression(allocator: Allocator, lexer: *Peekable(Lexer)) error{OutOfMemory}!*Expr {