authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2016-01-15 17:40:12-07:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2016-01-15 17:40:12-07:00
log0311b35a21e9896772cb982750be680b0ef71f1f
tree11ad9a19e13d0a4c4f6fd7853a3a0b25f2eb282b
parent74b1665586bafe0fcd063480b9480a77cbf93ab2

reduce precedence of {} suffix operator

this makes []u8 {1, 2, 3, 4} work for array literal

2 files changed, 104 insertions(+), 84 deletions(-)

doc/langref.md+13-11
...@@ -34,7 +34,7 @@ Root : many(TopLevelDecl) token(EOF)...@@ -34,7 +34,7 @@ Root : many(TopLevelDecl) token(EOF)
3434
35TopLevelDecl : FnDef | ExternBlock | RootExportDecl | Use | ContainerDecl | VariableDeclaration35TopLevelDecl : FnDef | ExternBlock | RootExportDecl | Use | ContainerDecl | VariableDeclaration
3636
37VariableDeclaration : option(FnVisibleMod) (token(Var) | token(Const)) token(Symbol) (token(Eq) Expression | token(Colon) UnwrapMaybeExpression option(token(Eq) Expression))37VariableDeclaration : option(FnVisibleMod) (token(Var) | token(Const)) token(Symbol) (token(Eq) Expression | token(Colon) PrefixOpExpression option(token(Eq) Expression))
3838
39ContainerDecl : many(Directive) option(FnVisibleMod) (token(Struct) | token(Enum)) token(Symbol) token(LBrace) many(StructMember) token(RBrace)39ContainerDecl : many(Directive) option(FnVisibleMod) (token(Struct) | token(Enum)) token(Symbol) token(LBrace) many(StructMember) token(RBrace)
4040
...@@ -48,7 +48,7 @@ RootExportDecl : many(Directive) token(Export) token(Symbol) token(String) token...@@ -48,7 +48,7 @@ RootExportDecl : many(Directive) token(Export) token(Symbol) token(String) token
4848
49ExternBlock : many(Directive) token(Extern) token(LBrace) many(FnDecl) token(RBrace)49ExternBlock : many(Directive) token(Extern) token(LBrace) many(FnDecl) token(RBrace)
5050
51FnProto : many(Directive) option(FnVisibleMod) token(Fn) token(Symbol) ParamDeclList option(UnwrapMaybeExpression)51FnProto : many(Directive) option(FnVisibleMod) token(Fn) token(Symbol) ParamDeclList option(PrefixOpExpression)
5252
53Directive : token(NumberSign) token(Symbol) token(LParen) token(String) token(RParen)53Directive : token(NumberSign) token(Symbol) token(LParen) token(String) token(RParen)
5454
...@@ -60,7 +60,7 @@ FnDef : FnProto token(FatArrow) Block...@@ -60,7 +60,7 @@ FnDef : FnProto token(FatArrow) Block
6060
61ParamDeclList : token(LParen) list(ParamDecl, token(Comma)) token(RParen)61ParamDeclList : token(LParen) list(ParamDecl, token(Comma)) token(RParen)
6262
63ParamDecl : option(token(NoAlias)) token(Symbol) token(Colon) UnwrapMaybeExpression | token(Ellipsis)63ParamDecl : option(token(NoAlias)) token(Symbol) token(Colon) PrefixOpExpression | token(Ellipsis)
6464
65Block : token(LBrace) list(option(Statement), token(Semicolon)) token(RBrace)65Block : token(LBrace) list(option(Statement), token(Semicolon)) token(RBrace)
6666
...@@ -78,7 +78,7 @@ AsmOutput : token(Colon) list(AsmOutputItem, token(Comma)) option(AsmInput)...@@ -78,7 +78,7 @@ AsmOutput : token(Colon) list(AsmOutputItem, token(Comma)) option(AsmInput)
7878
79AsmInput : token(Colon) list(AsmInputItem, token(Comma)) option(AsmClobbers)79AsmInput : token(Colon) list(AsmInputItem, token(Comma)) option(AsmClobbers)
8080
81AsmOutputItem : token(LBracket) token(Symbol) token(RBracket) token(String) token(LParen) (token(Symbol) | token(Arrow) UnwrapMaybeExpression) token(RParen)81AsmOutputItem : token(LBracket) token(Symbol) token(RBracket) token(String) token(LParen) (token(Symbol) | token(Arrow) PrefixOpExpression) token(RParen)
8282
83AsmInputItem : token(LBracket) token(Symbol) token(RBracket) token(String) token(LParen) Expression token(RParen)83AsmInputItem : token(LBracket) token(Symbol) token(RBracket) token(String) token(LParen) Expression token(RParen)
8484
...@@ -102,7 +102,7 @@ IfExpression : IfVarExpression | IfBoolExpression...@@ -102,7 +102,7 @@ IfExpression : IfVarExpression | IfBoolExpression
102102
103IfBoolExpression : token(If) token(LParen) Expression token(RParen) Expression option(Else)103IfBoolExpression : token(If) token(LParen) Expression token(RParen) Expression option(Else)
104104
105IfVarExpression : token(If) token(LParen) (token(Const) | token(Var)) token(Symbol) option(token(Colon) UnwrapMaybeExpression) Token(MaybeAssign) Expression token(RParen) Expression Option(Else)105IfVarExpression : token(If) token(LParen) (token(Const) | token(Var)) token(Symbol) option(token(Colon) PrefixOpExpression) Token(MaybeAssign) Expression token(RParen) Expression Option(Else)
106106
107Else : token(Else) Expression107Else : token(Else) Expression
108108
...@@ -126,13 +126,15 @@ AdditionExpression : MultiplyExpression AdditionOperator AdditionExpression | Mu...@@ -126,13 +126,15 @@ AdditionExpression : MultiplyExpression AdditionOperator AdditionExpression | Mu
126126
127AdditionOperator : token(Plus) | token(Minus)127AdditionOperator : token(Plus) | token(Minus)
128128
129MultiplyExpression : PrefixOpExpression MultiplyOperator MultiplyExpression | PrefixOpExpression129MultiplyExpression : CurlySuffixExpression MultiplyOperator MultiplyExpression | CurlySuffixExpression
130
131CurlySuffixExpression : PrefixOpExpression option(ContainerInitExpression)
130132
131MultiplyOperator : token(Star) | token(Slash) | token(Percent)133MultiplyOperator : token(Star) | token(Slash) | token(Percent)
132134
133PrefixOpExpression : PrefixOp PrefixOpExpression | SuffixOpExpression135PrefixOpExpression : PrefixOp PrefixOpExpression | SuffixOpExpression
134136
135SuffixOpExpression : PrimaryExpression option(FnCallExpression | ArrayAccessExpression | FieldAccessExpression | SliceExpression | ContainerInitExpression)137SuffixOpExpression : PrimaryExpression option(FnCallExpression | ArrayAccessExpression | FieldAccessExpression | SliceExpression)
136138
137FieldAccessExpression : token(Dot) token(Symbol)139FieldAccessExpression : token(Dot) token(Symbol)
138140
...@@ -152,7 +154,7 @@ PrefixOp : token(Not) | token(Dash) | token(Tilde) | token(Star) | (token(Ampers...@@ -152,7 +154,7 @@ PrefixOp : token(Not) | token(Dash) | token(Tilde) | token(Star) | (token(Ampers
152154
153PrimaryExpression : token(Number) | token(String) | token(CharLiteral) | KeywordLiteral | GroupedExpression | GotoExpression | BlockExpression | token(Symbol) | (token(AtSign) token(Symbol) FnCallExpression) | ArrayType | AsmExpression155PrimaryExpression : token(Number) | token(String) | token(CharLiteral) | KeywordLiteral | GroupedExpression | GotoExpression | BlockExpression | token(Symbol) | (token(AtSign) token(Symbol) FnCallExpression) | ArrayType | AsmExpression
154156
155ArrayType : token(LBracket) option(Expression) token(RBracket) option(token(Const)) UnwrapMaybeExpression157ArrayType : token(LBracket) option(Expression) token(RBracket) option(token(Const)) PrefixOpExpression
156158
157GotoExpression: token(Goto) token(Symbol)159GotoExpression: token(Goto) token(Symbol)
158160
...@@ -164,9 +166,9 @@ KeywordLiteral : token(True) | token(False) | token(Null) | token(Break) | token...@@ -164,9 +166,9 @@ KeywordLiteral : token(True) | token(False) | token(Null) | token(Break) | token
164## Operator Precedence166## Operator Precedence
165167
166```168```
167x() x[] x{} x.y169x() x[] x.y
168!x -x ~x *x &x170!x -x ~x *x &x ?x
169as171x{}
170* / %172* / %
171+ -173+ -
172<< >>174<< >>
src/parser.cpp+91-73
...@@ -903,6 +903,7 @@ static AstNode *ast_parse_block(ParseContext *pc, int *token_index, bool mandato...@@ -903,6 +903,7 @@ static AstNode *ast_parse_block(ParseContext *pc, int *token_index, bool mandato
903static AstNode *ast_parse_if_expr(ParseContext *pc, int *token_index, bool mandatory);903static AstNode *ast_parse_if_expr(ParseContext *pc, int *token_index, bool mandatory);
904static AstNode *ast_parse_block_expr(ParseContext *pc, int *token_index, bool mandatory);904static AstNode *ast_parse_block_expr(ParseContext *pc, int *token_index, bool mandatory);
905static AstNode *ast_parse_unwrap_maybe_expr(ParseContext *pc, int *token_index, bool mandatory);905static AstNode *ast_parse_unwrap_maybe_expr(ParseContext *pc, int *token_index, bool mandatory);
906static AstNode *ast_parse_prefix_op_expr(ParseContext *pc, int *token_index, bool mandatory);
906907
907static void ast_expect_token(ParseContext *pc, Token *token, TokenId token_id) {908static void ast_expect_token(ParseContext *pc, Token *token, TokenId token_id) {
908 if (token->id == token_id) {909 if (token->id == token_id) {
...@@ -998,7 +999,7 @@ static AstNode *ast_parse_param_decl(ParseContext *pc, int *token_index) {...@@ -998,7 +999,7 @@ static AstNode *ast_parse_param_decl(ParseContext *pc, int *token_index) {
998 *token_index += 1;999 *token_index += 1;
999 ast_expect_token(pc, colon, TokenIdColon);1000 ast_expect_token(pc, colon, TokenIdColon);
10001001
1001 node->data.param_decl.type = ast_parse_unwrap_maybe_expr(pc, token_index, true);1002 node->data.param_decl.type = ast_parse_prefix_op_expr(pc, token_index, true);
10021003
1003 return node;1004 return node;
1004}1005}
...@@ -1114,7 +1115,7 @@ static AstNode *ast_parse_array_type_expr(ParseContext *pc, int *token_index, bo...@@ -1114,7 +1115,7 @@ static AstNode *ast_parse_array_type_expr(ParseContext *pc, int *token_index, bo
1114 node->data.array_type.is_const = true;1115 node->data.array_type.is_const = true;
1115 }1116 }
11161117
1117 node->data.array_type.child_type = ast_parse_unwrap_maybe_expr(pc, token_index, true);1118 node->data.array_type.child_type = ast_parse_prefix_op_expr(pc, token_index, true);
11181119
1119 return node;1120 return node;
1120}1121}
...@@ -1159,7 +1160,7 @@ static void ast_parse_asm_output_item(ParseContext *pc, int *token_index, AstNod...@@ -1159,7 +1160,7 @@ static void ast_parse_asm_output_item(ParseContext *pc, int *token_index, AstNod
1159 if (token->id == TokenIdSymbol) {1160 if (token->id == TokenIdSymbol) {
1160 ast_buf_from_token(pc, token, &asm_output->variable_name);1161 ast_buf_from_token(pc, token, &asm_output->variable_name);
1161 } else if (token->id == TokenIdArrow) {1162 } else if (token->id == TokenIdArrow) {
1162 asm_output->return_type = ast_parse_unwrap_maybe_expr(pc, token_index, true);1163 asm_output->return_type = ast_parse_prefix_op_expr(pc, token_index, true);
1163 } else {1164 } else {
1164 ast_invalid_token_error(pc, token);1165 ast_invalid_token_error(pc, token);
1165 }1166 }
...@@ -1402,81 +1403,23 @@ static AstNode *ast_parse_primary_expr(ParseContext *pc, int *token_index, bool...@@ -1402,81 +1403,23 @@ static AstNode *ast_parse_primary_expr(ParseContext *pc, int *token_index, bool
1402}1403}
14031404
1404/*1405/*
1405SuffixOpExpression : PrimaryExpression option(FnCallExpression | ArrayAccessExpression | FieldAccessExpression | SliceExpression | ContainerInitExpression)1406CurlySuffixExpression : PrefixOpExpression option(ContainerInitExpression)
1406FnCallExpression : token(LParen) list(Expression, token(Comma)) token(RParen)
1407ArrayAccessExpression : token(LBracket) Expression token(RBracket)
1408SliceExpression : token(LBracket) Expression token(Ellipsis) option(Expression) token(RBracket) option(token(Const))
1409FieldAccessExpression : token(Dot) token(Symbol)
1410ContainerInitExpression : token(LBrace) ContainerInitBody token(RBrace)1407ContainerInitExpression : token(LBrace) ContainerInitBody token(RBrace)
1411ContainerInitBody : list(StructLiteralField, token(Comma)) | list(Expression, token(Comma))1408ContainerInitBody : list(StructLiteralField, token(Comma)) | list(Expression, token(Comma))
1412StructLiteralField : token(Dot) token(Symbol) token(Eq) Expression
1413*/1409*/
1414static AstNode *ast_parse_suffix_op_expr(ParseContext *pc, int *token_index, bool mandatory) {1410static AstNode *ast_parse_curly_suffix_expr(ParseContext *pc, int *token_index, bool mandatory) {
1415 AstNode *primary_expr = ast_parse_primary_expr(pc, token_index, mandatory);1411 AstNode *prefix_op_expr = ast_parse_prefix_op_expr(pc, token_index, mandatory);
1416 if (!primary_expr) {1412 if (!prefix_op_expr) {
1417 return nullptr;1413 return nullptr;
1418 }1414 }
14191415
1420 while (true) {1416 while (true) {
1421 Token *first_token = &pc->tokens->at(*token_index);1417 Token *first_token = &pc->tokens->at(*token_index);
1422 if (first_token->id == TokenIdLParen) {1418 if (first_token->id == TokenIdLBrace) {
1423 *token_index += 1;
1424
1425 AstNode *node = ast_create_node(pc, NodeTypeFnCallExpr, first_token);
1426 node->data.fn_call_expr.fn_ref_expr = primary_expr;
1427 ast_parse_fn_call_param_list(pc, token_index, &node->data.fn_call_expr.params);
1428
1429 primary_expr = node;
1430 } else if (first_token->id == TokenIdLBracket) {
1431 *token_index += 1;
1432
1433 AstNode *expr_node = ast_parse_expression(pc, token_index, true);
1434
1435 Token *ellipsis_or_r_bracket = &pc->tokens->at(*token_index);
1436
1437 if (ellipsis_or_r_bracket->id == TokenIdEllipsis) {
1438 *token_index += 1;
1439
1440 AstNode *node = ast_create_node(pc, NodeTypeSliceExpr, first_token);
1441 node->data.slice_expr.array_ref_expr = primary_expr;
1442 node->data.slice_expr.start = expr_node;
1443 node->data.slice_expr.end = ast_parse_expression(pc, token_index, false);
1444
1445 ast_eat_token(pc, token_index, TokenIdRBracket);
1446
1447 Token *const_tok = &pc->tokens->at(*token_index);
1448 if (const_tok->id == TokenIdKeywordConst) {
1449 *token_index += 1;
1450 node->data.slice_expr.is_const = true;
1451 }
1452
1453 primary_expr = node;
1454 } else if (ellipsis_or_r_bracket->id == TokenIdRBracket) {
1455 *token_index += 1;
1456
1457 AstNode *node = ast_create_node(pc, NodeTypeArrayAccessExpr, first_token);
1458 node->data.array_access_expr.array_ref_expr = primary_expr;
1459 node->data.array_access_expr.subscript = expr_node;
1460
1461 primary_expr = node;
1462 } else {
1463 ast_invalid_token_error(pc, first_token);
1464 }
1465 } else if (first_token->id == TokenIdDot) {
1466 *token_index += 1;
1467
1468 Token *name_token = ast_eat_token(pc, token_index, TokenIdSymbol);
1469
1470 AstNode *node = ast_create_node(pc, NodeTypeFieldAccessExpr, first_token);
1471 node->data.field_access_expr.struct_expr = primary_expr;
1472 ast_buf_from_token(pc, name_token, &node->data.field_access_expr.field_name);
1473
1474 primary_expr = node;
1475 } else if (first_token->id == TokenIdLBrace) {
1476 *token_index += 1;1419 *token_index += 1;
14771420
1478 AstNode *node = ast_create_node(pc, NodeTypeContainerInitExpr, first_token);1421 AstNode *node = ast_create_node(pc, NodeTypeContainerInitExpr, first_token);
1479 node->data.container_init_expr.type = primary_expr;1422 node->data.container_init_expr.type = prefix_op_expr;
14801423
1481 Token *token = &pc->tokens->at(*token_index);1424 Token *token = &pc->tokens->at(*token_index);
1482 if (token->id == TokenIdDot) {1425 if (token->id == TokenIdDot) {
...@@ -1536,6 +1479,81 @@ static AstNode *ast_parse_suffix_op_expr(ParseContext *pc, int *token_index, boo...@@ -1536,6 +1479,81 @@ static AstNode *ast_parse_suffix_op_expr(ParseContext *pc, int *token_index, boo
1536 }1479 }
1537 }1480 }
15381481
1482 prefix_op_expr = node;
1483 } else {
1484 return prefix_op_expr;
1485 }
1486 }
1487}
1488
1489/*
1490SuffixOpExpression : PrimaryExpression option(FnCallExpression | ArrayAccessExpression | FieldAccessExpression | SliceExpression)
1491FnCallExpression : token(LParen) list(Expression, token(Comma)) token(RParen)
1492ArrayAccessExpression : token(LBracket) Expression token(RBracket)
1493SliceExpression : token(LBracket) Expression token(Ellipsis) option(Expression) token(RBracket) option(token(Const))
1494FieldAccessExpression : token(Dot) token(Symbol)
1495StructLiteralField : token(Dot) token(Symbol) token(Eq) Expression
1496*/
1497static AstNode *ast_parse_suffix_op_expr(ParseContext *pc, int *token_index, bool mandatory) {
1498 AstNode *primary_expr = ast_parse_primary_expr(pc, token_index, mandatory);
1499 if (!primary_expr) {
1500 return nullptr;
1501 }
1502
1503 while (true) {
1504 Token *first_token = &pc->tokens->at(*token_index);
1505 if (first_token->id == TokenIdLParen) {
1506 *token_index += 1;
1507
1508 AstNode *node = ast_create_node(pc, NodeTypeFnCallExpr, first_token);
1509 node->data.fn_call_expr.fn_ref_expr = primary_expr;
1510 ast_parse_fn_call_param_list(pc, token_index, &node->data.fn_call_expr.params);
1511
1512 primary_expr = node;
1513 } else if (first_token->id == TokenIdLBracket) {
1514 *token_index += 1;
1515
1516 AstNode *expr_node = ast_parse_expression(pc, token_index, true);
1517
1518 Token *ellipsis_or_r_bracket = &pc->tokens->at(*token_index);
1519
1520 if (ellipsis_or_r_bracket->id == TokenIdEllipsis) {
1521 *token_index += 1;
1522
1523 AstNode *node = ast_create_node(pc, NodeTypeSliceExpr, first_token);
1524 node->data.slice_expr.array_ref_expr = primary_expr;
1525 node->data.slice_expr.start = expr_node;
1526 node->data.slice_expr.end = ast_parse_expression(pc, token_index, false);
1527
1528 ast_eat_token(pc, token_index, TokenIdRBracket);
1529
1530 Token *const_tok = &pc->tokens->at(*token_index);
1531 if (const_tok->id == TokenIdKeywordConst) {
1532 *token_index += 1;
1533 node->data.slice_expr.is_const = true;
1534 }
1535
1536 primary_expr = node;
1537 } else if (ellipsis_or_r_bracket->id == TokenIdRBracket) {
1538 *token_index += 1;
1539
1540 AstNode *node = ast_create_node(pc, NodeTypeArrayAccessExpr, first_token);
1541 node->data.array_access_expr.array_ref_expr = primary_expr;
1542 node->data.array_access_expr.subscript = expr_node;
1543
1544 primary_expr = node;
1545 } else {
1546 ast_invalid_token_error(pc, first_token);
1547 }
1548 } else if (first_token->id == TokenIdDot) {
1549 *token_index += 1;
1550
1551 Token *name_token = ast_eat_token(pc, token_index, TokenIdSymbol);
1552
1553 AstNode *node = ast_create_node(pc, NodeTypeFieldAccessExpr, first_token);
1554 node->data.field_access_expr.struct_expr = primary_expr;
1555 ast_buf_from_token(pc, name_token, &node->data.field_access_expr.field_name);
1556
1539 primary_expr = node;1557 primary_expr = node;
1540 } else {1558 } else {
1541 return primary_expr;1559 return primary_expr;
...@@ -1623,10 +1641,10 @@ static BinOpType ast_parse_mult_op(ParseContext *pc, int *token_index, bool mand...@@ -1623,10 +1641,10 @@ static BinOpType ast_parse_mult_op(ParseContext *pc, int *token_index, bool mand
1623}1641}
16241642
1625/*1643/*
1626MultiplyExpression : PrefixOpExpression MultiplyOperator MultiplyExpression | PrefixOpExpression1644MultiplyExpression : CurlySuffixExpression MultiplyOperator MultiplyExpression | CurlySuffixExpression
1627*/1645*/
1628static AstNode *ast_parse_mult_expr(ParseContext *pc, int *token_index, bool mandatory) {1646static AstNode *ast_parse_mult_expr(ParseContext *pc, int *token_index, bool mandatory) {
1629 AstNode *operand_1 = ast_parse_prefix_op_expr(pc, token_index, mandatory);1647 AstNode *operand_1 = ast_parse_curly_suffix_expr(pc, token_index, mandatory);
1630 if (!operand_1)1648 if (!operand_1)
1631 return nullptr;1649 return nullptr;
16321650
...@@ -1636,7 +1654,7 @@ static AstNode *ast_parse_mult_expr(ParseContext *pc, int *token_index, bool man...@@ -1636,7 +1654,7 @@ static AstNode *ast_parse_mult_expr(ParseContext *pc, int *token_index, bool man
1636 if (mult_op == BinOpTypeInvalid)1654 if (mult_op == BinOpTypeInvalid)
1637 return operand_1;1655 return operand_1;
16381656
1639 AstNode *operand_2 = ast_parse_prefix_op_expr(pc, token_index, true);1657 AstNode *operand_2 = ast_parse_curly_suffix_expr(pc, token_index, true);
16401658
1641 AstNode *node = ast_create_node(pc, NodeTypeBinOpExpr, token);1659 AstNode *node = ast_create_node(pc, NodeTypeBinOpExpr, token);
1642 node->data.bin_op_expr.op1 = operand_1;1660 node->data.bin_op_expr.op1 = operand_1;
...@@ -1948,7 +1966,7 @@ static AstNode *ast_parse_if_expr(ParseContext *pc, int *token_index, bool manda...@@ -1948,7 +1966,7 @@ static AstNode *ast_parse_if_expr(ParseContext *pc, int *token_index, bool manda
1948 node->data.if_var_expr.var_decl.expr = ast_parse_expression(pc, token_index, true);1966 node->data.if_var_expr.var_decl.expr = ast_parse_expression(pc, token_index, true);
1949 } else if (eq_or_colon->id == TokenIdColon) {1967 } else if (eq_or_colon->id == TokenIdColon) {
1950 *token_index += 1;1968 *token_index += 1;
1951 node->data.if_var_expr.var_decl.type = ast_parse_unwrap_maybe_expr(pc, token_index, true);1969 node->data.if_var_expr.var_decl.type = ast_parse_prefix_op_expr(pc, token_index, true);
19521970
1953 ast_eat_token(pc, token_index, TokenIdMaybeAssign);1971 ast_eat_token(pc, token_index, TokenIdMaybeAssign);
1954 node->data.if_var_expr.var_decl.expr = ast_parse_expression(pc, token_index, true);1972 node->data.if_var_expr.var_decl.expr = ast_parse_expression(pc, token_index, true);
...@@ -2028,7 +2046,7 @@ static AstNode *ast_parse_variable_declaration_expr(ParseContext *pc, int *token...@@ -2028,7 +2046,7 @@ static AstNode *ast_parse_variable_declaration_expr(ParseContext *pc, int *token
2028 node->data.variable_declaration.expr = ast_parse_expression(pc, token_index, true);2046 node->data.variable_declaration.expr = ast_parse_expression(pc, token_index, true);
2029 return node;2047 return node;
2030 } else if (eq_or_colon->id == TokenIdColon) {2048 } else if (eq_or_colon->id == TokenIdColon) {
2031 node->data.variable_declaration.type = ast_parse_unwrap_maybe_expr(pc, token_index, true);2049 node->data.variable_declaration.type = ast_parse_prefix_op_expr(pc, token_index, true);
2032 Token *eq_token = &pc->tokens->at(*token_index);2050 Token *eq_token = &pc->tokens->at(*token_index);
2033 if (eq_token->id == TokenIdEq) {2051 if (eq_token->id == TokenIdEq) {
2034 *token_index += 1;2052 *token_index += 1;
...@@ -2394,7 +2412,7 @@ static AstNode *ast_parse_fn_proto(ParseContext *pc, int *token_index, bool mand...@@ -2394,7 +2412,7 @@ static AstNode *ast_parse_fn_proto(ParseContext *pc, int *token_index, bool mand
2394 ast_parse_param_decl_list(pc, token_index, &node->data.fn_proto.params, &node->data.fn_proto.is_var_args);2412 ast_parse_param_decl_list(pc, token_index, &node->data.fn_proto.params, &node->data.fn_proto.is_var_args);
23952413
2396 Token *next_token = &pc->tokens->at(*token_index);2414 Token *next_token = &pc->tokens->at(*token_index);
2397 node->data.fn_proto.return_type = ast_parse_unwrap_maybe_expr(pc, token_index, false);2415 node->data.fn_proto.return_type = ast_parse_prefix_op_expr(pc, token_index, false);
2398 if (!node->data.fn_proto.return_type) {2416 if (!node->data.fn_proto.return_type) {
2399 node->data.fn_proto.return_type = ast_create_void_type_node(pc, next_token);2417 node->data.fn_proto.return_type = ast_create_void_type_node(pc, next_token);
2400 }2418 }