commit 3d2c0b707e1bbc987e6be885d12ebc89ec230edd
parent 0511c13fc1035402611f3a3fcb01232a7060776d
Author: Sebastian <sebastian@sebsite.pw>
Date: Fri, 4 Aug 2023 00:28:54 -0400
hare::parse: allow return and yield in more places
Signed-off-by: Sebastian <sebastian@sebsite.pw>
Diffstat:
1 file changed, 8 insertions(+), 7 deletions(-)
diff --git a/hare/parse/expr.ha b/hare/parse/expr.ha
@@ -618,8 +618,9 @@ fn control(lexer: *lex::lexer) (ast::expr | error) = {
case ltok::CONTINUE =>
yield label: ast::continue_expr;
case ltok::RETURN =>
- yield match (peek(lexer, ltok::COMMA,
- ltok::SEMICOLON, ltok::EOF)?) {
+ yield match (peek(lexer, ltok::COMMA, ltok::ELSE, ltok::RBRACE,
+ ltok::RBRACKET, ltok::RPAREN, ltok::SEMICOLON,
+ ltok::EOF)?) {
case void =>
yield alloc(expr(lexer)?): ast::return_expr;
case lex::token =>
@@ -1307,20 +1308,20 @@ fn yield_expr(lexer: *lex::lexer) (ast::expr | error) = {
const start = want(lexer, ltok::YIELD)?;
let label = "";
let value: nullable *ast::expr = null;
- match (try(lexer, ltok::SEMICOLON, ltok::COLON, ltok::EOF)?) {
+ match (try(lexer, ltok::COLON, ltok::COMMA, ltok::ELSE, ltok::RBRACE,
+ ltok::RBRACKET, ltok::RPAREN, ltok::SEMICOLON, ltok::EOF)?) {
case void =>
value = alloc(expr(lexer)?);
case let t: lex::token =>
- switch (t.0) {
- case ltok::SEMICOLON, ltok::EOF =>
- lex::unlex(lexer, t);
- case ltok::COLON =>
+ if (t.0 == ltok::COLON) {
label = want(lexer, ltok::NAME)?.1 as str;
match (try(lexer, ltok::COMMA)?) {
case void => void;
case lex::token =>
value = alloc(expr(lexer)?);
};
+ } else {
+ lex::unlex(lexer, t);
};
};
return ast::expr {