From fadf59c6aa4da7316430e8d4218e365ce1a05bc5 Mon Sep 17 00:00:00 2001 From: Dustin Swan Date: Tue, 3 Feb 2026 21:52:13 -0700 Subject: [PATCH] Fixing parsing matches, now we can grab full expressions in the body, reducing the need for parens to wrap multi-line match cases --- src/parser.ts | 22 +++++++++++++++++++--- 1 file changed, 19 insertions(+), 3 deletions(-) diff --git a/src/parser.ts b/src/parser.ts index 3ceb439..5d5af23 100644 --- a/src/parser.ts +++ b/src/parser.ts @@ -128,6 +128,22 @@ export class Parser { return expr; } + // Used in match, doesn't match another match + private parseExpressionNoMatch(): AST { + // Lambda + if (this.isLambdaStart()) { + return this.parseLambda(); + } + + // Let + if (this.current().kind === 'ident' && this.peek().kind === 'equals') { + return this.parseLet(); + } + + return this.parseInfix(); + } + + private parseMatch(expr: AST): AST { const cases: MatchCase[] = []; @@ -135,7 +151,7 @@ export class Parser { this.advance(); const pattern = this.parsePattern(); this.expect('backslash'); - const result = this.parseInfix(); + const result = this.parseExpressionNoMatch(); cases.push({ pattern, result }) } @@ -265,9 +281,9 @@ export class Parser { const nameToken = this.expect('ident'); const name = (nameToken as { value: string }).value; this.expect('equals'); - const value = this.parseExpression(); + const value = this.parseExpressionNoMatch(); this.expect('semicolon'); - const body = this.parseExpression(); + const body = this.parseExpressionNoMatch(); return { kind: 'let', name, value, body }; }