Adding debug builtin. Allowing us to assign to _ in lets

This commit is contained in:
Dustin Swan 2026-02-04 19:19:35 -07:00
parent 9f078aaeef
commit c44f06268f
No known key found for this signature in database
GPG key ID: 30D46587E2100467
4 changed files with 32 additions and 3 deletions

View file

@ -114,7 +114,7 @@ export class Parser {
}
// Let
if (this.current().kind === 'ident' && this.peek().kind === 'equals') {
if ((this.current().kind === 'ident' || this.current().kind === 'underscore') && this.peek().kind === 'equals') {
return this.parseLet();
}
@ -278,8 +278,20 @@ export class Parser {
}
private parseLet(): AST {
const nameToken = this.expect('ident');
const name = (nameToken as { value: string }).value;
const nameToken = this.current();
let name: string;
if (nameToken.kind === 'underscore') {
name = '_';
this.advance();
} else if (nameToken.kind === 'ident') {
name = (nameToken as { value: string }).value;
this.advance();
} else {
throw new Error(`Expected ident or underscore, got ${nameToken.kind}`);
}
this.expect('equals');
const value = this.parseExpressionNoMatch();
this.expect('semicolon');