]> Repositories - zlox.git/blobdiff - src/ast_printer.zig
Rename error functions
[zlox.git] / src / ast_printer.zig
index 21c8702c81e6020ebb855dc5754dad155b53e4d3..978484bcbfbf8b3ec5d98f62ad3276bed14b8842 100644 (file)
@@ -8,9 +8,9 @@ pub fn print(allocator: Allocator, expr: *const Expr) Allocator.Error![]const u8
         .binary => |binary| try parenthesize(allocator, binary.operator.lexeme, &.{ binary.left, binary.right }),
         .grouping => |grouping| try parenthesize(allocator, "group", &.{grouping.expression}),
         .literal => |literal| switch (literal.value) {
-            .nil => "nil",
-            .boolean => |boolean| if (boolean) "true" else "false",
-            .string => |string| string,
+            .nil => try allocator.dupe(u8, "nil"),
+            .boolean => |boolean| try std.fmt.allocPrint(allocator, "{}", .{boolean}),
+            .string => |string| try allocator.dupe(u8, string),
             .number => |number| try std.fmt.allocPrint(allocator, "{}", .{number}),
         },
         .unary => |unary| try parenthesize(allocator, unary.operator.lexeme, &.{unary.right}),