hare

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

commit 7c25166f2e4ec72ab37696dd0ed21da6133cbde7
parent 65be00677f3190335a9d2ad05112573b4ed4a4e9
Author: Alexey Yerin <yyp@disroot.org>
Date:   Tue, 31 Oct 2023 16:20:10 +0300

hare::parse: Disallow single type tagged unions

Similar to single item tuples, those are also disallowed in harec. They also
create invalid code in unparse->parse roundtrip.

Signed-off-by: Alexey Yerin <yyp@disroot.org>

Diffstat:
Mhare/parse/type.ha | 11+++++++++--
1 file changed, 9 insertions(+), 2 deletions(-)

diff --git a/hare/parse/type.ha b/hare/parse/type.ha @@ -180,9 +180,16 @@ fn tagged_type( ) (ast::_type | error) = { let tagged: ast::tagged_type = []; append(tagged, alloc(first)); - for (try(lexer, ltok::RPAREN)? is void) { + for (true) { append(tagged, alloc(_type(lexer)?)); - if (try(lexer, ltok::BOR)? is void) { + + match (try(lexer, ltok::BOR)?) { + case lex::token => + match (try(lexer, ltok::RPAREN)) { + case lex::token => break; + case => void; + }; + case void => want(lexer, ltok::RPAREN)?; break; };