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...@@ -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(Expression)51FnProto : many(Directive) option(FnVisibleMod) token(Fn) token(Symbol) ParamDeclList option(UnwrapMaybeExpression)
5252
53Directive : token(NumberSign) token(Symbol) token(LParen) token(String) token(RParen)53Directive : token(NumberSign) token(Symbol) token(LParen) token(String) token(RParen)
5454
...@@ -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) Expression) token(RParen)81AsmOutputItem : token(LBracket) token(Symbol) token(RBracket) token(String) token(LParen) (token(Symbol) | token(Arrow) UnwrapMaybeExpression) 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) 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
107Else : token(Else) Expression107Else : token(Else) Expression
108108
...@@ -152,7 +152,7 @@ PrefixOp : token(Not) | token(Dash) | token(Tilde) | token(Star) | (token(Ampers...@@ -152,7 +152,7 @@ PrefixOp : token(Not) | token(Dash) | token(Tilde) | token(Star) | (token(Ampers
152152
153PrimaryExpression : token(Number) | token(String) | token(CharLiteral) | KeywordLiteral | GroupedExpression | GotoExpression | BlockExpression | token(Symbol) | (token(AtSign) token(Symbol) FnCallExpression) | ArrayType | AsmExpression153PrimaryExpression : 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)) Expression155ArrayType : token(LBracket) option(Expression) token(RBracket) option(token(Const)) UnwrapMaybeExpression
156156
157GotoExpression: token(Goto) token(Symbol)157GotoExpression: 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...@@ -1089,7 +1089,7 @@ static AstNode *ast_parse_grouped_expr(ParseContext *pc, int *token_index, bool
1089}1089}
10901090
1091/*1091/*
1092ArrayType : token(LBracket) option(Expression) token(RBracket) option(token(Const)) Expression1092ArrayType : token(LBracket) option(Expression) token(RBracket) option(token(Const)) UnwrapMaybeExpression
1093*/1093*/
1094static AstNode *ast_parse_array_type_expr(ParseContext *pc, int *token_index, bool mandatory) {1094static AstNode *ast_parse_array_type_expr(ParseContext *pc, int *token_index, bool mandatory) {
1095 Token *l_bracket = &pc->tokens->at(*token_index);1095 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...@@ -1114,7 +1114,7 @@ static AstNode *ast_parse_array_type_expr(ParseContext *pc, int *token_index, bo
1114 node->data.array_type.is_const = true;1114 node->data.array_type.is_const = true;
1115 }1115 }
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
1119 return node;1119 return node;
1120}1120}
...@@ -1141,7 +1141,7 @@ static void ast_parse_asm_input_item(ParseContext *pc, int *token_index, AstNode...@@ -1141,7 +1141,7 @@ static void ast_parse_asm_input_item(ParseContext *pc, int *token_index, AstNode
1141}1141}
11421142
1143/*1143/*
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)
1145*/1145*/
1146static void ast_parse_asm_output_item(ParseContext *pc, int *token_index, AstNode *node) {1146static void ast_parse_asm_output_item(ParseContext *pc, int *token_index, AstNode *node) {
1147 ast_eat_token(pc, token_index, TokenIdLBracket);1147 ast_eat_token(pc, token_index, TokenIdLBracket);
...@@ -1159,7 +1159,7 @@ static void ast_parse_asm_output_item(ParseContext *pc, int *token_index, AstNod...@@ -1159,7 +1159,7 @@ static void ast_parse_asm_output_item(ParseContext *pc, int *token_index, AstNod
1159 if (token->id == TokenIdSymbol) {1159 if (token->id == TokenIdSymbol) {
1160 ast_buf_from_token(pc, token, &asm_output->variable_name);1160 ast_buf_from_token(pc, token, &asm_output->variable_name);
1161 } else if (token->id == TokenIdArrow) {1161 } 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);
1163 } else {1163 } else {
1164 ast_invalid_token_error(pc, token);1164 ast_invalid_token_error(pc, token);
1165 }1165 }
...@@ -1948,7 +1948,7 @@ static AstNode *ast_parse_if_expr(ParseContext *pc, int *token_index, bool manda...@@ -1948,7 +1948,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);1948 node->data.if_var_expr.var_decl.expr = ast_parse_expression(pc, token_index, true);
1949 } else if (eq_or_colon->id == TokenIdColon) {1949 } else if (eq_or_colon->id == TokenIdColon) {
1950 *token_index += 1;1950 *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
1953 ast_eat_token(pc, token_index, TokenIdMaybeAssign);1953 ast_eat_token(pc, token_index, TokenIdMaybeAssign);
1954 node->data.if_var_expr.var_decl.expr = ast_parse_expression(pc, token_index, true);1954 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...@@ -2342,7 +2342,7 @@ static AstNode *ast_parse_block(ParseContext *pc, int *token_index, bool mandato
2342}2342}
23432343
2344/*2344/*
2345FnProto : many(Directive) option(FnVisibleMod) token(Fn) token(Symbol) ParamDeclList option(Expression)2345FnProto : many(Directive) option(FnVisibleMod) token(Fn) token(Symbol) ParamDeclList option(UnwrapMaybeExpression)
2346*/2346*/
2347static AstNode *ast_parse_fn_proto(ParseContext *pc, int *token_index, bool mandatory) {2347static AstNode *ast_parse_fn_proto(ParseContext *pc, int *token_index, bool mandatory) {
2348 Token *first_token = &pc->tokens->at(*token_index);2348 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...@@ -2394,7 +2394,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);2394 ast_parse_param_decl_list(pc, token_index, &node->data.fn_proto.params, &node->data.fn_proto.is_var_args);
23952395
2396 Token *next_token = &pc->tokens->at(*token_index);2396 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);
2398 if (!node->data.fn_proto.return_type) {2398 if (!node->data.fn_proto.return_type) {
2399 node->data.fn_proto.return_type = ast_create_void_type_node(pc, next_token);2399 node->data.fn_proto.return_type = ast_create_void_type_node(pc, next_token);
2400 }2400 }