aboutsummaryrefslogtreecommitdiff
path: root/src/parse
diff options
context:
space:
mode:
authorBruce Hill <bruce@bruce-hill.com>2025-09-24 21:20:44 -0400
committerBruce Hill <bruce@bruce-hill.com>2025-09-24 21:20:44 -0400
commit0cfae753aa131f949253f3fba1e3a36c2bde6ac0 (patch)
treed1403a97d7e86f547f8e6ca9994095f31c37d2a2 /src/parse
parent76f80f80ff1788af96ae87fa909c130336d5399b (diff)
Revert "Deprecate `defer`"
This reverts commit 7e3e245f6809946ea06ef1998bcabb7e0902fbd7.
Diffstat (limited to 'src/parse')
-rw-r--r--src/parse/controlflow.c7
-rw-r--r--src/parse/controlflow.h1
-rw-r--r--src/parse/expressions.c6
-rw-r--r--src/parse/utils.c7
4 files changed, 15 insertions, 6 deletions
diff --git a/src/parse/controlflow.c b/src/parse/controlflow.c
index 74b3ea7a..1087e20e 100644
--- a/src/parse/controlflow.c
+++ b/src/parse/controlflow.c
@@ -79,6 +79,13 @@ ast_t *parse_pass(parse_ctx_t *ctx, const char *pos) {
return match_word(&pos, "pass") ? NewAST(ctx->file, start, pos, Pass) : NULL;
}
+ast_t *parse_defer(parse_ctx_t *ctx, const char *pos) {
+ const char *start = pos;
+ if (!match_word(&pos, "defer")) return NULL;
+ ast_t *body = expect(ctx, start, &pos, parse_block, "I expected a block to be deferred here");
+ return NewAST(ctx->file, start, pos, Defer, .body = body);
+}
+
ast_t *parse_skip(parse_ctx_t *ctx, const char *pos) {
const char *start = pos;
if (!match_word(&pos, "continue") && !match_word(&pos, "skip")) return NULL;
diff --git a/src/parse/controlflow.h b/src/parse/controlflow.h
index 35a5a3f6..2ef093d4 100644
--- a/src/parse/controlflow.h
+++ b/src/parse/controlflow.h
@@ -5,6 +5,7 @@
#include "context.h"
ast_t *parse_block(parse_ctx_t *ctx, const char *pos);
+ast_t *parse_defer(parse_ctx_t *ctx, const char *pos);
ast_t *parse_do(parse_ctx_t *ctx, const char *pos);
ast_t *parse_for(parse_ctx_t *ctx, const char *pos);
ast_t *parse_if(parse_ctx_t *ctx, const char *pos);
diff --git a/src/parse/expressions.c b/src/parse/expressions.c
index d6578b9e..3cb47669 100644
--- a/src/parse/expressions.c
+++ b/src/parse/expressions.c
@@ -191,9 +191,9 @@ ast_t *parse_term_no_suffix(parse_ctx_t *ctx, const char *pos) {
|| (term = parse_bool(ctx, pos)) || (term = parse_text(ctx, pos)) || (term = parse_path(ctx, pos))
|| (term = parse_lambda(ctx, pos)) || (term = parse_parens(ctx, pos)) || (term = parse_table(ctx, pos))
|| (term = parse_deserialize(ctx, pos)) || (term = parse_var(ctx, pos)) || (term = parse_list(ctx, pos))
- || (term = parse_reduction(ctx, pos)) || (term = parse_pass(ctx, pos)) || (term = parse_skip(ctx, pos))
- || (term = parse_stop(ctx, pos)) || (term = parse_return(ctx, pos)) || (term = parse_not(ctx, pos))
- || (term = parse_inline_c(ctx, pos)));
+ || (term = parse_reduction(ctx, pos)) || (term = parse_pass(ctx, pos)) || (term = parse_defer(ctx, pos))
+ || (term = parse_skip(ctx, pos)) || (term = parse_stop(ctx, pos)) || (term = parse_return(ctx, pos))
+ || (term = parse_not(ctx, pos)) || (term = parse_inline_c(ctx, pos)));
return term;
}
diff --git a/src/parse/utils.c b/src/parse/utils.c
index b45e388e..2048a3ff 100644
--- a/src/parse/utils.c
+++ b/src/parse/utils.c
@@ -12,9 +12,10 @@
#include "utils.h"
static const char *keywords[] = {
- "C_code", "_max_", "_min_", "and", "assert", "break", "continue", "deserialize", "do", "else", "enum", "extend",
- "for", "func", "if", "in", "lang", "mod", "mod1", "no", "none", "not", "or", "pass",
- "return", "skip", "skip", "stop", "struct", "then", "unless", "use", "when", "while", "xor", "yes",
+ "C_code", "_max_", "_min_", "and", "assert", "break", "continue", "defer", "deserialize", "do",
+ "else", "enum", "extend", "for", "func", "if", "in", "lang", "mod", "mod1",
+ "no", "none", "not", "or", "pass", "return", "skip", "skip", "stop", "struct",
+ "then", "unless", "use", "when", "while", "xor", "yes",
};
CONSTFUNC bool is_keyword(const char *word) {