We're checking types!!!!
This commit is contained in:
parent
f3c3a76671
commit
f272ffaca2
6 changed files with 304 additions and 24 deletions
27
src/ast.ts
27
src/ast.ts
|
|
@ -142,7 +142,7 @@ export type RecordUpdate = {
|
|||
export type Definition = {
|
||||
kind: 'definition'
|
||||
name: string
|
||||
body: AST
|
||||
body?: AST
|
||||
line?: number
|
||||
column?: number
|
||||
start?: number
|
||||
|
|
@ -327,6 +327,7 @@ export function prettyPrint(ast: AST, indent = 0): string {
|
|||
const ann = ast.annotation
|
||||
? ` : ${prettyPrintType(ast.annotation.type)}`
|
||||
: '';
|
||||
if (!ast.body) return `${ast.name}${ann};`;
|
||||
return `${ast.name}${ann} = ${prettyPrint(ast.body, indent)};`;
|
||||
|
||||
default:
|
||||
|
|
@ -398,18 +399,18 @@ export function prettyPrintType(type: TypeAST): string {
|
|||
}
|
||||
}
|
||||
|
||||
function prettyPrintTypeDefinition(td: TypeDefinition): string {
|
||||
const params = td.params.length > 0 ? ' ' + td.params.join(' ') : '';
|
||||
const ctors = td.constructors.map(c => {
|
||||
const args = c.args.map(a =>
|
||||
a.kind === 'type-function' || a.kind === 'type-apply'
|
||||
? `(${prettyPrintType(a)})`
|
||||
: prettyPrintType(a)
|
||||
).join(' ');
|
||||
return args ? `${c.name} ${args}` : c.name;
|
||||
}).join(' | ');
|
||||
return `${td.name}${params} = ${ctors};`;
|
||||
}
|
||||
// function prettyPrintTypeDefinition(td: TypeDefinition): string {
|
||||
// const params = td.params.length > 0 ? ' ' + td.params.join(' ') : '';
|
||||
// const ctors = td.constructors.map(c => {
|
||||
// const args = c.args.map(a =>
|
||||
// a.kind === 'type-function' || a.kind === 'type-apply'
|
||||
// ? `(${prettyPrintType(a)})`
|
||||
// : prettyPrintType(a)
|
||||
// ).join(' ');
|
||||
// return args ? `${c.name} ${args}` : c.name;
|
||||
// }).join(' | ');
|
||||
// return `${td.name}${params} = ${ctors};`;
|
||||
// }
|
||||
|
||||
function needsQuotes(key: string): boolean {
|
||||
return key === '_' || !/^[a-zA-Z_][a-zA-Z0-9_]*$/.test(key);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue