Skip to content

fmt: add --ir to print the pretty printing IR - #1314

Closed
sbdchd wants to merge 1 commit into
masterfrom
claude/pretty-print-ir-output-x56heh
Closed

fmt: add --ir to print the pretty printing IR#1314
sbdchd wants to merge 1 commit into
masterfrom
claude/pretty-print-ir-output-x56heh

Conversation

@sbdchd

@sbdchd sbdchd commented Aug 29, 2026

Copy link
Copy Markdown
Owner

When a statement formats in a surprising way it helps to see the
tiny_pretty::Doc tree the formatter built, rather than the text that
tree printed to, so squawk-fmt --ir (and squawk_fmt::fmt_ir) dumps
it:

$ echo 'select a from t;' | squawk-fmt --ir
list [
  group [
    group [
      text "select"
      nest 2 [ line_or_space list [ text "a" ] ]
    ]
    line_or_space
    text "from"
    space
    nest 2 [ list [ text "t" ] ]
    text ";"
  ]
]

Doc derives Debug, but {:#?} is ~6x more lines and Doc::Nest's
payload type isn't exported by tiny_pretty, so we can't walk the tree
ourselves. Instead we parse the Debug output, which is a small,
regular grammar, and re-render it compactly, falling back to the raw
{:#?} if that parse ever fails.

Co-Authored-By: Claude Opus 5 noreply@anthropic.com
Claude-Session: https://claude.ai/code/session_01Dhw2RENug3ippmngYuaHop

When a statement formats in a surprising way it helps to see the
`tiny_pretty::Doc` tree the formatter built, rather than the text that
tree printed to, so `squawk-fmt --ir` (and `squawk_fmt::fmt_ir`) dumps
it:

    $ echo 'select a from t;' | squawk-fmt --ir
    list [
      group [
        group [
          text "select"
          nest 2 [ line_or_space list [ text "a" ] ]
        ]
        line_or_space
        text "from"
        space
        nest 2 [ list [ text "t" ] ]
        text ";"
      ]
    ]

`Doc` derives `Debug`, but `{:#?}` is ~6x more lines and `Doc::Nest`'s
payload type isn't exported by tiny_pretty, so we can't walk the tree
ourselves. Instead we parse the `Debug` output, which is a small,
regular grammar, and re-render it compactly, falling back to the raw
`{:#?}` if that parse ever fails.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Dhw2RENug3ippmngYuaHop
@sbdchd sbdchd closed this Aug 29, 2026
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.

2 participants