Fixing pretty printer indentation. launching inspector when selecting any store value

master
Dustin Swan 2 weeks ago
parent 5c4ecbafdb
commit f27b946790
Signed by: dustinswan
GPG Key ID: 30D46587E2100467

@ -180,9 +180,9 @@ export function prettyPrint(ast: AST, indent = 0): string {
case 'literal': {
const val = ast.value;
if (val.kind === 'string') {
return `${i}"${val.value}"`;
return `"${val.value}"`;
}
return `${i}${val.value}`;
return `${val.value}`;
}
case 'variable':
@ -190,9 +190,9 @@ export function prettyPrint(ast: AST, indent = 0): string {
return ast.name;
case 'apply':
const func = prettyPrint(ast.func, 0);
const func = prettyPrint(ast.func, indent);
const args = ast.args.map(a => {
const printed = prettyPrint(a, 0);
const printed = prettyPrint(a, indent);
if (a.kind === 'lambda' || a.kind === 'match' || a.kind === 'let' || a.kind === 'rebind') {
return `(${printed})`;
}
@ -204,17 +204,22 @@ export function prettyPrint(ast: AST, indent = 0): string {
case 'let':
return `${ast.name} = ${prettyPrint(ast.value, indent + 1)};\n${i}${prettyPrint(ast.body, indent)}`
case 'list':
const elems = ast.elements.map(e => prettyPrint(e, 0)).join(', ');
return `[${elems}]`;
case 'list': {
const elems = ast.elements.map(e => prettyPrint(e, indent + 1))
if (elems.length <= 1) return `[${elems.join(', ')}]`;
const inner = elems.map(e => `${' '.repeat(indent + 1)}${e}`).join(',\n');
return `[\n${inner}\n${i}]`;
}
case 'record':
const parts = ast.entries.map(entry =>
entry.kind === 'spread'
? `...${prettyPrint(entry.expr, )}`
: `${entry.key} = ${prettyPrint(entry.value, 0)}`
? `...${prettyPrint(entry.expr, indent + 1)}`
: `${entry.key} = ${prettyPrint(entry.value, indent + 1)}`
);
return `{ ${parts.join(', ')} }`;
if (parts.length <= 1) return `{ ${parts.join(', ')} }`;
const inner = parts.map(p => `${' '.repeat(indent + 1)}${p}`).join(',\n');
return `{\n${inner}\n${i}}`;
case 'lambda': {
const params = ast.params.join(' ');
@ -228,27 +233,27 @@ export function prettyPrint(ast: AST, indent = 0): string {
}
case 'record-access':
return `${prettyPrint(ast.record, 0)}.${ast.field}`;
return `${prettyPrint(ast.record, indent)}.${ast.field}`;
case 'record-update': {
const updates = Object.entries(ast.updates)
.map(([k, v]) => `${k} = ${prettyPrint(v, 0)}`)
.map(([k, v]) => `${k} = ${prettyPrint(v, indent)}`)
.join(', ');
return `${prettyPrint(ast.record, 0)}.{ ${updates} }`
return `${prettyPrint(ast.record, indent)}.{ ${updates} }`
}
case 'match':
const expr = prettyPrint(ast.expr, 0);
const expr = prettyPrint(ast.expr, indent);
const cases = ast.cases
.map(c => `${i}| ${prettyPrintPattern(c.pattern)} \\ ${prettyPrint(c.result, indent + 1)}`)
.join('\n');
return `${expr}\n${cases}`;
case 'rebind':
return `${prettyPrint(ast.target, 0)} := ${prettyPrint(ast.value, 0)}`;
return `${prettyPrint(ast.target, indent)} := ${prettyPrint(ast.value, indent)}`;
case 'list-spread':
return `...${prettyPrint(ast.spread, 0)}`;
return `...${prettyPrint(ast.spread, indent)}`;
case 'definition':
return `${ast.name} = ${prettyPrint(ast.body, indent)};`;

@ -172,9 +172,9 @@ os =
result = eval input;
_ = debug "onSelect eval result" result;
result
| Value v \ openWindow input (_ \ ui.text { content = show v, color = "white" })
| Defined name \ openWindow name (size \ inspector { name = name, w = size.w, h = size.h })
| Err msg \ openWindow "Error" (_ \ ui.text { content = msg, color = "red" });
| Value v \ (getSource input == ""
| True \ openWindow input (_ \ ui.text { content = show v, color = "white" })
| False \ openWindow input (size \ inspector { name = input, w = size.w, h = size.h }));
handleFocusLeftEvent = state \
newIndex = max 0 (osState.wm.focusedIndex - 1);

Loading…
Cancel
Save