aboutsummaryrefslogtreecommitdiff
path: root/src/check_expr.c
diff options
context:
space:
mode:
authorGinger Bill <bill@gingerbill.org>2017-04-20 23:22:45 +0100
committerGinger Bill <bill@gingerbill.org>2017-04-20 23:22:45 +0100
commita713e3300786199510e525aa9f90ee8d91aa862a (patch)
treeb7fb9141d89e7a5ab673615cdfc0137630fc3260 /src/check_expr.c
parentc5411a25a94650ec6370eea3572d3d60f6240482 (diff)
Change interval syntax: .. open range, ..< half-closed range
Diffstat (limited to 'src/check_expr.c')
-rw-r--r--src/check_expr.c16
1 files changed, 16 insertions, 0 deletions
diff --git a/src/check_expr.c b/src/check_expr.c
index 9038d8667..a631bf272 100644
--- a/src/check_expr.c
+++ b/src/check_expr.c
@@ -2819,6 +2819,7 @@ bool check_index_value(Checker *c, AstNode *index_value, i64 max_count, i64 *val
return false;
}
+
return true;
}
}
@@ -5732,6 +5733,11 @@ ExprKind check_expr_base_internal(Checker *c, Operand *o, AstNode *node, Type *t
o->mode = Addressing_Value;
}
+ if (se->low == NULL && se->high != NULL) {
+ error(se->interval0, "1st index is required if a 2nd index is specified");
+ // It is okay to continue as it will assume the 1st index is zero
+ }
+
if (se->index3 && (se->high == NULL || se->max == NULL)) {
error(se->close, "2nd and 3rd indices are required in a 3-index slice");
o->mode = Addressing_Invalid;
@@ -5739,6 +5745,16 @@ ExprKind check_expr_base_internal(Checker *c, Operand *o, AstNode *node, Type *t
return kind;
}
+ if (se->index3 && se->interval0.kind != se->interval1.kind) {
+ error(se->close, "The interval separators for in a 3-index slice must be the same");
+ o->mode = Addressing_Invalid;
+ o->expr = node;
+ return kind;
+ }
+
+
+ TokenKind interval_kind = se->interval0.kind;
+
i64 indices[2] = {0};
AstNode *nodes[3] = {se->low, se->high, se->max};
for (isize i = 0; i < gb_count_of(nodes); i++) {