authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2016-01-14 15:21:41-07:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2016-01-14 15:21:41-07:00
log1645fa681f5cca05125b5aeba2bc76701c20f6bb
treefadd1f292120a59dad29ba5d8292757ebc674add
parent5f9ecb8566645f16ff9bf8527c92c7db9baf9719

parser: type expressions cannot be assignment


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

doc/langref.md+4-4
......@@ -48,7 +48,7 @@ RootExportDecl : many(Directive) token(Export) token(Symbol) token(String) token
4848
4949ExternBlock : many(Directive) token(Extern) token(LBrace) many(FnDecl) token(RBrace)
5050
51FnProto : many(Directive) option(FnVisibleMod) token(Fn) token(Symbol) ParamDeclList option(Expression)
51FnProto : many(Directive) option(FnVisibleMod) token(Fn) token(Symbol) ParamDeclList option(UnwrapMaybeExpression)
5252
5353Directive : token(NumberSign) token(Symbol) token(LParen) token(String) token(RParen)
5454
......@@ -78,7 +78,7 @@ AsmOutput : token(Colon) list(AsmOutputItem, token(Comma)) option(AsmInput)
7878
7979AsmInput : token(Colon) list(AsmInputItem, token(Comma)) option(AsmClobbers)
8080
81AsmOutputItem : token(LBracket) token(Symbol) token(RBracket) token(String) token(LParen) (token(Symbol) | token(Arrow) Expression) token(RParen)
81AsmOutputItem : token(LBracket) token(Symbol) token(RBracket) token(String) token(LParen) (token(Symbol) | token(Arrow) UnwrapMaybeExpression) token(RParen)
8282
8383AsmInputItem : token(LBracket) token(Symbol) token(RBracket) token(String) token(LParen) Expression token(RParen)
8484
......@@ -102,7 +102,7 @@ IfExpression : IfVarExpression | IfBoolExpression
102102
103103IfBoolExpression : 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) Expression) Token(MaybeAssign) Expression token(RParen) Expression Option(Else)
105IfVarExpression : token(If) token(LParen) (token(Const) | token(Var)) token(Symbol) option(token(Colon) UnwrapMaybeExpression) Token(MaybeAssign) Expression token(RParen) Expression Option(Else)
106106
107107Else : token(Else) Expression
108108
......@@ -152,7 +152,7 @@ PrefixOp : token(Not) | token(Dash) | token(Tilde) | token(Star) | (token(Ampers
152152
153153PrimaryExpression : token(Number) | token(String) | token(CharLiteral) | KeywordLiteral | GroupedExpression | GotoExpression | BlockExpression | token(Symbol) | (token(AtSign) token(Symbol) FnCallExpression) | ArrayType | AsmExpression
154154
155ArrayType : token(LBracket) option(Expression) token(RBracket) option(token(Const)) Expression
155ArrayType : token(LBracket) option(Expression) token(RBracket) option(token(Const)) UnwrapMaybeExpression
156156
157157GotoExpression: token(Goto) token(Symbol)
158158
src/parser.cpp+7-7
......@@ -1089,7 +1089,7 @@ static AstNode *ast_parse_grouped_expr(ParseContext *pc, int *token_index, bool
10891089}
10901090
10911091/*
1092ArrayType : token(LBracket) option(Expression) token(RBracket) option(token(Const)) Expression
1092ArrayType : token(LBracket) option(Expression) token(RBracket) option(token(Const)) UnwrapMaybeExpression
10931093*/
10941094static AstNode *ast_parse_array_type_expr(ParseContext *pc, int *token_index, bool mandatory) {
10951095 Token *l_bracket = &pc->tokens->at(*token_index);
......@@ -1114,7 +1114,7 @@ static AstNode *ast_parse_array_type_expr(ParseContext *pc, int *token_index, bo
11141114 node->data.array_type.is_const = true;
11151115 }
11161116
1117 node->data.array_type.child_type = ast_parse_expression(pc, token_index, true);
1117 node->data.array_type.child_type = ast_parse_unwrap_maybe_expr(pc, token_index, true);
11181118
11191119 return node;
11201120}
......@@ -1141,7 +1141,7 @@ static void ast_parse_asm_input_item(ParseContext *pc, int *token_index, AstNode
11411141}
11421142
11431143/*
1144AsmOutputItem : token(LBracket) token(Symbol) token(RBracket) token(String) token(LParen) (token(Symbol) | token(Arrow) Expression) token(RParen)
1144AsmOutputItem : token(LBracket) token(Symbol) token(RBracket) token(String) token(LParen) (token(Symbol) | token(Arrow) UnwrapMaybeExpression token(RParen)
11451145*/
11461146static void ast_parse_asm_output_item(ParseContext *pc, int *token_index, AstNode *node) {
11471147 ast_eat_token(pc, token_index, TokenIdLBracket);
......@@ -1159,7 +1159,7 @@ static void ast_parse_asm_output_item(ParseContext *pc, int *token_index, AstNod
11591159 if (token->id == TokenIdSymbol) {
11601160 ast_buf_from_token(pc, token, &asm_output->variable_name);
11611161 } else if (token->id == TokenIdArrow) {
1162 asm_output->return_type = ast_parse_expression(pc, token_index, true);
1162 asm_output->return_type = ast_parse_unwrap_maybe_expr(pc, token_index, true);
11631163 } else {
11641164 ast_invalid_token_error(pc, token);
11651165 }
......@@ -1948,7 +1948,7 @@ static AstNode *ast_parse_if_expr(ParseContext *pc, int *token_index, bool manda
19481948 node->data.if_var_expr.var_decl.expr = ast_parse_expression(pc, token_index, true);
19491949 } else if (eq_or_colon->id == TokenIdColon) {
19501950 *token_index += 1;
1951 node->data.if_var_expr.var_decl.type = ast_parse_expression(pc, token_index, true);
1951 node->data.if_var_expr.var_decl.type = ast_parse_unwrap_maybe_expr(pc, token_index, true);
19521952
19531953 ast_eat_token(pc, token_index, TokenIdMaybeAssign);
19541954 node->data.if_var_expr.var_decl.expr = ast_parse_expression(pc, token_index, true);
......@@ -2342,7 +2342,7 @@ static AstNode *ast_parse_block(ParseContext *pc, int *token_index, bool mandato
23422342}
23432343
23442344/*
2345FnProto : many(Directive) option(FnVisibleMod) token(Fn) token(Symbol) ParamDeclList option(Expression)
2345FnProto : many(Directive) option(FnVisibleMod) token(Fn) token(Symbol) ParamDeclList option(UnwrapMaybeExpression)
23462346*/
23472347static AstNode *ast_parse_fn_proto(ParseContext *pc, int *token_index, bool mandatory) {
23482348 Token *first_token = &pc->tokens->at(*token_index);
......@@ -2394,7 +2394,7 @@ static AstNode *ast_parse_fn_proto(ParseContext *pc, int *token_index, bool mand
23942394 ast_parse_param_decl_list(pc, token_index, &node->data.fn_proto.params, &node->data.fn_proto.is_var_args);
23952395
23962396 Token *next_token = &pc->tokens->at(*token_index);
2397 node->data.fn_proto.return_type = ast_parse_expression(pc, token_index, false);
2397 node->data.fn_proto.return_type = ast_parse_unwrap_maybe_expr(pc, token_index, false);
23982398 if (!node->data.fn_proto.return_type) {
23992399 node->data.fn_proto.return_type = ast_create_void_type_node(pc, next_token);
24002400 }