Skip to content

refactor(pretty_print): remove GroupKind, pass the emitter first, enums instead of bool flags - #996

Open
psteinroe wants to merge 1 commit into
refactor/pretty-print-utilsfrom
refactor/pretty-print-arguments
Open

psteinroe wants to merge 1 commit into
refactor/pretty-print-utilsfrom
refactor/pretty-print-arguments

Conversation

@psteinroe

Copy link
Copy Markdown
Collaborator

Stacked on #995.

Three mechanical changes that the rest of the stack builds on. No output changes: every snapshot stays as it is.

What changed

  • GroupKind is gone. Every group_start took a kind, generated from the parser's node list, but the renderer never read it. LayoutEvent::GroupStart carries nothing now, emit_parenthesized_condition no longer takes a kind, and the group_kind macro is removed from pgls_pretty_print_codegen.
  • The emitter comes first everywhere. emit_node, emit_node_enum, emit_node_with, the list callbacks and the few private helpers that took (node, e) now take (e, node), like every emit_<node> already did. Closures passed to list helpers are |e, node|, and where a closure only forwarded to a function, the function is passed directly.
  • Variants take an enum instead of a bool:
    • case_expr: BranchPlacement::{Aligned, Indented} replaces align: bool.
    • range_var: Only::{Allowed, Omitted} replaces allow_only: bool.
    • alter_table_cmd: emit_alter_table_cmd_of(e, cmd, ObjectType) replaces for_type: bool, so ALTER TABLE passes its own object type.
    • object_with_args: ObjectArguments::{Signature, AggregateSignature, Omitted} replaces two bools and the emit_object_name_only / emit_object_with_args_for_aggregate wrappers.
    • json_value_expr: Prefix::{Space, None} replaces prefix_space: bool.
    • select_stmt: the set operation check takes the OperandSide from utils/predicates.rs instead of is_left_operand: bool.

The bools left in parameters carry state rather than pick a variant: whether something was already written (emitted_any, has_content, first), whether a row is followed by a comma, and whether a space precedes ENCODING.

Tests

  • cargo test -p pgls_pretty_print: no snapshot changes.
  • cargo test -p pgls_pretty_print --release --test option_matrix -- --ignored
  • cargo clippy --workspace --all-targets -- -D warnings

…lace bool flags with enums

The renderer never read the kind of a group. Every emitter, list callback
and helper now takes the emitter first. The variants that took a bool
(CASE alignment, ONLY, ALTER TYPE attributes, object arguments, JSON format
prefix, set operation side) take an enum.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant