More quoting nonsense
This commit is contained in:
parent
d79166a5bc
commit
515ad7fc9c
5 changed files with 593 additions and 9 deletions
10
src/ast.ts
10
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);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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
|
||||
}
|
||||
]
|
||||
}
|
||||
} };
|
||||
|
|
|
|||
|
|
@ -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
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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,
|
||||
|
|
|
|||
|
|
@ -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 "";
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue