|
|
|
@ -128,6 +128,22 @@ export class Parser {
|
|
|
|
return expr;
|
|
|
|
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 {
|
|
|
|
private parseMatch(expr: AST): AST {
|
|
|
|
const cases: MatchCase[] = [];
|
|
|
|
const cases: MatchCase[] = [];
|
|
|
|
|
|
|
|
|
|
|
|
@ -135,7 +151,7 @@ export class Parser {
|
|
|
|
this.advance();
|
|
|
|
this.advance();
|
|
|
|
const pattern = this.parsePattern();
|
|
|
|
const pattern = this.parsePattern();
|
|
|
|
this.expect('backslash');
|
|
|
|
this.expect('backslash');
|
|
|
|
const result = this.parseInfix();
|
|
|
|
const result = this.parseExpressionNoMatch();
|
|
|
|
cases.push({ pattern, result })
|
|
|
|
cases.push({ pattern, result })
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@ -265,9 +281,9 @@ export class Parser {
|
|
|
|
const nameToken = this.expect('ident');
|
|
|
|
const nameToken = this.expect('ident');
|
|
|
|
const name = (nameToken as { value: string }).value;
|
|
|
|
const name = (nameToken as { value: string }).value;
|
|
|
|
this.expect('equals');
|
|
|
|
this.expect('equals');
|
|
|
|
const value = this.parseExpression();
|
|
|
|
const value = this.parseExpressionNoMatch();
|
|
|
|
this.expect('semicolon');
|
|
|
|
this.expect('semicolon');
|
|
|
|
const body = this.parseExpression();
|
|
|
|
const body = this.parseExpressionNoMatch();
|
|
|
|
|
|
|
|
|
|
|
|
return { kind: 'let', name, value, body };
|
|
|
|
return { kind: 'let', name, value, body };
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|