Fixing pretty printer not adding enough parens around record access things
This commit is contained in:
parent
a88a4fb764
commit
1a26ec4d24
1 changed files with 10 additions and 2 deletions
12
src/ast.ts
12
src/ast.ts
|
|
@ -319,9 +319,17 @@ export function prettyPrint(ast: AST, indent = 0): string {
|
||||||
return `${params} \\ ${body}`
|
return `${params} \\ ${body}`
|
||||||
}
|
}
|
||||||
|
|
||||||
case 'record-access':
|
case 'record-access': {
|
||||||
const field = needsQuotes(ast.field) ? `${JSON.stringify(ast.field)}` : ast.field;
|
const field = needsQuotes(ast.field) ? `${JSON.stringify(ast.field)}` : ast.field;
|
||||||
return `${prettyPrint(ast.record, indent)}.${field}`;
|
const inner = prettyPrint(ast.record, indent);
|
||||||
|
const needsParens = ast.record.kind === 'apply' ||
|
||||||
|
ast.record.kind === 'lambda' ||
|
||||||
|
ast.record.kind === 'match' ||
|
||||||
|
ast.record.kind === 'let' ||
|
||||||
|
ast.record.kind === 'rebind';
|
||||||
|
return needsParens ? `(${inner}).${field}` : `${inner}.${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)
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue