Font editer coming a long. first font is looking good. some parser changes to accomodate any string as record fields. other stuff

This commit is contained in:
Dustin Swan 2026-02-23 21:11:20 -07:00
parent e3b8930111
commit d79166a5bc
No known key found for this signature in database
GPG key ID: 30D46587E2100467
6 changed files with 4987 additions and 25 deletions

View file

@ -220,7 +220,7 @@ export function prettyPrint(ast: AST, indent = 0): string {
const parts = ast.entries.map(entry =>
entry.kind === 'spread'
? `...${prettyPrint(entry.expr, indent + 1)}`
: `${entry.key} = ${prettyPrint(entry.value, indent + 1)}`
: `${needsQuotes(entry.key) ? `"${entry.key}"` : entry.key} = ${prettyPrint(entry.value, indent + 1)}`
);
if (parts.length <= 1) return `{ ${parts.join(', ')} }`;
const inner = parts.map(p => `${' '.repeat(indent + 1)}${p}`).join(',\n');
@ -238,11 +238,12 @@ export function prettyPrint(ast: AST, indent = 0): string {
}
case 'record-access':
return `${prettyPrint(ast.record, indent)}.${ast.field}`;
const field = needsQuotes(ast.field) ? `"${ast.field}"` : ast.field;
return `${prettyPrint(ast.record, indent)}.${field}`;
case 'record-update': {
const updates = Object.entries(ast.updates)
.map(([k, v]) => `${k} = ${prettyPrint(v, indent)}`)
.map(([k, v]) => `${needsQuotes(k) ? `"${k}"` : k} = ${prettyPrint(v, indent)}`)
.join(', ');
return `${prettyPrint(ast.record, indent)}.{ ${updates} }`
}
@ -298,7 +299,7 @@ function prettyPrintPattern(pattern: Pattern): string {
case 'record':
const fields = Object.entries(pattern.fields)
.map(([k, p]) => `${k} = ${prettyPrintPattern(p)}`)
.map(([k, p]) => `${needsQuotes(k) ? `"${k}"` : k} = ${prettyPrintPattern(p)}`)
.join(', ');
return `{${fields}}`;
@ -306,3 +307,7 @@ function prettyPrintPattern(pattern: Pattern): string {
return `Unknown AST kind: ${(pattern as any).kind}`
}
}
function needsQuotes(key: string): boolean {
return !/^[a-z_][a-zA-Z0-9_]*$/.test(key);
}