]> Repositories - zlox.git/commitdiff
Remove unnecessary error logic
authorAyo Reis <hey@ayoreis.com>
Wed, 25 Feb 2026 18:28:18 +0000 (18:28 +0000)
committerAyo Reis <hey@ayoreis.com>
Wed, 25 Feb 2026 18:28:18 +0000 (18:28 +0000)
src/Parser.zig
src/Scanner.zig
src/ast_printer.zig

index 762edb8f22c4712334d97d179aea014a042a0426..7b5a3117d0a17f7383565223dae824dca0cf7dbd 100644 (file)
@@ -102,7 +102,7 @@ fn unary(self: *Parser) !*Expr {
         return expr;
     }
 
-    return try self.primary();
+    return self.primary();
 }
 
 fn primary(self: *Parser) !*Expr {
index 6890df6093246d4dc6682f776a4070b23e959595..fad8278d92888a2e6afad3225a3ae3a34eb8b366 100644 (file)
@@ -50,7 +50,7 @@ pub fn scanTokens(self: *Scanner) ![]Token {
     }
 
     try self.tokens.append(self.allocator, .init(.eof, "", null, self.line));
-    return try self.tokens.toOwnedSlice(self.allocator);
+    return self.tokens.toOwnedSlice(self.allocator);
 }
 
 fn scanToken(self: *Scanner) !void {
index 978484bcbfbf8b3ec5d98f62ad3276bed14b8842..2df8c8ecf790282b87913071cd17b78f513dd0ca 100644 (file)
@@ -5,15 +5,15 @@ const Token = @import("Token.zig");
 
 pub fn print(allocator: Allocator, expr: *const Expr) Allocator.Error![]const u8 {
     return switch (expr.*) {
-        .binary => |binary| try parenthesize(allocator, binary.operator.lexeme, &.{ binary.left, binary.right }),
-        .grouping => |grouping| try parenthesize(allocator, "group", &.{grouping.expression}),
+        .binary => |binary| parenthesize(allocator, binary.operator.lexeme, &.{ binary.left, binary.right }),
+        .grouping => |grouping| parenthesize(allocator, "group", &.{grouping.expression}),
         .literal => |literal| switch (literal.value) {
-            .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}),
+            .string => |string| allocator.dupe(u8, string),
+            .number => |number| std.fmt.allocPrint(allocator, "{}", .{number}),
+            .boolean => |boolean| std.fmt.allocPrint(allocator, "{}", .{boolean}),
+            .nil => allocator.dupe(u8, "nil"),
         },
-        .unary => |unary| try parenthesize(allocator, unary.operator.lexeme, &.{unary.right}),
+        .unary => |unary| parenthesize(allocator, unary.operator.lexeme, &.{unary.right}),
     };
 }
 
@@ -30,5 +30,5 @@ fn parenthesize(allocator: Allocator, name: []const u8, exprs: []const *const Ex
     }
     try builder.append(allocator, ')');
 
-    return try builder.toOwnedSlice(allocator);
+    return builder.toOwnedSlice(allocator);
 }