diff --git a/std/zig/ast.zig b/std/zig/ast.zig index aefbd9cbab..f63cc0d1bf 100644 --- a/std/zig/ast.zig +++ b/std/zig/ast.zig @@ -255,39 +255,39 @@ pub const Error = union(enum) { } } - pub const InvalidToken = SingleTokenError("Invalid token {}"); - pub const ExpectedContainerMembers = SingleTokenError("Expected test, comptime, var decl, or container field, found {}"); - pub const ExpectedStringLiteral = SingleTokenError("Expected string literal, found {}"); - pub const ExpectedIntegerLiteral = SingleTokenError("Expected integer literal, found {}"); - pub const ExpectedIdentifier = SingleTokenError("Expected identifier, found {}"); - pub const ExpectedStatement = SingleTokenError("Expected statement, found {}"); - pub const ExpectedVarDeclOrFn = SingleTokenError("Expected variable declaration or function, found {}"); - pub const ExpectedVarDecl = SingleTokenError("Expected variable declaration, found {}"); - pub const ExpectedReturnType = SingleTokenError("Expected 'var' or return type expression, found {}"); - pub const ExpectedAggregateKw = SingleTokenError("Expected " ++ @tagName(Token.Id.Keyword_struct) ++ ", " ++ @tagName(Token.Id.Keyword_union) ++ ", or " ++ @tagName(Token.Id.Keyword_enum) ++ ", found {}"); - pub const ExpectedEqOrSemi = SingleTokenError("Expected '=' or ';', found {}"); - pub const ExpectedSemiOrLBrace = SingleTokenError("Expected ';' or '{{', found {}"); - pub const ExpectedSemiOrElse = SingleTokenError("Expected ';' or 'else', found {}"); - pub const ExpectedLBrace = SingleTokenError("Expected '{{', found {}"); - pub const ExpectedLabelOrLBrace = SingleTokenError("Expected label or '{{', found {}"); - pub const ExpectedColonOrRParen = SingleTokenError("Expected ':' or ')', found {}"); - pub const ExpectedLabelable = SingleTokenError("Expected 'while', 'for', 'inline', 'suspend', or '{{', found {}"); - pub const ExpectedInlinable = SingleTokenError("Expected 'while' or 'for', found {}"); - pub const ExpectedAsmOutputReturnOrType = SingleTokenError("Expected '->' or " ++ @tagName(Token.Id.Identifier) ++ ", found {}"); - pub const ExpectedSliceOrRBracket = SingleTokenError("Expected ']' or '..', found {}"); - pub const ExpectedTypeExpr = SingleTokenError("Expected type expression, found {}"); - pub const ExpectedPrimaryTypeExpr = SingleTokenError("Expected primary type expression, found {}"); - pub const ExpectedExpr = SingleTokenError("Expected expression, found {}"); - pub const ExpectedPrimaryExpr = SingleTokenError("Expected primary expression, found {}"); - pub const ExpectedParamList = SingleTokenError("Expected parameter list, found {}"); - pub const ExpectedPayload = SingleTokenError("Expected loop payload, found {}"); - pub const ExpectedBlockOrAssignment = SingleTokenError("Expected block or assignment, found {}"); - pub const ExpectedBlockOrExpression = SingleTokenError("Expected block or expression, found {}"); - pub const ExpectedExprOrAssignment = SingleTokenError("Expected expression or assignment, found {}"); - pub const ExpectedPrefixExpr = SingleTokenError("Expected prefix expression, found {}"); - pub const ExpectedLoopExpr = SingleTokenError("Expected loop expression, found {}"); - pub const ExpectedDerefOrUnwrap = SingleTokenError("Expected pointer dereference or optional unwrap, found {}"); - pub const ExpectedSuffixOp = SingleTokenError("Expected pointer dereference, optional unwrap, or field access, found {}"); + pub const InvalidToken = SingleTokenError("Invalid token '{}'"); + pub const ExpectedContainerMembers = SingleTokenError("Expected test, comptime, var decl, or container field, found '{}'"); + pub const ExpectedStringLiteral = SingleTokenError("Expected string literal, found '{}'"); + pub const ExpectedIntegerLiteral = SingleTokenError("Expected integer literal, found '{}'"); + pub const ExpectedIdentifier = SingleTokenError("Expected identifier, found '{}'"); + pub const ExpectedStatement = SingleTokenError("Expected statement, found '{}'"); + pub const ExpectedVarDeclOrFn = SingleTokenError("Expected variable declaration or function, found '{}'"); + pub const ExpectedVarDecl = SingleTokenError("Expected variable declaration, found '{}'"); + pub const ExpectedReturnType = SingleTokenError("Expected 'var' or return type expression, found '{}'"); + pub const ExpectedAggregateKw = SingleTokenError("Expected '" ++ Token.Id.Keyword_struct.symbol() ++ "', '" ++ Token.Id.Keyword_union.symbol() ++ "', or '" ++ Token.Id.Keyword_enum.symbol() ++ "', found '{}'"); + pub const ExpectedEqOrSemi = SingleTokenError("Expected '=' or ';', found '{}'"); + pub const ExpectedSemiOrLBrace = SingleTokenError("Expected ';' or '{{', found '{}'"); + pub const ExpectedSemiOrElse = SingleTokenError("Expected ';' or 'else', found '{}'"); + pub const ExpectedLBrace = SingleTokenError("Expected '{{', found '{}'"); + pub const ExpectedLabelOrLBrace = SingleTokenError("Expected label or '{{', found '{}'"); + pub const ExpectedColonOrRParen = SingleTokenError("Expected ':' or ')', found '{}'"); + pub const ExpectedLabelable = SingleTokenError("Expected 'while', 'for', 'inline', 'suspend', or '{{', found '{}'"); + pub const ExpectedInlinable = SingleTokenError("Expected 'while' or 'for', found '{}'"); + pub const ExpectedAsmOutputReturnOrType = SingleTokenError("Expected '->' or '" ++ Token.Id.Identifier.symbol() ++ "', found '{}'"); + pub const ExpectedSliceOrRBracket = SingleTokenError("Expected ']' or '..', found '{}'"); + pub const ExpectedTypeExpr = SingleTokenError("Expected type expression, found '{}'"); + pub const ExpectedPrimaryTypeExpr = SingleTokenError("Expected primary type expression, found '{}'"); + pub const ExpectedExpr = SingleTokenError("Expected expression, found '{}'"); + pub const ExpectedPrimaryExpr = SingleTokenError("Expected primary expression, found '{}'"); + pub const ExpectedParamList = SingleTokenError("Expected parameter list, found '{}'"); + pub const ExpectedPayload = SingleTokenError("Expected loop payload, found '{}'"); + pub const ExpectedBlockOrAssignment = SingleTokenError("Expected block or assignment, found '{}'"); + pub const ExpectedBlockOrExpression = SingleTokenError("Expected block or expression, found '{}'"); + pub const ExpectedExprOrAssignment = SingleTokenError("Expected expression or assignment, found '{}'"); + pub const ExpectedPrefixExpr = SingleTokenError("Expected prefix expression, found '{}'"); + pub const ExpectedLoopExpr = SingleTokenError("Expected loop expression, found '{}'"); + pub const ExpectedDerefOrUnwrap = SingleTokenError("Expected pointer dereference or optional unwrap, found '{}'"); + pub const ExpectedSuffixOp = SingleTokenError("Expected pointer dereference, optional unwrap, or field access, found '{}'"); pub const ExpectedParamType = SimpleError("Expected parameter type"); pub const ExpectedPubItem = SimpleError("Pub must be followed by fn decl, var decl, or container member"); @@ -324,11 +324,11 @@ pub const Error = union(enum) { return stream.print("`&&` is invalid. Note that `and` is boolean AND."); }, .Invalid => { - return stream.print("expected {}, found invalid bytes", self.expected_id.symbol()); + return stream.print("expected '{}', found invalid bytes", self.expected_id.symbol()); }, else => { const token_name = found_token.id.symbol(); - return stream.print("expected {}, found {}", self.expected_id.symbol(), token_name); + return stream.print("expected '{}', found '{}'", self.expected_id.symbol(), token_name); }, } } @@ -340,7 +340,7 @@ pub const Error = union(enum) { pub fn render(self: *const ExpectedCommaOrEnd, tokens: *Tree.TokenList, stream: var) !void { const actual_token = tokens.at(self.token); - return stream.print("expected ',' or {}, found {}", self.end_id.symbol(), actual_token.id.symbol()); + return stream.print("expected ',' or '{}', found '{}'", self.end_id.symbol(), actual_token.id.symbol()); } }; diff --git a/std/zig/tokenizer.zig b/std/zig/tokenizer.zig index e406567976..4569a9f5a5 100644 --- a/std/zig/tokenizer.zig +++ b/std/zig/tokenizer.zig @@ -197,19 +197,19 @@ pub const Token = struct { pub fn symbol(id: Id) []const u8 { return switch (id) { - .Invalid => "[Invalid]", + .Invalid => "Invalid", .Invalid_ampersands => "&&", - .Identifier => "[Identifier]", - .StringLiteral => "[StringLiteral]", - .MultilineStringLiteralLine => "[MultilineStringLiteralLine]", - .CharLiteral => "[CharLiteral]", - .Eof => "[Eof]", - .Builtin => "[Builtin]", - .IntegerLiteral => "[IntegerLiteral]", - .FloatLiteral => "[FloatLiteral]", - .LineComment => "[LineComment]", - .DocComment => "[DocComment]", - .ShebangLine => "[ShebangLine]", + .Identifier => "Identifier", + .StringLiteral => "StringLiteral", + .MultilineStringLiteralLine => "MultilineStringLiteralLine", + .CharLiteral => "CharLiteral", + .Eof => "Eof", + .Builtin => "Builtin", + .IntegerLiteral => "IntegerLiteral", + .FloatLiteral => "FloatLiteral", + .LineComment => "LineComment", + .DocComment => "DocComment", + .ShebangLine => "ShebangLine", .Bang => "!", .Pipe => "|",