hare

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

commit 2d55f1f6dd63d4c55e70b6acf08cfcc6d1fa1071
parent 80f0833a99201590dca745a6d67fc64b02f5c70f
Author: Eyal Sawady <ecs@d2evs.net>
Date:   Sun,  9 May 2021 17:33:57 -0400

hare::parse: fix pointer match cases

The previous version had an edge case and grew too far to the right.

Signed-off-by: Eyal Sawady <ecs@d2evs.net>

Diffstat:
Mhare/parse/+test/expr.ha | 1+
Mhare/parse/expr.ha | 37++++++++++++++++---------------------
2 files changed, 17 insertions(+), 21 deletions(-)

diff --git a/hare/parse/+test/expr.ha b/hare/parse/+test/expr.ha @@ -231,6 +231,7 @@ foo: int => bar, foo::bar => baz, null => void, + *int => void, }; match (x) { s: matchdata => y, diff --git a/hare/parse/expr.ha b/hare/parse/expr.ha @@ -983,28 +983,23 @@ fn match_expr(lexer: *lex::lexer) (ast::expr | error) = { for (true) { match (try(lexer, ltok::TIMES)?) { void => append(cases, match_case(lexer)?), - t: lex::token => { - match (peek(lexer, ltok::NAME)?) { - t: lex::token => { - let case = match_case(lexer)?; - case._type = alloc(ast::_type { - loc = case._type.loc, + t: lex::token => match (try(lexer, ltok::CASE)?) { + void => { + let case = match_case(lexer)?; + case._type = alloc(ast::_type { + loc = case._type.loc, + flags = 0, + _type = ast::pointer_type { + referent = case._type, flags = 0, - _type = ast::pointer_type { - referent = case._type, - flags = 0: ast::pointer_flags, - }, - }); - append(cases, case); - }, - void => { - want(lexer, ltok::CASE)?; - if (default != null) { - return syntaxerr(t.2, "More than one default match case"); - }; - default = alloc(expression(lexer)?); - }, - }; + }, + }); + append(cases, case); + }, + lex::token => if (default == null) { + default = alloc(expression(lexer)?); + } else return syntaxerr(t.2, + "More than one default match case"), }, };