aboutsummaryrefslogtreecommitdiff
path: root/parse.c
diff options
context:
space:
mode:
Diffstat (limited to 'parse.c')
-rw-r--r--parse.c10
1 files changed, 9 insertions, 1 deletions
diff --git a/parse.c b/parse.c
index 28e91b27..75aff30b 100644
--- a/parse.c
+++ b/parse.c
@@ -983,10 +983,18 @@ PARSER(parse_while) {
// while condition [do] [<indent>] body
const char *start = pos;
if (!match_word(&pos, "while")) return NULL;
+
+ const char *tmp = pos;
+ // Shorthand form: `while when ...`
+ if (match_word(&tmp, "when")) {
+ ast_t *when = expect(ctx, start, &pos, parse_when, "I expected a 'when' block after this");
+ if (!when->__data.When.else_body) when->__data.When.else_body = NewAST(ctx->file, pos, pos, Stop);
+ return NewAST(ctx->file, start, pos, While, .body=when);
+ }
ast_t *condition = expect(ctx, start, &pos, parse_expr, "I don't see a viable condition for this 'while'");
expect_str(ctx, start, &pos, ":", "I expected a ':' here");
ast_t *body = expect(ctx, start, &pos, parse_opt_indented_block, "I expected a body for this 'while'");
- const char *tmp = pos;
+ tmp = pos;
whitespace(&tmp);
return NewAST(ctx->file, start, pos, While, .condition=condition, .body=body);
}