mirror of
https://github.com/Ed94/Odin.git
synced 2026-06-27 07:51:49 -07:00
in keyword for for and match type
This commit is contained in:
@@ -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};
|
||||
|
||||
+5
-3
@@ -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:
|
||||
|
||||
+2
-2
@@ -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;
|
||||
|
||||
+5
-8
@@ -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;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user