evaluating pattern matching
This commit is contained in:
parent
7f94cfe8cd
commit
a85203bc94
4 changed files with 102 additions and 9 deletions
15
src/ast.ts
15
src/ast.ts
|
|
@ -126,8 +126,18 @@ export function prettyPrint(ast: AST, indent = 0): string {
|
|||
const i = ' '.repeat(indent);
|
||||
|
||||
switch (ast.kind) {
|
||||
case 'literal':
|
||||
return `${i}${ast.value}`;
|
||||
case 'literal': {
|
||||
const val = ast.value;
|
||||
switch (val.kind) {
|
||||
case 'int':
|
||||
case 'float':
|
||||
return `${i}${val.value}`;
|
||||
case 'string':
|
||||
return `${i}"${val.value}"`;
|
||||
default:
|
||||
return `${i}${val.kind}`;
|
||||
}
|
||||
}
|
||||
|
||||
case 'variable':
|
||||
return `${i}${ast.name}`;
|
||||
|
|
@ -171,7 +181,6 @@ export function prettyPrint(ast: AST, indent = 0): string {
|
|||
.join('\n');
|
||||
return `${i}match ${expr}\n${cases}`;
|
||||
|
||||
|
||||
default:
|
||||
return `${i}${ast.kind}`
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue