commit 0b23719c9f128b183c427a9a3c182f2f96195e58
parent c6151b58d1f2fccf006d9ac33cea7f4c835b8dbe
Author: Sebastian <sebastian@sebsite.pw>
Date: Mon, 7 Mar 2022 22:35:10 -0500
parse: permit trailing comma in switch case
case foo, bar, =>
This is already allowed by the specification and accepted by harec.
Signed-off-by: Sebastian <sebastian@sebsite.pw>
Diffstat:
1 file changed, 7 insertions(+), 8 deletions(-)
diff --git a/hare/parse/expr.ha b/hare/parse/expr.ha
@@ -1014,17 +1014,16 @@ fn switch_expr(lexer: *lex::lexer) (ast::expr | error) = {
want(lexer, ltok::CASE)?;
let opts: []*ast::expr = [];
- if (try(lexer, ltok::ARROW)? is void) {
- for (true) {
- append(opts, alloc(expr(lexer)?));
-
- if (try(lexer, ltok::COMMA)? is void) {
- want(lexer, ltok::ARROW)?;
+ if (try(lexer, ltok::ARROW)? is void) for (true) {
+ append(opts, alloc(expr(lexer)?));
+ switch (want(lexer, ltok::ARROW, ltok::COMMA)?.0) {
+ case ltok::ARROW =>
+ break;
+ case ltok::COMMA =>
+ if (try(lexer, ltok::ARROW)? is lex::token) {
break;
};
};
- synassert(lex::mkloc(lexer), len(opts) != 0,
- "Expected a list of options")?;
};
let exprs: []*ast::expr = [];