authorgravatar for git@vexu.euVeikka Tuominen <git@vexu.eu> 2022-02-16 13:19:43+02:00
committergravatar for git@vexu.euVeikka Tuominen <git@vexu.eu> 2022-02-17 14:23:42+02:00
log35e989235b29c5d921c8cf053a1d2f92fa0ce57a
tree271ec83fbfccdbc930c30023499711b0ca755d7f
parent9c36cf92f009eda14cb773e89148547dadb137c6

parser: get rid of "invalid token" error


2 files changed, 6 insertions(+), 11 deletions(-)

lib/std/zig/Ast.zig-6
...@@ -291,11 +291,6 @@ pub fn renderError(tree: Ast, parse_error: Error, stream: anytype) !void {...@@ -291,11 +291,6 @@ pub fn renderError(tree: Ast, parse_error: Error, stream: anytype) !void {
291 .invalid_bit_range => {291 .invalid_bit_range => {
292 return stream.writeAll("bit range not allowed on slices and arrays");292 return stream.writeAll("bit range not allowed on slices and arrays");
293 },293 },
294 .invalid_token => {
295 return stream.print("invalid token: '{s}'", .{
296 token_tags[parse_error.token].symbol(),
297 });
298 },
299 .same_line_doc_comment => {294 .same_line_doc_comment => {
300 return stream.writeAll("same line documentation comment");295 return stream.writeAll("same line documentation comment");
301 },296 },
...@@ -2515,7 +2510,6 @@ pub const Error = struct {...@@ -2515,7 +2510,6 @@ pub const Error = struct {
2515 extra_volatile_qualifier,2510 extra_volatile_qualifier,
2516 ptr_mod_on_array_child_type,2511 ptr_mod_on_array_child_type,
2517 invalid_bit_range,2512 invalid_bit_range,
2518 invalid_token,
2519 same_line_doc_comment,2513 same_line_doc_comment,
2520 unattached_doc_comment,2514 unattached_doc_comment,
2521 varargs_nonfinal,2515 varargs_nonfinal,
lib/std/zig/parse.zig+6-5
...@@ -1437,7 +1437,8 @@ const Parser = struct {...@@ -1437,7 +1437,8 @@ const Parser = struct {
1437 }1437 }
1438 const rhs = try p.parseExprPrecedence(info.prec + 1);1438 const rhs = try p.parseExprPrecedence(info.prec + 1);
1439 if (rhs == 0) {1439 if (rhs == 0) {
1440 return p.fail(.invalid_token);1440 try p.warn(.expected_expr);
1441 return node;
1441 }1442 }
14421443
1443 node = try p.addNode(.{1444 node = try p.addNode(.{
...@@ -1916,7 +1917,7 @@ const Parser = struct {...@@ -1916,7 +1917,7 @@ const Parser = struct {
19161917
1917 /// IfExpr <- IfPrefix Expr (KEYWORD_else Payload? Expr)?1918 /// IfExpr <- IfPrefix Expr (KEYWORD_else Payload? Expr)?
1918 fn parseIfExpr(p: *Parser) !Node.Index {1919 fn parseIfExpr(p: *Parser) !Node.Index {
1919 return p.parseIf(parseExpr);1920 return p.parseIf(expectExpr);
1920 }1921 }
19211922
1922 /// Block <- LBRACE Statement* RBRACE1923 /// Block <- LBRACE Statement* RBRACE
...@@ -2384,7 +2385,7 @@ const Parser = struct {...@@ -2384,7 +2385,7 @@ const Parser = struct {
23842385
2385 .builtin => return p.parseBuiltinCall(),2386 .builtin => return p.parseBuiltinCall(),
2386 .keyword_fn => return p.parseFnProto(),2387 .keyword_fn => return p.parseFnProto(),
2387 .keyword_if => return p.parseIf(parseTypeExpr),2388 .keyword_if => return p.parseIf(expectTypeExpr),
2388 .keyword_switch => return p.expectSwitchExpr(),2389 .keyword_switch => return p.expectSwitchExpr(),
23892390
2390 .keyword_extern,2391 .keyword_extern,
...@@ -3577,7 +3578,7 @@ const Parser = struct {...@@ -3577,7 +3578,7 @@ const Parser = struct {
3577 _ = try p.parsePtrPayload();3578 _ = try p.parsePtrPayload();
35783579
3579 const then_expr = try bodyParseFn(p);3580 const then_expr = try bodyParseFn(p);
3580 if (then_expr == 0) return p.fail(.invalid_token);3581 assert(then_expr != 0);
35813582
3582 _ = p.eatToken(.keyword_else) orelse return p.addNode(.{3583 _ = p.eatToken(.keyword_else) orelse return p.addNode(.{
3583 .tag = .if_simple,3584 .tag = .if_simple,
...@@ -3589,7 +3590,7 @@ const Parser = struct {...@@ -3589,7 +3590,7 @@ const Parser = struct {
3589 });3590 });
3590 _ = try p.parsePayload();3591 _ = try p.parsePayload();
3591 const else_expr = try bodyParseFn(p);3592 const else_expr = try bodyParseFn(p);
3592 if (else_expr == 0) return p.fail(.invalid_token);3593 assert(then_expr != 0);
35933594
3594 return p.addNode(.{3595 return p.addNode(.{
3595 .tag = .@"if",3596 .tag = .@"if",