aboutsummaryrefslogtreecommitdiff
path: root/parse.c
diff options
context:
space:
mode:
authorBruce Hill <bruce@bruce-hill.com>2024-09-11 01:48:15 -0400
committerBruce Hill <bruce@bruce-hill.com>2024-09-11 01:48:15 -0400
commit989dc3f4428fd3185753336cb91baf48e0c85ad0 (patch)
tree15eb26b7161f9953039f98625a42f7c68c688c86 /parse.c
parent23209a0aab983501701c62ac87c891309a7d3d58 (diff)
Support `if x := blah: ...`
Diffstat (limited to 'parse.c')
-rw-r--r--parse.c5
1 files changed, 3 insertions, 2 deletions
diff --git a/parse.c b/parse.c
index 95b05cbc..6191ceaf 100644
--- a/parse.c
+++ b/parse.c
@@ -1003,8 +1003,9 @@ PARSER(parse_if) {
if (!match_word(&pos, "if"))
return NULL;
- ast_t *condition = expect(ctx, start, &pos, parse_expr,
- "I expected to find a condition for this 'if'");
+ ast_t *condition = optional(ctx, &pos, parse_declaration);
+ if (!condition)
+ condition = expect(ctx, start, &pos, parse_expr, "I expected to find a condition for this 'if'");
ast_t *body = expect(ctx, start, &pos, parse_block, "I expected a body for this 'if' statement");