aboutsummaryrefslogtreecommitdiff
path: root/src/parser.cpp
diff options
context:
space:
mode:
authorgingerBill <bill@gingerbill.org>2023-05-29 23:17:06 +0100
committergingerBill <bill@gingerbill.org>2023-05-29 23:17:06 +0100
commit97490c6445cb3ba85f470e64e6ed6d24394c421a (patch)
tree0830f019734c96afd14faf81a7f05ee88021c66f /src/parser.cpp
parent1247d36a12b9a0043fda0f73f164bd7fa5dc3897 (diff)
Basic support for `#reverse for in` on normal arrays
Diffstat (limited to 'src/parser.cpp')
-rw-r--r--src/parser.cpp11
1 files changed, 11 insertions, 0 deletions
diff --git a/src/parser.cpp b/src/parser.cpp
index 1b48dce87..afdb1078d 100644
--- a/src/parser.cpp
+++ b/src/parser.cpp
@@ -4759,6 +4759,17 @@ gb_internal Ast *parse_stmt(AstFile *f) {
return stmt;
} else if (tag == "unroll") {
return parse_unrolled_for_loop(f, name);
+ } else if (tag == "reverse") {
+ Ast *for_stmt = parse_for_stmt(f);
+ if (for_stmt->kind == Ast_RangeStmt) {
+ if (for_stmt->RangeStmt.reverse) {
+ syntax_error(token, "#reverse already applied to a 'for in' statement");
+ }
+ for_stmt->RangeStmt.reverse = true;
+ } else {
+ syntax_error(token, "#reverse can only be applied to a 'for in' statement");
+ }
+ return for_stmt;
} else if (tag == "include") {
syntax_error(token, "#include is not a valid import declaration kind. Did you mean 'import'?");
s = ast_bad_stmt(f, token, f->curr_token);