| ... | @@ -3551,58 +3551,17 @@ const Parser = struct { | ... | @@ -3551,58 +3551,17 @@ const Parser = struct { |
| 3551 | /// ParamDeclList <- (ParamDecl COMMA)* ParamDecl? | 3551 | /// ParamDeclList <- (ParamDecl COMMA)* ParamDecl? |
| 3552 | fn parseParamDeclList(p: *Parser) !SmallSpan { | 3552 | fn parseParamDeclList(p: *Parser) !SmallSpan { |
| 3553 | _ = try p.expectToken(.l_paren); | 3553 | _ = try p.expectToken(.l_paren); |
| 3554 | if (p.eatToken(.r_paren)) |_| { | | |
| 3555 | return SmallSpan{ .zero_or_one = 0 }; | | |
| 3556 | } | | |
| 3557 | const param_one = while (true) { | | |
| 3558 | const param = try p.expectParamDecl(); | | |
| 3559 | if (param != 0) break param; | | |
| 3560 | switch (p.token_tags[p.nextToken()]) { | | |
| 3561 | .comma => { | | |
| 3562 | if (p.eatToken(.r_paren)) |_| { | | |
| 3563 | return SmallSpan{ .zero_or_one = 0 }; | | |
| 3564 | } | | |
| 3565 | }, | | |
| 3566 | .r_paren => return SmallSpan{ .zero_or_one = 0 }, | | |
| 3567 | else => { | | |
| 3568 | // This is likely just a missing comma; | | |
| 3569 | // give an error but continue parsing this list. | | |
| 3570 | p.tok_i -= 1; | | |
| 3571 | try p.warnExpected(.comma); | | |
| 3572 | }, | | |
| 3573 | } | | |
| 3574 | } else unreachable; | | |
| 3575 | | | |
| 3576 | const param_two = while (true) { | | |
| 3577 | switch (p.token_tags[p.nextToken()]) { | | |
| 3578 | .comma => {}, | | |
| 3579 | .r_paren => return SmallSpan{ .zero_or_one = param_one }, | | |
| 3580 | .colon, .r_brace, .r_bracket => { | | |
| 3581 | p.tok_i -= 1; | | |
| 3582 | return p.failExpected(.r_paren); | | |
| 3583 | }, | | |
| 3584 | else => { | | |
| 3585 | // This is likely just a missing comma; | | |
| 3586 | // give an error but continue parsing this list. | | |
| 3587 | p.tok_i -= 1; | | |
| 3588 | try p.warnExpected(.comma); | | |
| 3589 | }, | | |
| 3590 | } | | |
| 3591 | if (p.eatToken(.r_paren)) |_| { | | |
| 3592 | return SmallSpan{ .zero_or_one = param_one }; | | |
| 3593 | } | | |
| 3594 | const param = try p.expectParamDecl(); | | |
| 3595 | if (param != 0) break param; | | |
| 3596 | } else unreachable; | | |
| 3597 | | | |
| 3598 | const scratch_top = p.scratch.items.len; | 3554 | const scratch_top = p.scratch.items.len; |
| 3599 | defer p.scratch.shrinkRetainingCapacity(scratch_top); | 3555 | defer p.scratch.shrinkRetainingCapacity(scratch_top); |
| 3600 | try p.scratch.appendSlice(p.gpa, &.{ param_one, param_two }); | | |
| 3601 | | | |
| 3602 | while (true) { | 3556 | while (true) { |
| | 3557 | if (p.eatToken(.r_paren)) |_| break; |
| | 3558 | const param = try p.expectParamDecl(); |
| | 3559 | if (param != 0) { |
| | 3560 | try p.scratch.append(p.gpa, param); |
| | 3561 | } |
| 3603 | switch (p.token_tags[p.nextToken()]) { | 3562 | switch (p.token_tags[p.nextToken()]) { |
| 3604 | .comma => {}, | 3563 | .comma => {}, |
| 3605 | .r_paren => return SmallSpan{ .multi = try p.listToSpan(p.scratch.items[scratch_top..]) }, | 3564 | .r_paren => break, |
| 3606 | .colon, .r_brace, .r_bracket => { | 3565 | .colon, .r_brace, .r_bracket => { |
| 3607 | p.tok_i -= 1; | 3566 | p.tok_i -= 1; |
| 3608 | return p.failExpected(.r_paren); | 3567 | return p.failExpected(.r_paren); |
| ... | @@ -3614,12 +3573,13 @@ const Parser = struct { | ... | @@ -3614,12 +3573,13 @@ const Parser = struct { |
| 3614 | try p.warnExpected(.comma); | 3573 | try p.warnExpected(.comma); |
| 3615 | }, | 3574 | }, |
| 3616 | } | 3575 | } |
| 3617 | if (p.eatToken(.r_paren)) |_| { | | |
| 3618 | return SmallSpan{ .multi = try p.listToSpan(p.scratch.items[scratch_top..]) }; | | |
| 3619 | } | | |
| 3620 | const param = try p.expectParamDecl(); | | |
| 3621 | if (param != 0) try p.scratch.append(p.gpa, param); | | |
| 3622 | } | 3576 | } |
| | 3577 | const params = p.scratch.items[scratch_top..]; |
| | 3578 | return switch (params.len) { |
| | 3579 | 0 => SmallSpan { .zero_or_one = 0 }, |
| | 3580 | 1 => SmallSpan { .zero_or_one = params[0] }, |
| | 3581 | else => SmallSpan { .multi = try p.listToSpan(params) }, |
| | 3582 | }; |
| 3623 | } | 3583 | } |
| 3624 | | 3584 | |
| 3625 | const NodeParseFn = fn (p: *Parser) Error!Node.Index; | 3585 | const NodeParseFn = fn (p: *Parser) Error!Node.Index; |