aboutsummaryrefslogtreecommitdiff
path: root/parse.c
diff options
context:
space:
mode:
authorBruce Hill <bruce@bruce-hill.com>2024-11-03 12:20:53 -0500
committerBruce Hill <bruce@bruce-hill.com>2024-11-03 12:20:53 -0500
commit078b4431854895c64d9b55bc3e1a9122cc911f48 (patch)
treeaead6d835d0b9227059dd90bc2c626003e807ea9 /parse.c
parentd905fa4888876eddc7716e88ffa158ed657bcf37 (diff)
Add a `repeat` keyword
Diffstat (limited to 'parse.c')
-rw-r--r--parse.c10
1 files changed, 10 insertions, 0 deletions
diff --git a/parse.c b/parse.c
index 2ea8cd78..7af03a16 100644
--- a/parse.c
+++ b/parse.c
@@ -122,6 +122,7 @@ static PARSER(parse_parens);
static PARSER(parse_pass);
static PARSER(parse_path);
static PARSER(parse_reduction);
+static PARSER(parse_repeat);
static PARSER(parse_return);
static PARSER(parse_say);
static PARSER(parse_set);
@@ -1222,6 +1223,14 @@ PARSER(parse_while) {
return NewAST(ctx->file, start, pos, While, .condition=condition, .body=body);
}
+PARSER(parse_repeat) {
+ // repeat: [<indent>] body
+ const char *start = pos;
+ if (!match_word(&pos, "repeat")) return NULL;
+ ast_t *body = expect(ctx, start, &pos, parse_block, "I expected a body for this 'repeat'");
+ return NewAST(ctx->file, start, pos, Repeat, .body=body);
+}
+
PARSER(parse_heap_alloc) {
const char *start = pos;
if (!match(&pos, "@")) return NULL;
@@ -1874,6 +1883,7 @@ PARSER(parse_extended_expr) {
|| (expr=optional(ctx, &pos, parse_while))
|| (expr=optional(ctx, &pos, parse_if))
|| (expr=optional(ctx, &pos, parse_when))
+ || (expr=optional(ctx, &pos, parse_repeat))
|| (expr=optional(ctx, &pos, parse_do))
)
return expr;