From 3671582c15235e5f79a84936ea2f834f6968ff8c Mon Sep 17 00:00:00 2001 From: Andrew Kelley Date: Thu, 25 Jan 2018 04:10:11 -0500 Subject: syntax: functions require return type. remove `->` The purpose of this is: * Only one way to do things * Changing a function with void return type to return a possible error becomes a 1 character change, subtly encouraging people to use errors. See #632 Here are some imperfect sed commands for performing this update: remove arrow: ``` sed -i 's/\(\bfn\b.*\)-> /\1/g' $(find . -name "*.zig") ``` add void: ``` sed -i 's/\(\bfn\b.*\))\s*{/\1) void {/g' $(find ../ -name "*.zig") ``` Some cleanup may be necessary, but this should do the bulk of the work. --- src/parser.cpp | 14 ++------------ 1 file changed, 2 insertions(+), 12 deletions(-) (limited to 'src/parser.cpp') diff --git a/src/parser.cpp b/src/parser.cpp index 3439ec0c54..12293bc61b 100644 --- a/src/parser.cpp +++ b/src/parser.cpp @@ -84,11 +84,6 @@ static AstNode *ast_create_node(ParseContext *pc, NodeType type, Token *first_to return node; } -static AstNode *ast_create_void_type_node(ParseContext *pc, Token *token) { - AstNode *node = ast_create_node(pc, NodeTypeSymbol, token); - node->data.symbol_expr.symbol = pc->void_buf; - return node; -} static void parse_asm_template(ParseContext *pc, AstNode *node) { Buf *asm_template = node->data.asm_expr.asm_template; @@ -2245,7 +2240,7 @@ static AstNode *ast_parse_block(ParseContext *pc, size_t *token_index, bool mand } /* -FnProto = option("nakedcc" | "stdcallcc" | "extern") "fn" option(Symbol) ParamDeclList option("align" "(" Expression ")") option("section" "(" Expression ")") option("->" TypeExpr) +FnProto = option("nakedcc" | "stdcallcc" | "extern") "fn" option(Symbol) ParamDeclList option("align" "(" Expression ")") option("section" "(" Expression ")") TypeExpr */ static AstNode *ast_parse_fn_proto(ParseContext *pc, size_t *token_index, bool mandatory, VisibMod visib_mod) { Token *first_token = &pc->tokens->at(*token_index); @@ -2320,12 +2315,7 @@ static AstNode *ast_parse_fn_proto(ParseContext *pc, size_t *token_index, bool m ast_eat_token(pc, token_index, TokenIdRParen); next_token = &pc->tokens->at(*token_index); } - if (next_token->id == TokenIdArrow) { - *token_index += 1; - node->data.fn_proto.return_type = ast_parse_type_expr(pc, token_index, false); - } else { - node->data.fn_proto.return_type = ast_create_void_type_node(pc, next_token); - } + node->data.fn_proto.return_type = ast_parse_type_expr(pc, token_index, true); return node; } -- cgit v1.2.3