evaluating pattern matching

This commit is contained in:
Dustin Swan 2026-02-01 19:22:50 -07:00
parent 7f94cfe8cd
commit a85203bc94
No known key found for this signature in database
GPG key ID: 30D46587E2100467
4 changed files with 102 additions and 9 deletions

View file

@ -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}`
}