Ellipsis is now just ..; Remove half-closed range operator and treat all of them as half-closed; slice expression uses ..;

This commit is contained in:
Ginger Bill
2017-02-26 14:19:03 +00:00
parent 18b3c0b2fc
commit 3c9143957c
14 changed files with 210 additions and 197 deletions
+1 -2
View File
@@ -715,8 +715,7 @@ void check_stmt_internal(Checker *c, AstNode *node, u32 flags) {
TokenKind op = Token_Lt;
switch (ie->op.kind) {
case Token_HalfOpenRange: op = Token_Lt; break;
case Token_Ellipsis: op = Token_LtEq; break;
case Token_Ellipsis: op = Token_Lt; break;
default: error(ie->op, "Invalid range operator"); break;
}
bool ok = compare_exact_values(Token_Lt, a, b);
+1 -2
View File
@@ -4742,8 +4742,7 @@ void ir_build_range_interval(irProcedure *proc, AstNodeIntervalExpr *node, Type
TokenKind op = Token_Lt;
switch (node->op.kind) {
case Token_HalfOpenRange: op = Token_Lt; break;
case Token_Ellipsis: op = Token_LtEq; break;
case Token_Ellipsis: op = Token_Lt; break;
default: GB_PANIC("Invalid interval operator"); break;
}
irValue *cond = ir_emit_comp(proc, op, ir_emit_load(proc, value), upper);
+2 -7
View File
@@ -1950,16 +1950,12 @@ AstNode *parse_atom_expr(AstFile *f, bool lhs) {
f->expr_level++;
open = expect_token(f, Token_OpenBracket);
// if (f->curr_token.kind != Token_Ellipsis &&
// f->curr_token.kind != Token_HalfOpenRange) {
if (f->curr_token.kind != Token_Colon) {
if (f->curr_token.kind != Token_Ellipsis) {
indices[0] = parse_expr(f, false);
}
bool is_index = true;
// if (f->curr_token.kind == Token_Ellipsis ||
// f->curr_token.kind == Token_HalfOpenRange) {
if (f->curr_token.kind == Token_Colon) {
if (f->curr_token.kind == Token_Ellipsis) {
is_index = false;
interval = f->curr_token;
next_token(f);
@@ -2261,7 +2257,6 @@ AstNode *parse_simple_stmt(AstFile *f, bool in_stmt_ok) {
allow_token(f, Token_in);
AstNode *expr = parse_expr(f, false);
switch (f->curr_token.kind) {
case Token_HalfOpenRange:
case Token_Ellipsis: {
Token op = f->curr_token;
next_token(f);
+31 -9
View File
@@ -73,8 +73,8 @@ TOKEN_KIND(Token__ComparisonEnd, "_ComparisonEnd"), \
TOKEN_KIND(Token_Semicolon, ";"), \
TOKEN_KIND(Token_Period, "."), \
TOKEN_KIND(Token_Comma, ","), \
TOKEN_KIND(Token_Ellipsis, "..."), \
TOKEN_KIND(Token_HalfOpenRange, "..<"), \
TOKEN_KIND(Token_Ellipsis, ".."), \
/* TOKEN_KIND(Token_HalfOpenRange, "..<"), */ \
TOKEN_KIND(Token__OperatorEnd, "_OperatorEnd"), \
\
TOKEN_KIND(Token__KeywordBegin, "_KeywordBegin"), \
@@ -225,6 +225,23 @@ void syntax_error_va(Token token, char *fmt, va_list va) {
gb_mutex_unlock(&global_error_collector.mutex);
}
void syntax_warning_va(Token token, char *fmt, va_list va) {
gb_mutex_lock(&global_error_collector.mutex);
global_error_collector.warning_count++;
// NOTE(bill): Duplicate error, skip it
if (!token_pos_eq(global_error_collector.prev, token.pos)) {
global_error_collector.prev = token.pos;
gb_printf_err("%.*s(%td:%td) Syntax Warning: %s\n",
LIT(token.pos.file), token.pos.line, token.pos.column,
gb_bprintf_va(fmt, va));
} else if (token.pos.line == 0) {
gb_printf_err("Warning: %s\n", gb_bprintf_va(fmt, va));
}
gb_mutex_unlock(&global_error_collector.mutex);
}
void warning(Token token, char *fmt, ...) {
va_list va;
@@ -247,6 +264,13 @@ void syntax_error(Token token, char *fmt, ...) {
va_end(va);
}
void syntax_warning(Token token, char *fmt, ...) {
va_list va;
va_start(va, fmt);
syntax_warning_va(token, fmt, va);
va_end(va);
}
void compiler_error(char *fmt, ...) {
va_list va;
@@ -834,13 +858,11 @@ Token tokenizer_get_token(Tokenizer *t) {
token.kind = Token_Period; // Default
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_HalfOpenRange;
} else if (t->curr_rune == '.') {
advance_to_next_rune(t);
token.kind = Token_Ellipsis;
}
token.kind = Token_Ellipsis;
// if (t->curr_rune == '<') {
// advance_to_next_rune(t);
// token.kind = Token_HalfOpenRange;
// }
}
break;