Switching to ML style type annotations. not separate statement from the expression
This commit is contained in:
parent
6acec5641c
commit
f3c3a76671
6 changed files with 35 additions and 36 deletions
|
|
@ -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 {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue