aboutsummaryrefslogtreecommitdiff
path: root/src/parser.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/parser.cpp')
-rw-r--r--src/parser.cpp10
1 files changed, 9 insertions, 1 deletions
diff --git a/src/parser.cpp b/src/parser.cpp
index a397585e8..0057ab611 100644
--- a/src/parser.cpp
+++ b/src/parser.cpp
@@ -3274,6 +3274,8 @@ gb_internal Ast *parse_atom_expr(AstFile *f, Ast *operand, bool lhs) {
case Token_OpenBracket: {
bool prev_allow_range = f->allow_range;
f->allow_range = false;
+ defer (f->allow_range = prev_allow_range);
+
Token open = {}, close = {}, interval = {};
Ast *indices[2] = {};
@@ -3282,6 +3284,13 @@ gb_internal Ast *parse_atom_expr(AstFile *f, Ast *operand, bool lhs) {
f->expr_level++;
open = expect_token(f, Token_OpenBracket);
+ if (f->curr_token.kind == Token_CloseBracket) {
+ error(f->curr_token, "Expected an operand, got ]");
+ close = expect_token(f, Token_CloseBracket);
+ operand = ast_index_expr(f, operand, nullptr, open, close);
+ break;
+ }
+
switch (f->curr_token.kind) {
case Token_Ellipsis:
case Token_RangeFull:
@@ -3331,7 +3340,6 @@ gb_internal Ast *parse_atom_expr(AstFile *f, Ast *operand, bool lhs) {
operand = ast_index_expr(f, operand, indices[0], open, close);
}
- f->allow_range = prev_allow_range;
} break;
case Token_Pointer: // Deference