Adding debug builtin. Allowing us to assign to _ in lets
This commit is contained in:
parent
9f078aaeef
commit
c44f06268f
4 changed files with 32 additions and 3 deletions
|
|
@ -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');
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue