| author | |
| committer | |
| log | cd3068b4eb78d0820e35779ee1531e27c255ddf7 |
| tree | f32fbbc99b1a4c31bf0c416e212b357f0bb4d82f |
| parent | 3b297f58f70c72fb57cdc46a681db4e99abd34b5 |
| parent | 23ee619fc5ae43a9ca116fa4fa956759dd74e977 |
| signature |
Update stage2 parser errors to match compiler friendliness2 files changed, 164 insertions(+), 40 deletions(-)
std/zig/ast.zig+40-40| ... | ... | @@ -255,39 +255,39 @@ pub const Error = union(enum) { |
| 255 | 255 | } |
| 256 | 256 | } |
| 257 | 257 | |
| 258 | pub const InvalidToken = SingleTokenError("Invalid token {}"); | |
| 259 | pub const ExpectedContainerMembers = SingleTokenError("Expected test, comptime, var decl, or container field, found {}"); | |
| 260 | pub const ExpectedStringLiteral = SingleTokenError("Expected string literal, found {}"); | |
| 261 | pub const ExpectedIntegerLiteral = SingleTokenError("Expected integer literal, found {}"); | |
| 262 | pub const ExpectedIdentifier = SingleTokenError("Expected identifier, found {}"); | |
| 263 | pub const ExpectedStatement = SingleTokenError("Expected statement, found {}"); | |
| 264 | pub const ExpectedVarDeclOrFn = SingleTokenError("Expected variable declaration or function, found {}"); | |
| 265 | pub const ExpectedVarDecl = SingleTokenError("Expected variable declaration, found {}"); | |
| 266 | pub const ExpectedReturnType = SingleTokenError("Expected 'var' or return type expression, found {}"); | |
| 267 | pub const ExpectedAggregateKw = SingleTokenError("Expected " ++ @tagName(Token.Id.Keyword_struct) ++ ", " ++ @tagName(Token.Id.Keyword_union) ++ ", or " ++ @tagName(Token.Id.Keyword_enum) ++ ", found {}"); | |
| 268 | pub const ExpectedEqOrSemi = SingleTokenError("Expected '=' or ';', found {}"); | |
| 269 | pub const ExpectedSemiOrLBrace = SingleTokenError("Expected ';' or '{{', found {}"); | |
| 270 | pub const ExpectedSemiOrElse = SingleTokenError("Expected ';' or 'else', found {}"); | |
| 271 | pub const ExpectedLBrace = SingleTokenError("Expected '{{', found {}"); | |
| 272 | pub const ExpectedLabelOrLBrace = SingleTokenError("Expected label or '{{', found {}"); | |
| 273 | pub const ExpectedColonOrRParen = SingleTokenError("Expected ':' or ')', found {}"); | |
| 274 | pub const ExpectedLabelable = SingleTokenError("Expected 'while', 'for', 'inline', 'suspend', or '{{', found {}"); | |
| 275 | pub const ExpectedInlinable = SingleTokenError("Expected 'while' or 'for', found {}"); | |
| 276 | pub const ExpectedAsmOutputReturnOrType = SingleTokenError("Expected '->' or " ++ @tagName(Token.Id.Identifier) ++ ", found {}"); | |
| 277 | pub const ExpectedSliceOrRBracket = SingleTokenError("Expected ']' or '..', found {}"); | |
| 278 | pub const ExpectedTypeExpr = SingleTokenError("Expected type expression, found {}"); | |
| 279 | pub const ExpectedPrimaryTypeExpr = SingleTokenError("Expected primary type expression, found {}"); | |
| 280 | pub const ExpectedExpr = SingleTokenError("Expected expression, found {}"); | |
| 281 | pub const ExpectedPrimaryExpr = SingleTokenError("Expected primary expression, found {}"); | |
| 282 | pub const ExpectedParamList = SingleTokenError("Expected parameter list, found {}"); | |
| 283 | pub const ExpectedPayload = SingleTokenError("Expected loop payload, found {}"); | |
| 284 | pub const ExpectedBlockOrAssignment = SingleTokenError("Expected block or assignment, found {}"); | |
| 285 | pub const ExpectedBlockOrExpression = SingleTokenError("Expected block or expression, found {}"); | |
| 286 | pub const ExpectedExprOrAssignment = SingleTokenError("Expected expression or assignment, found {}"); | |
| 287 | pub const ExpectedPrefixExpr = SingleTokenError("Expected prefix expression, found {}"); | |
| 288 | pub const ExpectedLoopExpr = SingleTokenError("Expected loop expression, found {}"); | |
| 289 | pub const ExpectedDerefOrUnwrap = SingleTokenError("Expected pointer dereference or optional unwrap, found {}"); | |
| 290 | pub const ExpectedSuffixOp = SingleTokenError("Expected pointer dereference, optional unwrap, or field access, found {}"); | |
| 258 | pub const InvalidToken = SingleTokenError("Invalid token '{}'"); | |
| 259 | pub const ExpectedContainerMembers = SingleTokenError("Expected test, comptime, var decl, or container field, found '{}'"); | |
| 260 | pub const ExpectedStringLiteral = SingleTokenError("Expected string literal, found '{}'"); | |
| 261 | pub const ExpectedIntegerLiteral = SingleTokenError("Expected integer literal, found '{}'"); | |
| 262 | pub const ExpectedIdentifier = SingleTokenError("Expected identifier, found '{}'"); | |
| 263 | pub const ExpectedStatement = SingleTokenError("Expected statement, found '{}'"); | |
| 264 | pub const ExpectedVarDeclOrFn = SingleTokenError("Expected variable declaration or function, found '{}'"); | |
| 265 | pub const ExpectedVarDecl = SingleTokenError("Expected variable declaration, found '{}'"); | |
| 266 | pub const ExpectedReturnType = SingleTokenError("Expected 'var' or return type expression, found '{}'"); | |
| 267 | pub const ExpectedAggregateKw = SingleTokenError("Expected '" ++ Token.Id.Keyword_struct.symbol() ++ "', '" ++ Token.Id.Keyword_union.symbol() ++ "', or '" ++ Token.Id.Keyword_enum.symbol() ++ "', found '{}'"); | |
| 268 | pub const ExpectedEqOrSemi = SingleTokenError("Expected '=' or ';', found '{}'"); | |
| 269 | pub const ExpectedSemiOrLBrace = SingleTokenError("Expected ';' or '{{', found '{}'"); | |
| 270 | pub const ExpectedSemiOrElse = SingleTokenError("Expected ';' or 'else', found '{}'"); | |
| 271 | pub const ExpectedLBrace = SingleTokenError("Expected '{{', found '{}'"); | |
| 272 | pub const ExpectedLabelOrLBrace = SingleTokenError("Expected label or '{{', found '{}'"); | |
| 273 | pub const ExpectedColonOrRParen = SingleTokenError("Expected ':' or ')', found '{}'"); | |
| 274 | pub const ExpectedLabelable = SingleTokenError("Expected 'while', 'for', 'inline', 'suspend', or '{{', found '{}'"); | |
| 275 | pub const ExpectedInlinable = SingleTokenError("Expected 'while' or 'for', found '{}'"); | |
| 276 | pub const ExpectedAsmOutputReturnOrType = SingleTokenError("Expected '->' or '" ++ Token.Id.Identifier.symbol() ++ "', found '{}'"); | |
| 277 | pub const ExpectedSliceOrRBracket = SingleTokenError("Expected ']' or '..', found '{}'"); | |
| 278 | pub const ExpectedTypeExpr = SingleTokenError("Expected type expression, found '{}'"); | |
| 279 | pub const ExpectedPrimaryTypeExpr = SingleTokenError("Expected primary type expression, found '{}'"); | |
| 280 | pub const ExpectedExpr = SingleTokenError("Expected expression, found '{}'"); | |
| 281 | pub const ExpectedPrimaryExpr = SingleTokenError("Expected primary expression, found '{}'"); | |
| 282 | pub const ExpectedParamList = SingleTokenError("Expected parameter list, found '{}'"); | |
| 283 | pub const ExpectedPayload = SingleTokenError("Expected loop payload, found '{}'"); | |
| 284 | pub const ExpectedBlockOrAssignment = SingleTokenError("Expected block or assignment, found '{}'"); | |
| 285 | pub const ExpectedBlockOrExpression = SingleTokenError("Expected block or expression, found '{}'"); | |
| 286 | pub const ExpectedExprOrAssignment = SingleTokenError("Expected expression or assignment, found '{}'"); | |
| 287 | pub const ExpectedPrefixExpr = SingleTokenError("Expected prefix expression, found '{}'"); | |
| 288 | pub const ExpectedLoopExpr = SingleTokenError("Expected loop expression, found '{}'"); | |
| 289 | pub const ExpectedDerefOrUnwrap = SingleTokenError("Expected pointer dereference or optional unwrap, found '{}'"); | |
| 290 | pub const ExpectedSuffixOp = SingleTokenError("Expected pointer dereference, optional unwrap, or field access, found '{}'"); | |
| 291 | 291 | |
| 292 | 292 | pub const ExpectedParamType = SimpleError("Expected parameter type"); |
| 293 | 293 | 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) { |
| 324 | 324 | return stream.print("`&&` is invalid. Note that `and` is boolean AND."); |
| 325 | 325 | }, |
| 326 | 326 | .Invalid => { |
| 327 | return stream.print("expected {}, found invalid bytes", @tagName(self.expected_id)); | |
| 327 | return stream.print("expected '{}', found invalid bytes", self.expected_id.symbol()); | |
| 328 | 328 | }, |
| 329 | 329 | else => { |
| 330 | const token_name = @tagName(found_token.id); | |
| 331 | return stream.print("expected {}, found {}", @tagName(self.expected_id), token_name); | |
| 330 | const token_name = found_token.id.symbol(); | |
| 331 | return stream.print("expected '{}', found '{}'", self.expected_id.symbol(), token_name); | |
| 332 | 332 | }, |
| 333 | 333 | } |
| 334 | 334 | } |
| ... | ... | @@ -339,8 +339,8 @@ pub const Error = union(enum) { |
| 339 | 339 | end_id: Token.Id, |
| 340 | 340 | |
| 341 | 341 | pub fn render(self: *const ExpectedCommaOrEnd, tokens: *Tree.TokenList, stream: var) !void { |
| 342 | const token_name = @tagName(tokens.at(self.token).id); | |
| 343 | return stream.print("expected ',' or {}, found {}", @tagName(self.end_id), token_name); | |
| 342 | const actual_token = tokens.at(self.token); | |
| 343 | return stream.print("expected ',' or '{}', found '{}'", self.end_id.symbol(), actual_token.id.symbol()); | |
| 344 | 344 | } |
| 345 | 345 | }; |
| 346 | 346 | |
| ... | ... | @@ -351,8 +351,8 @@ pub const Error = union(enum) { |
| 351 | 351 | token: TokenIndex, |
| 352 | 352 | |
| 353 | 353 | pub fn render(self: *const ThisError, tokens: *Tree.TokenList, stream: var) !void { |
| 354 | const token_name = @tagName(tokens.at(self.token).id); | |
| 355 | return stream.print(msg, token_name); | |
| 354 | const actual_token = tokens.at(self.token); | |
| 355 | return stream.print(msg, actual_token.id.symbol()); | |
| 356 | 356 | } |
| 357 | 357 | }; |
| 358 | 358 | } |
std/zig/tokenizer.zig+124| ... | ... | @@ -196,6 +196,130 @@ pub const Token = struct { |
| 196 | 196 | Keyword_var, |
| 197 | 197 | Keyword_volatile, |
| 198 | 198 | Keyword_while, |
| 199 | ||
| 200 | pub fn symbol(id: Id) []const u8 { | |
| 201 | return switch (id) { | |
| 202 | .Invalid => "Invalid", | |
| 203 | .Invalid_ampersands => "&&", | |
| 204 | .Identifier => "Identifier", | |
| 205 | .StringLiteral => "StringLiteral", | |
| 206 | .MultilineStringLiteralLine => "MultilineStringLiteralLine", | |
| 207 | .CharLiteral => "CharLiteral", | |
| 208 | .Eof => "Eof", | |
| 209 | .Builtin => "Builtin", | |
| 210 | .IntegerLiteral => "IntegerLiteral", | |
| 211 | .FloatLiteral => "FloatLiteral", | |
| 212 | .LineComment => "LineComment", | |
| 213 | .DocComment => "DocComment", | |
| 214 | .ShebangLine => "ShebangLine", | |
| 215 | ||
| 216 | .Bang => "!", | |
| 217 | .Pipe => "|", | |
| 218 | .PipePipe => "||", | |
| 219 | .PipeEqual => "|=", | |
| 220 | .Equal => "=", | |
| 221 | .EqualEqual => "==", | |
| 222 | .EqualAngleBracketRight => "=>", | |
| 223 | .BangEqual => "!=", | |
| 224 | .LParen => "(", | |
| 225 | .RParen => ")", | |
| 226 | .Semicolon => ";", | |
| 227 | .Percent => "%", | |
| 228 | .PercentEqual => "%=", | |
| 229 | .LBrace => "{", | |
| 230 | .RBrace => "}", | |
| 231 | .LBracket => "[", | |
| 232 | .RBracket => "]", | |
| 233 | .Period => ".", | |
| 234 | .Ellipsis2 => "..", | |
| 235 | .Ellipsis3 => "...", | |
| 236 | .Caret => "^", | |
| 237 | .CaretEqual => "^=", | |
| 238 | .Plus => "+", | |
| 239 | .PlusPlus => "++", | |
| 240 | .PlusEqual => "+=", | |
| 241 | .PlusPercent => "+%", | |
| 242 | .PlusPercentEqual => "+%=", | |
| 243 | .Minus => "-", | |
| 244 | .MinusEqual => "-=", | |
| 245 | .MinusPercent => "-%", | |
| 246 | .MinusPercentEqual => "-%=", | |
| 247 | .Asterisk => "*", | |
| 248 | .AsteriskEqual => "*=", | |
| 249 | .AsteriskAsterisk => "**", | |
| 250 | .AsteriskPercent => "*%", | |
| 251 | .AsteriskPercentEqual => "*%=", | |
| 252 | .Arrow => "->", | |
| 253 | .Colon => ":", | |
| 254 | .Slash => "/", | |
| 255 | .SlashEqual => "/=", | |
| 256 | .Comma => ",", | |
| 257 | .Ampersand => "&", | |
| 258 | .AmpersandEqual => "&=", | |
| 259 | .QuestionMark => "?", | |
| 260 | .AngleBracketLeft => "<", | |
| 261 | .AngleBracketLeftEqual => "<=", | |
| 262 | .AngleBracketAngleBracketLeft => "<<", | |
| 263 | .AngleBracketAngleBracketLeftEqual => "<<=", | |
| 264 | .AngleBracketRight => ">", | |
| 265 | .AngleBracketRightEqual => ">=", | |
| 266 | .AngleBracketAngleBracketRight => ">>", | |
| 267 | .AngleBracketAngleBracketRightEqual => ">>=", | |
| 268 | .Tilde => "~", | |
| 269 | .BracketStarBracket => "[*]", | |
| 270 | .BracketStarCBracket => "[*c]", | |
| 271 | .Keyword_align => "align", | |
| 272 | .Keyword_allowzero => "allowzero", | |
| 273 | .Keyword_and => "and", | |
| 274 | .Keyword_asm => "asm", | |
| 275 | .Keyword_async => "async", | |
| 276 | .Keyword_await => "await", | |
| 277 | .Keyword_break => "break", | |
| 278 | .Keyword_cancel => "cancel", | |
| 279 | .Keyword_catch => "catch", | |
| 280 | .Keyword_comptime => "comptime", | |
| 281 | .Keyword_const => "const", | |
| 282 | .Keyword_continue => "continue", | |
| 283 | .Keyword_defer => "defer", | |
| 284 | .Keyword_else => "else", | |
| 285 | .Keyword_enum => "enum", | |
| 286 | .Keyword_errdefer => "errdefer", | |
| 287 | .Keyword_error => "error", | |
| 288 | .Keyword_export => "export", | |
| 289 | .Keyword_extern => "extern", | |
| 290 | .Keyword_false => "false", | |
| 291 | .Keyword_fn => "fn", | |
| 292 | .Keyword_for => "for", | |
| 293 | .Keyword_if => "if", | |
| 294 | .Keyword_inline => "inline", | |
| 295 | .Keyword_nakedcc => "nakedcc", | |
| 296 | .Keyword_noalias => "noalias", | |
| 297 | .Keyword_null => "null", | |
| 298 | .Keyword_or => "or", | |
| 299 | .Keyword_orelse => "orelse", | |
| 300 | .Keyword_packed => "packed", | |
| 301 | .Keyword_promise => "promise", | |
| 302 | .Keyword_pub => "pub", | |
| 303 | .Keyword_resume => "resume", | |
| 304 | .Keyword_return => "return", | |
| 305 | .Keyword_linksection => "linksection", | |
| 306 | .Keyword_stdcallcc => "stdcallcc", | |
| 307 | .Keyword_struct => "struct", | |
| 308 | .Keyword_suspend => "suspend", | |
| 309 | .Keyword_switch => "switch", | |
| 310 | .Keyword_test => "test", | |
| 311 | .Keyword_threadlocal => "threadlocal", | |
| 312 | .Keyword_true => "true", | |
| 313 | .Keyword_try => "try", | |
| 314 | .Keyword_undefined => "undefined", | |
| 315 | .Keyword_union => "union", | |
| 316 | .Keyword_unreachable => "unreachable", | |
| 317 | .Keyword_usingnamespace => "usingnamespace", | |
| 318 | .Keyword_var => "var", | |
| 319 | .Keyword_volatile => "volatile", | |
| 320 | .Keyword_while => "while", | |
| 321 | }; | |
| 322 | } | |
| 199 | 323 | }; |
| 200 | 324 | }; |
| 201 | 325 |