| ... | @@ -302,13 +302,13 @@ static void ast_parse_param_decl_list(ParseContext *pc, size_t *token_index, | ... | @@ -302,13 +302,13 @@ static void ast_parse_param_decl_list(ParseContext *pc, size_t *token_index, |
| 302 | | 302 | |
| 303 | ast_eat_token(pc, token_index, TokenIdLParen); | 303 | ast_eat_token(pc, token_index, TokenIdLParen); |
| 304 | | 304 | |
| 305 | Token *token = &pc->tokens->at(*token_index); | | |
| 306 | if (token->id == TokenIdRParen) { | | |
| 307 | *token_index += 1; | | |
| 308 | return; | | |
| 309 | } | | |
| 310 | | | |
| 311 | for (;;) { | 305 | for (;;) { |
| | 306 | Token *token = &pc->tokens->at(*token_index); |
| | 307 | if (token->id == TokenIdRParen) { |
| | 308 | *token_index += 1; |
| | 309 | return; |
| | 310 | } |
| | 311 | |
| 312 | AstNode *param_decl_node = ast_parse_param_decl(pc, token_index); | 312 | AstNode *param_decl_node = ast_parse_param_decl(pc, token_index); |
| 313 | bool expect_end = false; | 313 | bool expect_end = false; |
| 314 | assert(param_decl_node); | 314 | assert(param_decl_node); |
| ... | @@ -316,31 +316,33 @@ static void ast_parse_param_decl_list(ParseContext *pc, size_t *token_index, | ... | @@ -316,31 +316,33 @@ static void ast_parse_param_decl_list(ParseContext *pc, size_t *token_index, |
| 316 | expect_end = param_decl_node->data.param_decl.is_var_args; | 316 | expect_end = param_decl_node->data.param_decl.is_var_args; |
| 317 | *is_var_args = expect_end; | 317 | *is_var_args = expect_end; |
| 318 | | 318 | |
| 319 | Token *token = &pc->tokens->at(*token_index); | 319 | token = &pc->tokens->at(*token_index); |
| 320 | *token_index += 1; | 320 | *token_index += 1; |
| 321 | if (token->id == TokenIdRParen) { | 321 | if (token->id == TokenIdRParen) { |
| 322 | return; | 322 | return; |
| 323 | } else if (expect_end) { | | |
| 324 | ast_invalid_token_error(pc, token); | | |
| 325 | } else { | 323 | } else { |
| 326 | ast_expect_token(pc, token, TokenIdComma); | 324 | ast_expect_token(pc, token, TokenIdComma); |
| | 325 | if (expect_end) { |
| | 326 | ast_eat_token(pc, token_index, TokenIdRParen); |
| | 327 | return; |
| | 328 | } |
| 327 | } | 329 | } |
| 328 | } | 330 | } |
| 329 | zig_unreachable(); | 331 | zig_unreachable(); |
| 330 | } | 332 | } |
| 331 | | 333 | |
| 332 | static void ast_parse_fn_call_param_list(ParseContext *pc, size_t *token_index, ZigList<AstNode*> *params) { | 334 | static void ast_parse_fn_call_param_list(ParseContext *pc, size_t *token_index, ZigList<AstNode*> *params) { |
| 333 | Token *token = &pc->tokens->at(*token_index); | | |
| 334 | if (token->id == TokenIdRParen) { | | |
| 335 | *token_index += 1; | | |
| 336 | return; | | |
| 337 | } | | |
| 338 | | | |
| 339 | for (;;) { | 335 | for (;;) { |
| | 336 | Token *token = &pc->tokens->at(*token_index); |
| | 337 | if (token->id == TokenIdRParen) { |
| | 338 | *token_index += 1; |
| | 339 | return; |
| | 340 | } |
| | 341 | |
| 340 | AstNode *expr = ast_parse_expression(pc, token_index, true); | 342 | AstNode *expr = ast_parse_expression(pc, token_index, true); |
| 341 | params->append(expr); | 343 | params->append(expr); |
| 342 | | 344 | |
| 343 | Token *token = &pc->tokens->at(*token_index); | 345 | token = &pc->tokens->at(*token_index); |
| 344 | *token_index += 1; | 346 | *token_index += 1; |
| 345 | if (token->id == TokenIdRParen) { | 347 | if (token->id == TokenIdRParen) { |
| 346 | return; | 348 | return; |
| ... | @@ -482,7 +484,13 @@ static void ast_parse_asm_clobbers(ParseContext *pc, size_t *token_index, AstNod | ... | @@ -482,7 +484,13 @@ static void ast_parse_asm_clobbers(ParseContext *pc, size_t *token_index, AstNod |
| 482 | | 484 | |
| 483 | if (comma->id == TokenIdComma) { | 485 | if (comma->id == TokenIdComma) { |
| 484 | *token_index += 1; | 486 | *token_index += 1; |
| 485 | continue; | 487 | |
| | 488 | Token *token = &pc->tokens->at(*token_index); |
| | 489 | if (token->id == TokenIdRParen) { |
| | 490 | break; |
| | 491 | } else { |
| | 492 | continue; |
| | 493 | } |
| 486 | } else { | 494 | } else { |
| 487 | break; | 495 | break; |
| 488 | } | 496 | } |
| ... | @@ -513,7 +521,13 @@ static void ast_parse_asm_input(ParseContext *pc, size_t *token_index, AstNode * | ... | @@ -513,7 +521,13 @@ static void ast_parse_asm_input(ParseContext *pc, size_t *token_index, AstNode * |
| 513 | | 521 | |
| 514 | if (comma->id == TokenIdComma) { | 522 | if (comma->id == TokenIdComma) { |
| 515 | *token_index += 1; | 523 | *token_index += 1; |
| 516 | continue; | 524 | |
| | 525 | Token *token = &pc->tokens->at(*token_index); |
| | 526 | if (token->id == TokenIdColon || token->id == TokenIdRParen) { |
| | 527 | break; |
| | 528 | } else { |
| | 529 | continue; |
| | 530 | } |
| 517 | } else { | 531 | } else { |
| 518 | break; | 532 | break; |
| 519 | } | 533 | } |
| ... | @@ -546,7 +560,13 @@ static void ast_parse_asm_output(ParseContext *pc, size_t *token_index, AstNode | ... | @@ -546,7 +560,13 @@ static void ast_parse_asm_output(ParseContext *pc, size_t *token_index, AstNode |
| 546 | | 560 | |
| 547 | if (comma->id == TokenIdComma) { | 561 | if (comma->id == TokenIdComma) { |
| 548 | *token_index += 1; | 562 | *token_index += 1; |
| 549 | continue; | 563 | |
| | 564 | Token *token = &pc->tokens->at(*token_index); |
| | 565 | if (token->id == TokenIdColon || token->id == TokenIdRParen) { |
| | 566 | break; |
| | 567 | } else { |
| | 568 | continue; |
| | 569 | } |
| 550 | } else { | 570 | } else { |
| 551 | break; | 571 | break; |
| 552 | } | 572 | } |
| ... | @@ -1783,7 +1803,13 @@ static AstNode *ast_parse_switch_expr(ParseContext *pc, size_t *token_index, boo | ... | @@ -1783,7 +1803,13 @@ static AstNode *ast_parse_switch_expr(ParseContext *pc, size_t *token_index, boo |
| 1783 | Token *comma_tok = &pc->tokens->at(*token_index); | 1803 | Token *comma_tok = &pc->tokens->at(*token_index); |
| 1784 | if (comma_tok->id == TokenIdComma) { | 1804 | if (comma_tok->id == TokenIdComma) { |
| 1785 | *token_index += 1; | 1805 | *token_index += 1; |
| 1786 | continue; | 1806 | |
| | 1807 | Token *token = &pc->tokens->at(*token_index); |
| | 1808 | if (token->id == TokenIdFatArrow) { |
| | 1809 | break; |
| | 1810 | } else { |
| | 1811 | continue; |
| | 1812 | } |
| 1787 | } | 1813 | } |
| 1788 | break; | 1814 | break; |
| 1789 | } | 1815 | } |
| ... | @@ -1812,7 +1838,15 @@ static AstNode *ast_parse_switch_expr(ParseContext *pc, size_t *token_index, boo | ... | @@ -1812,7 +1838,15 @@ static AstNode *ast_parse_switch_expr(ParseContext *pc, size_t *token_index, boo |
| 1812 | } | 1838 | } |
| 1813 | | 1839 | |
| 1814 | prong_node->data.switch_prong.expr = ast_parse_expression(pc, token_index, true); | 1840 | prong_node->data.switch_prong.expr = ast_parse_expression(pc, token_index, true); |
| 1815 | ast_eat_token(pc, token_index, TokenIdComma); | 1841 | |
| | 1842 | Token *trailing_token = &pc->tokens->at(*token_index); |
| | 1843 | if (trailing_token->id == TokenIdRBrace) { |
| | 1844 | *token_index += 1; |
| | 1845 | |
| | 1846 | return node; |
| | 1847 | } else { |
| | 1848 | ast_eat_token(pc, token_index, TokenIdComma); |
| | 1849 | } |
| 1816 | | 1850 | |
| 1817 | } | 1851 | } |
| 1818 | } | 1852 | } |
| ... | @@ -2364,17 +2398,28 @@ static AstNode *ast_parse_container_decl(ParseContext *pc, size_t *token_index, | ... | @@ -2364,17 +2398,28 @@ static AstNode *ast_parse_container_decl(ParseContext *pc, size_t *token_index, |
| 2364 | field_node->data.struct_field.visib_mod = visib_mod; | 2398 | field_node->data.struct_field.visib_mod = visib_mod; |
| 2365 | field_node->data.struct_field.name = token_buf(token); | 2399 | field_node->data.struct_field.name = token_buf(token); |
| 2366 | | 2400 | |
| 2367 | Token *expr_or_comma = &pc->tokens->at(*token_index); | 2401 | Token *token = &pc->tokens->at(*token_index); |
| 2368 | if (expr_or_comma->id == TokenIdComma) { | 2402 | if (token->id == TokenIdComma || token->id == TokenIdRBrace) { |
| 2369 | field_node->data.struct_field.type = ast_create_void_type_node(pc, expr_or_comma); | 2403 | field_node->data.struct_field.type = ast_create_void_type_node(pc, token); |
| 2370 | *token_index += 1; | 2404 | *token_index += 1; |
| | 2405 | node->data.container_decl.fields.append(field_node); |
| | 2406 | |
| | 2407 | if (token->id == TokenIdRBrace) { |
| | 2408 | break; |
| | 2409 | } |
| 2371 | } else { | 2410 | } else { |
| 2372 | ast_eat_token(pc, token_index, TokenIdColon); | 2411 | ast_eat_token(pc, token_index, TokenIdColon); |
| 2373 | field_node->data.struct_field.type = ast_parse_expression(pc, token_index, true); | 2412 | field_node->data.struct_field.type = ast_parse_expression(pc, token_index, true); |
| 2374 | ast_eat_token(pc, token_index, TokenIdComma); | 2413 | node->data.container_decl.fields.append(field_node); |
| 2375 | } | | |
| 2376 | | 2414 | |
| 2377 | node->data.container_decl.fields.append(field_node); | 2415 | Token *token = &pc->tokens->at(*token_index); |
| | 2416 | if (token->id == TokenIdRBrace) { |
| | 2417 | *token_index += 1; |
| | 2418 | break; |
| | 2419 | } else { |
| | 2420 | ast_eat_token(pc, token_index, TokenIdComma); |
| | 2421 | } |
| | 2422 | } |
| 2378 | } else { | 2423 | } else { |
| 2379 | ast_invalid_token_error(pc, token); | 2424 | ast_invalid_token_error(pc, token); |
| 2380 | } | 2425 | } |