From d046f4a57d536a893f4034cee9765fd8ae41603e Mon Sep 17 00:00:00 2001 From: Bruce Hill Date: Sun, 6 Apr 2025 16:39:14 -0400 Subject: Optional 'then' after 'if'/'when' clauses --- src/parse.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) (limited to 'src') diff --git a/src/parse.c b/src/parse.c index d9f06371..848ac340 100644 --- a/src/parse.c +++ b/src/parse.c @@ -61,7 +61,7 @@ int op_tightness[] = { }; static const char *keywords[] = { - "yes", "xor", "while", "when", "use", "unless", "struct", "stop", "skip", "return", + "yes", "xor", "while", "when", "use", "unless", "then", "struct", "stop", "skip", "return", "or", "not", "none", "no", "mod1", "mod", "pass", "lang", "inline", "in", "if", "func", "for", "extern", "extend", "enum", "else", "do", "deserialize", "defer", "and", "_min_", "_max_", NULL, @@ -938,7 +938,7 @@ ast_t *parse_optional_conditional_suffix(parse_ctx_t *ctx, ast_t *stmt) { } PARSER(parse_if) { - // "if" ["else" ] | "unless" ["else" ] + // "if" ["then"] ["else" ] | "unless" ["else" ] const char *start = pos; int64_t starting_indent = get_indent(ctx, pos); @@ -957,6 +957,7 @@ PARSER(parse_if) { if (unless) condition = WrapAST(condition, Not, condition); + (void)match_word(&pos, "then"); // Optional 'then' ast_t *body = expect(ctx, start, &pos, parse_block, "I expected a body for this 'if' statement"); const char *tmp = pos; @@ -999,6 +1000,7 @@ PARSER(parse_when) { new_clauses = new(when_clause_t, .pattern=pattern, .next=new_clauses); spaces(&pos); } + (void)match_word(&pos, "then"); // Optional 'then' ast_t *body = expect(ctx, start, &pos, parse_block, "I expected a body for this 'when' clause"); for (when_clause_t *c = new_clauses; c && c != clauses; c = c->next) { c->body = body; -- cgit v1.2.3