~sircmpwn/hare unlisted

2d55f1f6dd63d4c55e70b6acf08cfcc6d1fa1071 — Eyal Sawady a month ago 80f0833
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>
2 files changed, 17 insertions(+), 21 deletions(-)

M hare/parse/+test/expr.ha
M hare/parse/expr.ha
M hare/parse/+test/expr.ha => hare/parse/+test/expr.ha +1 -0
@@ 231,6 231,7 @@
		foo: int => bar,
		foo::bar => baz,
		null => void,
		*int => void,
	};
	match (x) {
		s: matchdata => y,

M hare/parse/expr.ha => hare/parse/expr.ha +16 -21
@@ 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"),
			},
		};