Skip to content

Pretty-printing library#256

Open
wojpok wants to merge 16 commits intofram-lang:masterfrom
wojpok:pp
Open

Pretty-printing library#256
wojpok wants to merge 16 commits intofram-lang:masterfrom
wojpok:pp

Conversation

@wojpok
Copy link
Collaborator

@wojpok wojpok commented Aug 17, 2025

A Pretty-pretting library with shift/reset aligment operators and true horizontal catenation.

Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR introduces a comprehensive pretty-printing library for the Fram language, featuring advanced alignment operators using shift/reset mechanisms and true horizontal concatenation. The library enables flexible document layout with automatic width management, non-local alignments for table formatting, and ANSI terminal styling support.

Key Changes:

  • Implements a sophisticated pretty-printing algorithm with layout selection based on Pareto optimality
  • Adds shift/reset alignment operators for automatic column alignment without pre-calculation
  • Provides true vertical concatenation (>+>) in addition to standard horizontal (<>) and line-break ($$) operators

Reviewed changes

Copilot reviewed 20 out of 20 changed files in this pull request and generated 23 comments.

Show a summary per file
File Description
lib/Pretty.fram Main public API exposing document types and combinators
lib/Pretty/Core.fram Core layout algorithm with Pareto selection and stream-based layout generation
lib/Pretty/Size.fram Size tracking with shift lists for managing floating alignment points
lib/Pretty/Lines.fram Line representation and rendering with alignment state management
lib/Pretty/Style.fram ANSI terminal styling support with color and text decoration options
lib/Stream.fram Adds lazyStream helper for lazy stream construction
pretty/examples/Example1-impPrettyPrinter.fram IMP language pretty-printer demonstrating library features
pretty/examples/Example2-table.fram Table formatting example using vertical separators
pretty/tutorial/Tutorial1-basic.fram Basic text document tutorial
pretty/tutorial/Tutorial2-combine.fram Horizontal combination operator tutorial
pretty/tutorial/Tutorial3-flush.fram Line break insertion tutorial
pretty/tutorial/Tutorial4-vcat.fram Vertical concatenation tutorial
pretty/tutorial/Tutorial5-hang.fram Hanging indent tutorial
pretty/tutorial/Tutorial6-aligns.fram Shift operator tutorial
pretty/tutorial/Tutorial7-alignScopes.fram Reset operator for alignment scopes tutorial
pretty/tutorial/Tutorial8-hcat.fram True horizontal concatenation tutorial
pretty/tutorial/Tutorial9-vsep.fram Vertical separator usage tutorial
pretty/tutorial/Tutorial10-style.fram ANSI styling tutorial
pretty/test/Test1-tablesWithHang.fram Test for table formatting with hanging indents
pretty/test/Test2-alignmentsUnderCat.fram Test for alignments under concatenation operators

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

pub let ($$) (d1 : Doc) (d2 : Doc) = d1.flush.combine d2

{##
Puts 2 documents in paraller. The last line will always be aligned with
Copy link

Copilot AI Dec 4, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Spelling error: "paraller" should be "parallel".

Suggested change
Puts 2 documents in paraller. The last line will always be aligned with
Puts 2 documents in parallel. The last line will always be aligned with

Copilot uses AI. Check for mistakes.
SShift {width=width + w, dangle=dangle + w} tl
end in

# Handles paraller join of two given shift list
Copy link

Copilot AI Dec 4, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Spelling error: "paraller" should be "parallel".

Suggested change
# Handles paraller join of two given shift list
# Handles parallel join of two given shift list

Copilot uses AI. Check for mistakes.
end in

# Handles paraller join of two given shift list
# By assumpion w1 does NOT contain SLast label
Copy link

Copilot AI Dec 4, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Spelling error: "By assumpion" should be "By assumption".

Suggested change
# By assumpion w1 does NOT contain SLast label
# By assumption w1 does NOT contain SLast label

Copilot uses AI. Check for mistakes.
assertEqF (t <> t.shift).width
(SShift {width=3, dangle=3} (SLast {width=3} (SFix {width=3}))));

testCase "`shift` aligns paraller structures" (fn () =>
Copy link

Copilot AI Dec 4, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Spelling error: "paraller" should be "parallel".

Suggested change
testCase "`shift` aligns paraller structures" (fn () =>
testCase "`shift` aligns parallel structures" (fn () =>

Copilot uses AI. Check for mistakes.
are willing to globally align with others.

The `SLast' node is a label that indicates a line where <> will attach
foramatted text. In every Size object there is exactly one SLast node.
Copy link

Copilot AI Dec 4, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Spelling error: "foramatted" should be "formatted".

Suggested change
foramatted text. In every Size object there is exactly one SLast node.
formatted text. In every Size object there is exactly one SLast node.

Copilot uses AI. Check for mistakes.
{## ## The pretty-printer module. ##}

{##
This module containes fully-featured pretty-printer library.
Copy link

Copilot AI Dec 4, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Spelling error: "containes" should be "contains".

Suggested change
This module containes fully-featured pretty-printer library.
This module contains fully-featured pretty-printer library.

Copilot uses AI. Check for mistakes.
pub let (text : String -> Doc) = Core.text

{##
Empty documnt.
Copy link

Copilot AI Dec 4, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Spelling error: "documnt" should be "document".

Suggested change
Empty documnt.
Empty document.

Copilot uses AI. Check for mistakes.
{## Enclosing of a document. ##}
pub let enclose l r d = l <> r <> d

{## Equotes given docuemnt. ##}
Copy link

Copilot AI Dec 4, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Spelling error: "docuemnt" should be "document".

Suggested change
{## Equotes given docuemnt. ##}
{## Equotes given document. ##}

Copilot uses AI. Check for mistakes.
# The starting point of algorithm
# The <> catenation happens at `SLast' node of w1, thus
# width is copied up until `SLast' and then combineWs
# operation is permormed. The SLast label will be
Copy link

Copilot AI Dec 4, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Spelling error: "permormed" should be "performed".

Suggested change
# operation is permormed. The SLast label will be
# operation is performed. The SLast label will be

Copilot uses AI. Check for mistakes.
(x, p + static)
else
match List.drop (n - 1) sh with
| [] => runtimeError "Alignment - not enought shifts"
Copy link

Copilot AI Dec 4, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Spelling error: "enought" should be "enough".

Suggested change
| [] => runtimeError "Alignment - not enought shifts"
| [] => runtimeError "Alignment - not enough shifts"

Copilot uses AI. Check for mistakes.
@wojpok wojpok marked this pull request as draft December 11, 2025 09:12
@wojpok
Copy link
Collaborator Author

wojpok commented Dec 11, 2025

I moved this PR as draft. I will update it once testing framework is ready

@wojpok wojpok marked this pull request as ready for review January 21, 2026 19:27
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