diff options
| author | Bruce Hill <bruce@bruce-hill.com> | 2025-04-06 16:39:14 -0400 |
|---|---|---|
| committer | Bruce Hill <bruce@bruce-hill.com> | 2025-04-06 16:39:14 -0400 |
| commit | d046f4a57d536a893f4034cee9765fd8ae41603e (patch) | |
| tree | 1c60bdd01ae2fafcf6d4835072a69c55f5216d0c /src | |
| parent | 6d12f1dce744146dfa9072d574c540e1d49bb31b (diff) | |
Optional 'then' after 'if'/'when' clauses
Diffstat (limited to 'src')
| -rw-r--r-- | src/parse.c | 6 |
1 files changed, 4 insertions, 2 deletions
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" <condition> <body> ["else" <body>] | "unless" <condition> <body> ["else" <body>] + // "if" <condition> ["then"] <body> ["else" <body>] | "unless" <condition> <body> ["else" <body>] 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; |
