You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
- [x] BooleanTest (IS TRUE/FALSE/UNKNOWN and negations)
752
752
- [x] CallStmt (CALL procedure)
753
753
- [x] CaseExpr (CASE WHEN ... THEN ... ELSE ... END)
@@ -939,6 +939,9 @@ Keep this section focused on durable guidance. When you add new insights, summar
939
939
- Render symbolic operator names (composed purely of punctuation) without quoting and force a space before parentheses so DROP/ALTER statements remain parseable.
940
940
- Drop `LineType::SoftOrSpace` before optional DML clauses so compact statements stay single-line while long lists can wrap cleanly.
941
941
- Drop `LineType::SoftOrSpace` before `OVER` clauses and each window spec segment so inline window functions can wrap without blowing per-line limits while still re-parsing to the same AST.
942
+
- Preserve explicit parentheses in arithmetic expressions by wrapping child `AExpr` nodes whenever their operator precedence is lower than the parent or a left-associative parent holds a right-nested operand; otherwise constructs like `100 * 3 + (vs.i - 1) * 3` lose grouping and fail AST equality.
943
+
- Wrap `BoolExpr` children whose precedence is lower than their parent (e.g. OR under AND, AND/OR under NOT) so expressions like `(a OR b) AND c` retain explicit parentheses and keep the original AST structure.
944
+
- Use `emit_clause_condition` to indent boolean clause bodies (`WHERE`, `HAVING`, planner filters) so wrapped predicates align under their keywords instead of hugging the left margin.
942
945
943
946
**Node-Specific Patterns**:
944
947
- Respect `CoercionForm` when emitting row constructors; implicit casts must stay bare tuples or the planner-visible `row_format` flag changes.
@@ -948,6 +951,7 @@ Keep this section focused on durable guidance. When you add new insights, summar
948
951
- Decode window frame bitmasks to render RANGE/ROWS/GROUPS with the correct UNBOUNDED/CURRENT/OFFSET bounds and guard PRECEDING/FOLLOWING against missing offsets.
949
952
- Ordered-set aggregates must render `WITHIN GROUP (ORDER BY ...)` outside the argument list and emit `FILTER (WHERE ...)` ahead of any `OVER` clause so planner fallbacks reuse the same surface layout.
950
953
- For `MergeStmt`, only append `BY TARGET` when the clause has no predicate (the `DO NOTHING` branch); conditional branches should stay as bare `WHEN NOT MATCHED` so we don't rewrite user intent.
954
+
- When a binary comparison must wrap, keep the operator attached to the left expression and indent the right-hand side behind a `LineType::SoftOrSpace` break. This avoids the renderer splitting each token onto its own line once the surrounding group has already broken.
951
955
952
956
**Planner Nodes (CRITICAL - Read Carefully)**:
953
957
- **NEVER create synthetic nodes or wrap nodes in SELECT statements for deparse round-trips**. This violates the architecture and breaks AST preservation.
@@ -1009,7 +1013,8 @@ just ready
1009
1013
1010
1014
## Next Steps
1011
1015
1012
-
1. Investigate the remaining line-length failure in `test_multi__window_60`; the embedded `CREATE FUNCTION` body still emits a long SQL string that blows past the 60-column budget, so we either need a smarter break in the ViewStmt emitter or a harness carve-out for multiline literals.
1016
+
1. Investigate why `ResTarget` aliases are still quoted even when lowercase-only, and adjust the identifier helper if we can emit bare aliases without breaking AST equality.
1017
+
2. Audit rename/owner emitters so non-table object types (FDWs, conversions, operator families) carry their specific keywords and reshape lists like `USING` clauses without falling back to `ALTER TABLE`.
**Tests**: `cargo test -p pgls_pretty_print test_single__update_with_cte_returning_0_60 -- --show-output`; `cargo test -p pgls_pretty_print test_multi__float4_60 -- --show-output`
14
+
**Key Changes**:
15
+
- Reworked `emit_clause_condition` and `emit_aexpr_op` so binary comparisons keep their operator with the left-hand side while permitting the right-hand side to wrap with indentation, preventing per-token line splitting.
16
+
- Reviewed and accepted snapshot churn after the clause helper landed, ensuring the layout changes are captured for SELECT/UPDATE predicates and JSON-heavy fixtures.
17
+
- Documented the wrapping pattern and queued follow-up work for rename/owner emitters that still fall back to `ALTER TABLE`.
18
+
19
+
**Learnings**:
20
+
- The current renderer breaks every `SoftOrSpace` once a group overflows, so grouping the left operand and operator together is critical to avoid fragmented predicates.
21
+
- Owner/rename emitters for non-table object types still need bespoke formatting to keep AST equality—worth calling out explicitly in durable guidance and Next Steps.
22
+
23
+
**Next Steps**:
24
+
- Expand rename/owner support so conversions, FDWs, and operator families emit their proper keywords rather than defaulting to `ALTER TABLE`.
25
+
- Re-run the full pretty-print suite once the rename emitters are tightened.
26
+
---
27
+
28
+
---
29
+
**Date**: 2025-10-30 (Session 66)
30
+
**Nodes Implemented/Fixed**: Clause body indentation helper; WHERE/HAVING emitters
- Introduced `emit_clause_condition` and rewired WHERE/HAVING, planner filters, and related clauses to use it so wrapped predicates indent beneath their clause keyword.
35
+
- Updated durable guidance to document the helper and removed the completed Next Step on clause indentation.
36
+
- Verified new layout on targeted fixtures; snapshots remain to be refreshed once the broader suite is reviewed.
37
+
38
+
**Learnings**:
39
+
- Centralising boolean clause formatting behind a shared helper keeps indentation consistent across statement emitters and simplifies future adjustments.
40
+
- Planner FILTER clauses (Aggref/FuncCall/WindowFunc) benefit from the same indentation logic, avoiding bespoke spacing tweaks.
41
+
42
+
**Next Steps**:
43
+
- Review snapshot fallout from clause indentation and accept once output looks stable across multi-statement fixtures.
44
+
- Resume investigation into emitting bare lowercase `ResTarget` aliases without reintroducing AST churn.
**Tests**: cargo test -p pgls_pretty_print test_single__bool_expr_parentheses_0_80 -- --show-output; cargo test -p pgls_pretty_print test_single__aexpr_precedence_parentheses_0_80 -- --show-output; cargo insta accept
52
+
**Key Changes**:
53
+
- Added precedence-aware parentheses handling in `emit_bool_expr` so nested OR/AND/NOT combinations keep the original grouping.
54
+
- Introduced `bool_expr_parentheses_0_80.sql` and `aexpr_precedence_parentheses_0_80.sql` single-statement fixtures and accepted their snapshots to lock in coverage.
55
+
- Updated durable guidance and Next Steps to track indentation follow-ups and alias-quoting investigations.
56
+
57
+
**Learnings**:
58
+
- BoolExpr trees rely on operator precedence rather than explicit markers; wrapping lower-precedence children is required to preserve `(a OR b) AND c`-style groupings during pretty printing.
59
+
- Clearing lingering `.snap.new` files via `cargo insta accept` prevents legacy snapshot churn from obscuring new regressions.
**Tests**: cargo test -p pgls_pretty_print test_multi__window_60 -- --nocapture
71
+
**Key Changes**:
72
+
- Added operator-precedence analysis in `emit_aexpr_op` so lower-precedence or right-nested operands are wrapped, restoring parentheses for expressions like `100 * 3 + (vs.i - 1) * 3`.
73
+
- Updated the `window_60` snapshot to reflect the restored grouping and verified the multi-statement harness now passes without AST diffs.
74
+
- Captured durable guidance about preserving explicit arithmetic parentheses in `agentic/pretty_printer.md` and refreshed the Next Steps queue.
75
+
76
+
**Learnings**:
77
+
- Preserving AST structure for arithmetic requires checking both precedence and associativity; wrapping only lower-precedence children is insufficient when left-associative parents hold right-nested operands.
78
+
79
+
**Next Steps**:
80
+
- Extend `BoolExpr` emission to keep user-written parentheses when mixing AND/OR so precedence alone doesn't change the tree shape.
81
+
- Add focused fixtures exercising the new `AExpr` precedence guard to prevent regressions.
82
+
---
83
+
9
84
---
10
85
**Date**: 2025-10-23 (Session 63)
11
86
**Nodes Implemented/Fixed**: MergeStmt emitter tweaks; JSON_TABLE and ordered-set coverage
0 commit comments