Switching to ML style type annotations. not separate statement from the expression

This commit is contained in:
Dustin Swan 2026-03-26 16:05:22 -06:00
parent 6acec5641c
commit f3c3a76671
No known key found for this signature in database
GPG key ID: 30D46587E2100467
6 changed files with 35 additions and 36 deletions

View file

@ -160,21 +160,6 @@ export class Parser {
continue;
}
// type annotation
if (this.current().kind === 'ident' && this.peek().kind === 'colon') {
this.advance(); // eat ident
this.advance();
const type = this.parseType();
this.expect('semicolon');
// parse definition
const def = this.parseDefinition();
def.annotation = { constraints: [], type };
definitions.push(def);
continue;
}
definitions.push(this.parseDefinition());
}
@ -185,6 +170,12 @@ export class Parser {
const nameToken = this.expect('ident');
const name = (nameToken as { value: string }).value;
let annotation: Annotation | undefined;
if (this.current().kind === 'colon') {
this.advance();
annotation = { constraints: [], type: this.parseType() };
}
this.expect('equals');
const body = this.parseExpression();
@ -193,7 +184,7 @@ export class Parser {
this.expect('semicolon');
}
return { kind: 'definition', name, body, ...this.getPos(nameToken) };
return { kind: 'definition', name, body, annotation, ...this.getPos(nameToken) };
}
private parseExpression(): AST {