hare

The Hare programming language
git clone https://git.torresjrjr.com/hare.git
Log | Files | Refs | README | LICENSE

commit 2d570e4371baf7ec84884c279171c7eaca759571
parent e3ff09296066bb007b77372227c435ffa680c839
Author: Sebastian <sebastian@sebsite.pw>
Date:   Thu, 21 Apr 2022 15:41:22 -0400

hare::parse: accept EOF after return or yield

This is mainly to make it easier to test these expressions, since
another expression may or may not follow. EOF behaves the same as a
semicolon.

Signed-off-by: Sebastian <sebastian@sebsite.pw>

Diffstat:
Mhare/parse/expr.ha | 7++++---
1 file changed, 4 insertions(+), 3 deletions(-)

diff --git a/hare/parse/expr.ha b/hare/parse/expr.ha @@ -530,7 +530,8 @@ 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)?) { + yield match (peek(lexer, ltok::COMMA, + ltok::SEMICOLON, ltok::EOF)?) { case void => yield alloc(expr(lexer)?): ast::return_expr; case lex::token => @@ -1194,12 +1195,12 @@ 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::LABEL)?) { + match (try(lexer, ltok::SEMICOLON, ltok::LABEL, ltok::EOF)?) { case void => value = alloc(expr(lexer)?); case let t: lex::token => switch (t.0) { - case ltok::SEMICOLON => + case ltok::SEMICOLON, ltok::EOF => lex::unlex(lexer, t); case ltok::LABEL => label = t.1 as str;