From 515ad7fc9c6b156d8ea689f58d35548653e5bf5e Mon Sep 17 00:00:00 2001 From: Dustin Swan Date: Mon, 23 Feb 2026 22:22:13 -0700 Subject: [PATCH] More quoting nonsense --- src/ast.ts | 10 +- src/cg/06-font.cg | 574 +++++++++++++++++++++++++++++++++++++++ src/cg/06-fontEditor.cg | 5 +- src/cg/06-pixelEditor.cg | 4 +- src/runtime-js.ts | 9 + 5 files changed, 593 insertions(+), 9 deletions(-) diff --git a/src/ast.ts b/src/ast.ts index 46a1fa6..9e8cd3e 100644 --- a/src/ast.ts +++ b/src/ast.ts @@ -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)}` - : `${needsQuotes(entry.key) ? `"${entry.key}"` : entry.key} = ${prettyPrint(entry.value, indent + 1)}` + : `${needsQuotes(entry.key) ? JSON.stringify(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,12 +238,12 @@ export function prettyPrint(ast: AST, indent = 0): string { } case 'record-access': - const field = needsQuotes(ast.field) ? `"${ast.field}"` : ast.field; + const field = needsQuotes(ast.field) ? `${JSON.stringify(ast.field)}` : ast.field; return `${prettyPrint(ast.record, indent)}.${field}`; case 'record-update': { const updates = Object.entries(ast.updates) - .map(([k, v]) => `${needsQuotes(k) ? `"${k}"` : k} = ${prettyPrint(v, indent)}`) + .map(([k, v]) => `${needsQuotes(k) ? `${JSON.stringify(k)}` : k} = ${prettyPrint(v, indent)}`) .join(', '); return `${prettyPrint(ast.record, indent)}.{ ${updates} }` } @@ -299,7 +299,7 @@ function prettyPrintPattern(pattern: Pattern): string { case 'record': const fields = Object.entries(pattern.fields) - .map(([k, p]) => `${needsQuotes(k) ? `"${k}"` : k} = ${prettyPrintPattern(p)}`) + .map(([k, p]) => `${needsQuotes(k) ? `${JSON.stringify(k)}` : k} = ${prettyPrintPattern(p)}`) .join(', '); return `{${fields}}`; @@ -309,5 +309,5 @@ function prettyPrintPattern(pattern: Pattern): string { } function needsQuotes(key: string): boolean { - return !/^[a-z_][a-zA-Z0-9_]*$/.test(key); + return !/^[a-zA-Z_][a-zA-Z0-9_]*$/.test(key); } diff --git a/src/cg/06-font.cg b/src/cg/06-font.cg index 5a0c78f..901fed3 100644 --- a/src/cg/06-font.cg +++ b/src/cg/06-font.cg @@ -4938,5 +4938,579 @@ y = 4 } ] + }, + "&" = { + w = 7, + h = 12, + map = [ + { + x = 3, + y = 2 + }, + { + x = 4, + y = 2 + }, + { + x = 5, + y = 3 + }, + { + x = 5, + y = 4 + }, + { + x = 4, + y = 5 + }, + { + x = 1, + y = 6 + }, + { + x = 3, + y = 5 + }, + { + x = 2, + y = 8 + }, + { + x = 3, + y = 8 + }, + { + x = 4, + y = 8 + }, + { + x = 5, + y = 7 + }, + { + x = 6, + y = 6 + }, + { + x = 1, + y = 7 + }, + { + x = 4, + y = 6 + }, + { + x = 6, + y = 8 + }, + { + x = 2, + y = 4 + }, + { + x = 2, + y = 3 + }, + { + x = 2, + y = 5 + } + ] + }, + "*" = { + w = 7, + h = 12, + map = [ + { + x = 3, + y = 1 + }, + { + x = 3, + y = 2 + }, + { + x = 3, + y = 3 + }, + { + x = 3, + y = 4 + }, + { + x = 3, + y = 5 + }, + { + x = 3, + y = 6 + }, + { + x = 1, + y = 2 + }, + { + x = 2, + y = 3 + }, + { + x = 4, + y = 4 + }, + { + x = 5, + y = 5 + }, + { + x = 5, + y = 2 + }, + { + x = 4, + y = 3 + }, + { + x = 2, + y = 4 + }, + { + x = 1, + y = 5 + } + ] + }, + "(" = { + w = 7, + h = 12, + map = [ + { + x = 3, + y = 2 + }, + { + x = 2, + y = 3 + }, + { + x = 2, + y = 4 + }, + { + x = 2, + y = 5 + }, + { + x = 2, + y = 6 + }, + { + x = 2, + y = 7 + }, + { + x = 3, + y = 8 + } + ] + }, + ")" = { + w = 7, + h = 12, + map = [ + { + x = 3, + y = 2 + }, + { + x = 4, + y = 3 + }, + { + x = 4, + y = 4 + }, + { + x = 4, + y = 5 + }, + { + x = 4, + y = 6 + }, + { + x = 4, + y = 7 + }, + { + x = 3, + y = 8 + } + ] + }, + "[" = { + w = 7, + h = 12, + map = [ + { + x = 3, + y = 2 + }, + { + x = 2, + y = 2 + }, + { + x = 2, + y = 3 + }, + { + x = 2, + y = 4 + }, + { + x = 2, + y = 5 + }, + { + x = 2, + y = 7 + }, + { + x = 2, + y = 8 + }, + { + x = 2, + y = 6 + }, + { + x = 3, + y = 8 + } + ] + }, + "]" = { + w = 7, + h = 12, + map = [ + { + x = 3, + y = 2 + }, + { + x = 4, + y = 2 + }, + { + x = 4, + y = 3 + }, + { + x = 4, + y = 4 + }, + { + x = 4, + y = 5 + }, + { + x = 4, + y = 8 + }, + { + x = 4, + y = 7 + }, + { + x = 4, + y = 6 + }, + { + x = 3, + y = 8 + } + ] + }, + "{" = { + w = 7, + h = 12, + map = [ + { + x = 4, + y = 2 + }, + { + x = 3, + y = 2 + }, + { + x = 2, + y = 3 + }, + { + x = 2, + y = 4 + }, + { + x = 1, + y = 5 + }, + { + x = 2, + y = 6 + }, + { + x = 2, + y = 7 + }, + { + x = 3, + y = 8 + }, + { + x = 4, + y = 8 + } + ] + }, + "}" = { + w = 7, + h = 12, + map = [ + { + x = 2, + y = 2 + }, + { + x = 3, + y = 2 + }, + { + x = 4, + y = 3 + }, + { + x = 4, + y = 4 + }, + { + x = 5, + y = 5 + }, + { + x = 4, + y = 6 + }, + { + x = 4, + y = 7 + }, + { + x = 3, + y = 8 + }, + { + x = 2, + y = 8 + } + ] + }, + "/" = { + w = 7, + h = 12, + map = [ + { + x = 5, + y = 2 + }, + { + x = 4, + y = 3 + }, + { + x = 4, + y = 4 + }, + { + x = 3, + y = 5 + }, + { + x = 3, + y = 6 + }, + { + x = 2, + y = 7 + }, + { + x = 2, + y = 8 + } + ] + }, + "\\" = { + w = 7, + h = 12, + map = [ + { + x = 1, + y = 2 + }, + { + x = 2, + y = 3 + }, + { + x = 2, + y = 4 + }, + { + x = 3, + y = 5 + }, + { + x = 3, + y = 6 + }, + { + x = 4, + y = 7 + }, + { + x = 4, + y = 8 + } + ] + }, + "?" = { + w = 7, + h = 12, + map = [ + { + x = 2, + y = 2 + }, + { + x = 3, + y = 2 + }, + { + x = 4, + y = 2 + }, + { + x = 5, + y = 3 + }, + { + x = 1, + y = 3 + }, + { + x = 5, + y = 4 + }, + { + x = 4, + y = 5 + }, + { + x = 3, + y = 6 + }, + { + x = 3, + y = 8 + } + ] + }, + "=" = { + w = 7, + h = 12, + map = [ + { + x = 1, + y = 4 + }, + { + x = 2, + y = 4 + }, + { + x = 3, + y = 4 + }, + { + x = 4, + y = 4 + }, + { + x = 5, + y = 4 + }, + { + x = 1, + y = 7 + }, + { + x = 2, + y = 7 + }, + { + x = 3, + y = 7 + }, + { + x = 4, + y = 7 + }, + { + x = 5, + y = 7 + } + ] + }, + "+" = { + w = 7, + h = 12, + map = [ + { + x = 3, + y = 3 + }, + { + x = 3, + y = 4 + }, + { + x = 3, + y = 5 + }, + { + x = 3, + y = 6 + }, + { + x = 3, + y = 7 + }, + { + x = 1, + y = 5 + }, + { + x = 2, + y = 5 + }, + { + x = 4, + y = 5 + }, + { + x = 5, + y = 5 + } + ] } } }; diff --git a/src/cg/06-fontEditor.cg b/src/cg/06-fontEditor.cg index f612583..5669a8b 100644 --- a/src/cg/06-fontEditor.cg +++ b/src/cg/06-fontEditor.cg @@ -5,7 +5,8 @@ fontEditor = config \ c = { ...defaults, ...config }; - existing = eval! (c.path); + existing = getAt c.path; + _ = debug! "existing" existing; # return app { @@ -21,7 +22,7 @@ fontEditor = config \ key = "fontEditor-" & c.path, init = existing - | Value v \ { + | Some v \ { glyphs = v.glyphs, height = v.height } diff --git a/src/cg/06-pixelEditor.cg b/src/cg/06-pixelEditor.cg index 05a559d..7b6659c 100644 --- a/src/cg/06-pixelEditor.cg +++ b/src/cg/06-pixelEditor.cg @@ -35,7 +35,7 @@ pixelEditor = config \ newState = state.{ map = newMap }; { state = newState, emit = saveGlyph newState }); - existing = eval! (c.path); + existing = getAt c.path; _ = debug! "existing" existing; # return App @@ -49,7 +49,7 @@ pixelEditor = config \ key = "pixelEditor-" & c.path, init = existing - | Value v \ { + | Some v \ { map = v.map, pixelWidth = v.w, pixelHeight = v.h, diff --git a/src/runtime-js.ts b/src/runtime-js.ts index 4997ac9..9562507 100644 --- a/src/runtime-js.ts +++ b/src/runtime-js.ts @@ -107,6 +107,15 @@ export const _rt = { .filter(name => _rt.fuzzyMatch(query)(name)._tag === 'True') .sort((a, b) => a.length - b.length); }, + getAt: (pathStr: string) => { + const parts = pathStr.split('.'); + let obj: any = store[parts[0]]; + for (let i = 1; i < parts.length; i++) { + if (obj === undefined || obj === null) return { _tag: 'None' }; + obj = obj[parts[i]]; + } + return obj === undefined ? { _tag: 'None' } : { _tag: 'Some', _0: obj }; + }, getSource: (name: string) => { const ast = definitions.get(name); if (!ast) return "";