aboutsummaryrefslogtreecommitdiff
path: root/parse.c
diff options
context:
space:
mode:
authorBruce Hill <bruce@bruce-hill.com>2024-08-18 15:22:51 -0400
committerBruce Hill <bruce@bruce-hill.com>2024-08-18 15:22:51 -0400
commita49870f810f19bef7e1dae1f61681c1682823d00 (patch)
treed00588be4f289c3036cdf2e7ad252f06663cd154 /parse.c
parentf4b04a1b8cd882e25fee592c819650c9b7e8566b (diff)
Add primality testing and next_prime()/prev_prime()
Diffstat (limited to 'parse.c')
-rw-r--r--parse.c7
1 files changed, 5 insertions, 2 deletions
diff --git a/parse.c b/parse.c
index 740791b5..3b5974aa 100644
--- a/parse.c
+++ b/parse.c
@@ -930,10 +930,13 @@ ast_t *parse_comprehension_suffix(parse_ctx_t *ctx, ast_t *expr) {
expect_str(ctx, start, &pos, "in", "I expected an 'in' for this 'for'");
ast_t *iter = expect(ctx, start, &pos, parse_expr, "I expected an iterable value for this 'for'");
- whitespace(&pos);
+ const char *next_pos = pos;
+ whitespace(&next_pos);
ast_t *filter = NULL;
- if (match_word(&pos, "if"))
+ if (match_word(&next_pos, "if")) {
+ pos = next_pos;
filter = expect(ctx, pos-2, &pos, parse_expr, "I expected a condition for this 'if'");
+ }
return NewAST(ctx->file, start, pos, Comprehension, .expr=expr, .vars=vars, .iter=iter, .filter=filter);
}