diff options
| author | Ginger Bill <bill@gingerbill.org> | 2017-01-27 16:34:58 +0000 |
|---|---|---|
| committer | Ginger Bill <bill@gingerbill.org> | 2017-01-27 16:34:58 +0000 |
| commit | 832009f33acc573d44dd9dfb470ad8fef72216ff (patch) | |
| tree | b34120bf3d81739d7f516efb54235aaa2d15d04e /src | |
| parent | d3d3bfd4557c23da58a33066c4a7e5042435829d (diff) | |
`in` keyword for `for` and `match type`
Diffstat (limited to 'src')
| -rw-r--r-- | src/check_decl.c | 1 | ||||
| -rw-r--r-- | src/check_expr.c | 8 | ||||
| -rw-r--r-- | src/parser.c | 4 | ||||
| -rw-r--r-- | src/tokenizer.c | 13 |
4 files changed, 13 insertions, 13 deletions
diff --git a/src/check_decl.c b/src/check_decl.c index 39c924ebd..9fb786286 100644 --- a/src/check_decl.c +++ b/src/check_decl.c @@ -64,6 +64,7 @@ void check_init_variables(Checker *c, Entity **lhs, isize lhs_count, AstNodeArra Array(Operand) operands; array_init_reserve(&operands, c->tmp_allocator, 2*lhs_count); + // TODO(bill): Allow for type hints from the entities for_array(i, inits) { AstNode *rhs = inits.e[i]; Operand o = {0}; diff --git a/src/check_expr.c b/src/check_expr.c index 273f237fb..f6037beee 100644 --- a/src/check_expr.c +++ b/src/check_expr.c @@ -4071,19 +4071,21 @@ ExprKind check__expr_base(Checker *c, Operand *o, AstNode *node, Type *type_hint error_node(ie->cond, "Non-boolean condition in if expression"); } - Operand x = {Addressing_Invalid}; Operand y = {Addressing_Invalid}; Type *if_type = NULL; Type *else_type = NULL; - check_expr(c, &x, ie->body); + if (type_hint) { + gb_printf_err("here\n"); + } + check_expr_with_type_hint(c, &x, ie->body, type_hint); if_type = x.type; if (ie->else_expr != NULL) { switch (ie->else_expr->kind) { case AstNode_IfExpr: case AstNode_BlockExpr: - check_expr(c, &y, ie->else_expr); + check_expr_with_type_hint(c, &y, ie->else_expr, if_type); else_type = y.type; break; default: diff --git a/src/parser.c b/src/parser.c index f8a732fb4..b3b1822c2 100644 --- a/src/parser.c +++ b/src/parser.c @@ -2944,7 +2944,7 @@ AstNode *parse_for_stmt(AstFile *f) { Token token = expect_token(f, Token_for); AstNodeArray names = parse_ident_list(f); parse_check_name_list_for_reserves(f, names); - Token colon = expect_token_after(f, Token_Colon, "for name list"); + Token colon = expect_token_after(f, Token_in, "for name list"); isize prev_level = f->expr_level; f->expr_level = -1; @@ -3029,7 +3029,7 @@ AstNode *parse_match_stmt(AstFile *f) { f->expr_level = -1; AstNode *var = parse_identifier(f); - expect_token(f, Token_Colon); + expect_token_after(f, Token_in, "match type name"); tag = parse_simple_stmt(f); f->expr_level = prev_level; diff --git a/src/tokenizer.c b/src/tokenizer.c index 79cdda258..c21c09942 100644 --- a/src/tokenizer.c +++ b/src/tokenizer.c @@ -75,7 +75,7 @@ TOKEN_KIND(Token__ComparisonEnd, "_ComparisonEnd"), \ TOKEN_KIND(Token_Semicolon, ";"), \ TOKEN_KIND(Token_Period, "."), \ TOKEN_KIND(Token_Comma, ","), \ - TOKEN_KIND(Token_Ellipsis, "..."), \ + TOKEN_KIND(Token_Ellipsis, ".."), \ TOKEN_KIND(Token_HalfOpenRange, "..<"), \ TOKEN_KIND(Token__OperatorEnd, "_OperatorEnd"), \ \ @@ -94,6 +94,7 @@ TOKEN_KIND(Token__KeywordBegin, "_KeywordBegin"), \ TOKEN_KIND(Token_else, "else"), \ TOKEN_KIND(Token_while, "while"), \ TOKEN_KIND(Token_for, "for"), \ + TOKEN_KIND(Token_in, "in"), \ TOKEN_KIND(Token_when, "when"), \ TOKEN_KIND(Token_range, "range"), \ TOKEN_KIND(Token_defer, "defer"), \ @@ -845,14 +846,10 @@ Token tokenizer_get_token(Tokenizer *t) { case '.': token.kind = Token_Period; // Default - /* if (gb_is_between(t->curr_rune, '0', '9')) { // Might be a number - token = scan_number_to_token(t, true); - } else */ if (t->curr_rune == '.') { // Could be an ellipsis + if (t->curr_rune == '.') { // Could be an ellipsis advance_to_next_rune(t); - if (t->curr_rune == '.') { - advance_to_next_rune(t); - token.kind = Token_Ellipsis; - } else if (t->curr_rune == '<') { + token.kind = Token_Ellipsis; + if (t->curr_rune == '<') { advance_to_next_rune(t); token.kind = Token_HalfOpenRange; } |