From: Ayo Reis Date: Wed, 25 Feb 2026 13:13:06 +0000 (+0000) Subject: Rename error functions X-Git-Url: https://git.ayoreis.com/zlox.git/commitdiff_plain/b1df22a631a16008822c347371e35f7b54b2eed8?ds=inline Rename error functions --- diff --git a/src/Parser.zig b/src/Parser.zig index a584c3f..bcc6ee6 100644 --- a/src/Parser.zig +++ b/src/Parser.zig @@ -138,7 +138,7 @@ fn primary(self: *Parser) !*Expr { return grouping; } - try self.@"error"(self.peek(), "Expect expression."); + try self.err(self.peek(), "Expect expression."); } fn match(self: *Parser, types: []const TokenType) bool { @@ -155,7 +155,7 @@ fn match(self: *Parser, types: []const TokenType) bool { fn consume(self: *Parser, @"type": TokenType, message: []const u8) !Token { if (self.check(@"type")) return self.advance(); - try self.@"error"(self.peek(), message); + try self.err(self.peek(), message); } fn check(self: *Parser, @"type": TokenType) bool { @@ -180,8 +180,8 @@ fn previous(self: *Parser) Token { return self.tokens[self.current - 1]; } -fn @"error"(self: *Parser, token: Token, message: []const u8) !noreturn { - try lox.parse_error(self.allocator, token, message); +fn err(self: *Parser, token: Token, message: []const u8) !noreturn { + try lox.parseError(self.allocator, token, message); return error.ParseError; } diff --git a/src/Scanner.zig b/src/Scanner.zig index 98fc69e..6890df6 100644 --- a/src/Scanner.zig +++ b/src/Scanner.zig @@ -87,7 +87,7 @@ fn scanToken(self: *Scanner) !void { } else if (isAlpha(c)) { try self.identifier(); } else { - try lox.@"error"(self.line, "Unexpected character."); + try lox.scanError(self.line, "Unexpected character."); }, } } @@ -120,7 +120,7 @@ fn string(self: *Scanner) !void { } if (self.isAtEnd()) { - try lox.@"error"(self.line, "Unterminated string."); + try lox.scanError(self.line, "Unterminated string."); return; } diff --git a/src/main.zig b/src/main.zig index 0e41f10..a17dbd7 100644 --- a/src/main.zig +++ b/src/main.zig @@ -71,7 +71,7 @@ fn run(allocator: Allocator, source: []const u8) !void { std.debug.print("{s}\n", .{printed}); } -pub fn @"error"(line: u32, message: []const u8) !void { +pub fn scanError(line: u32, message: []const u8) !void { try report(line, "", message); } @@ -85,7 +85,7 @@ fn report(line: u32, where: []const u8, message: []const u8) !void { hadError = true; } -pub fn parse_error(allocator: Allocator, token: Token, message: []const u8) !void { +pub fn parseError(allocator: Allocator, token: Token, message: []const u8) !void { if (token.type == .eof) { try report(token.line, " at end", message); } else {