rm ast_printer

This commit is contained in:
Luna 2019-07-01 15:02:14 -03:00
parent 90f33e84fc
commit b0e123f83a

View file

@ -1,32 +0,0 @@
const std = @import("std");
const ast = @import("ast.zig");
fn parenthesize(name: []const u8, exprs: []*ast.Expr) void {
std.debug.warn("({}", name);
for (exprs) |expr| {
std.debug.warn(" ");
printAst(expr);
}
std.debug.warn(")");
}
pub fn printAst(ast_expr: *ast.Expr) void {
switch (ast_expr.*) {
.Binary => |expr| parenthesize(expr.operator.lexeme, &[_]*ast.Expr{ expr.left, expr.right }),
.Grouping => |expr| parenthesize("group", &[_]*ast.Expr{expr.expression}),
.Unary => |expr| parenthesize(expr.operator.lexeme, &[_]*ast.Expr{expr.right}),
.Number => |ast_num| {
switch (ast_num) {
.Integer32 => |num| std.debug.warn("{}", num),
.Integer64 => |num| std.debug.warn("{}", num),
.Unsigned32 => |num| std.debug.warn("{}", num),
.Unsigned64 => |num| std.debug.warn("{}", num),
.Float32 => |num| std.debug.warn("{}", num),
.Float64 => |num| std.debug.warn("{}", num),
}
},
else => unreachable,
}
}