More quoting nonsense

master
Dustin Swan 4 days ago
parent d79166a5bc
commit 515ad7fc9c
Signed by: dustinswan
GPG Key ID: 30D46587E2100467

@ -220,7 +220,7 @@ export function prettyPrint(ast: AST, indent = 0): string {
const parts = ast.entries.map(entry => const parts = ast.entries.map(entry =>
entry.kind === 'spread' entry.kind === 'spread'
? `...${prettyPrint(entry.expr, indent + 1)}` ? `...${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(', ')} }`; if (parts.length <= 1) return `{ ${parts.join(', ')} }`;
const inner = parts.map(p => `${' '.repeat(indent + 1)}${p}`).join(',\n'); 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': 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}`; return `${prettyPrint(ast.record, indent)}.${field}`;
case 'record-update': { case 'record-update': {
const updates = Object.entries(ast.updates) 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(', '); .join(', ');
return `${prettyPrint(ast.record, indent)}.{ ${updates} }` return `${prettyPrint(ast.record, indent)}.{ ${updates} }`
} }
@ -299,7 +299,7 @@ function prettyPrintPattern(pattern: Pattern): string {
case 'record': case 'record':
const fields = Object.entries(pattern.fields) 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(', '); .join(', ');
return `{${fields}}`; return `{${fields}}`;
@ -309,5 +309,5 @@ function prettyPrintPattern(pattern: Pattern): string {
} }
function needsQuotes(key: string): boolean { function needsQuotes(key: string): boolean {
return !/^[a-z_][a-zA-Z0-9_]*$/.test(key); return !/^[a-zA-Z_][a-zA-Z0-9_]*$/.test(key);
} }

@ -4938,5 +4938,579 @@
y = 4 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
}
]
} }
} }; } };

@ -5,7 +5,8 @@ fontEditor = config \
c = { ...defaults, ...config }; c = { ...defaults, ...config };
existing = eval! (c.path); existing = getAt c.path;
_ = debug! "existing" existing;
# return app # return app
{ {
@ -21,7 +22,7 @@ fontEditor = config \
key = "fontEditor-" & c.path, key = "fontEditor-" & c.path,
init = existing init = existing
| Value v \ { | Some v \ {
glyphs = v.glyphs, glyphs = v.glyphs,
height = v.height height = v.height
} }

@ -35,7 +35,7 @@ pixelEditor = config \
newState = state.{ map = newMap }; newState = state.{ map = newMap };
{ state = newState, emit = saveGlyph newState }); { state = newState, emit = saveGlyph newState });
existing = eval! (c.path); existing = getAt c.path;
_ = debug! "existing" existing; _ = debug! "existing" existing;
# return App # return App
@ -49,7 +49,7 @@ pixelEditor = config \
key = "pixelEditor-" & c.path, key = "pixelEditor-" & c.path,
init = existing init = existing
| Value v \ { | Some v \ {
map = v.map, map = v.map,
pixelWidth = v.w, pixelWidth = v.w,
pixelHeight = v.h, pixelHeight = v.h,

@ -107,6 +107,15 @@ export const _rt = {
.filter(name => _rt.fuzzyMatch(query)(name)._tag === 'True') .filter(name => _rt.fuzzyMatch(query)(name)._tag === 'True')
.sort((a, b) => a.length - b.length); .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) => { getSource: (name: string) => {
const ast = definitions.get(name); const ast = definitions.get(name);
if (!ast) return ""; if (!ast) return "";

Loading…
Cancel
Save