Conversation
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
Spelling error: "paraller" should be "parallel".
| 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 |
| SShift {width=width + w, dangle=dangle + w} tl | ||
| end in | ||
|
|
||
| # Handles paraller join of two given shift list |
There was a problem hiding this comment.
Spelling error: "paraller" should be "parallel".
| # Handles paraller join of two given shift list | |
| # Handles parallel join of two given shift list |
| end in | ||
|
|
||
| # Handles paraller join of two given shift list | ||
| # By assumpion w1 does NOT contain SLast label |
There was a problem hiding this comment.
Spelling error: "By assumpion" should be "By assumption".
| # By assumpion w1 does NOT contain SLast label | |
| # By assumption w1 does NOT contain SLast label |
lib/Pretty/Size.fram
Outdated
| assertEqF (t <> t.shift).width | ||
| (SShift {width=3, dangle=3} (SLast {width=3} (SFix {width=3})))); | ||
|
|
||
| testCase "`shift` aligns paraller structures" (fn () => |
There was a problem hiding this comment.
Spelling error: "paraller" should be "parallel".
| testCase "`shift` aligns paraller structures" (fn () => | |
| testCase "`shift` aligns parallel structures" (fn () => |
| 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. |
There was a problem hiding this comment.
Spelling error: "foramatted" should be "formatted".
| foramatted text. In every Size object there is exactly one SLast node. | |
| formatted text. In every Size object there is exactly one SLast node. |
| {## ## The pretty-printer module. ##} | ||
|
|
||
| {## | ||
| This module containes fully-featured pretty-printer library. |
There was a problem hiding this comment.
Spelling error: "containes" should be "contains".
| This module containes fully-featured pretty-printer library. | |
| This module contains fully-featured pretty-printer library. |
| pub let (text : String -> Doc) = Core.text | ||
|
|
||
| {## | ||
| Empty documnt. |
There was a problem hiding this comment.
Spelling error: "documnt" should be "document".
| Empty documnt. | |
| Empty document. |
| {## Enclosing of a document. ##} | ||
| pub let enclose l r d = l <> r <> d | ||
|
|
||
| {## Equotes given docuemnt. ##} |
There was a problem hiding this comment.
Spelling error: "docuemnt" should be "document".
| {## Equotes given docuemnt. ##} | |
| {## Equotes given document. ##} |
| # 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 |
There was a problem hiding this comment.
Spelling error: "permormed" should be "performed".
| # operation is permormed. The SLast label will be | |
| # operation is performed. The SLast label will be |
| (x, p + static) | ||
| else | ||
| match List.drop (n - 1) sh with | ||
| | [] => runtimeError "Alignment - not enought shifts" |
There was a problem hiding this comment.
Spelling error: "enought" should be "enough".
| | [] => runtimeError "Alignment - not enought shifts" | |
| | [] => runtimeError "Alignment - not enough shifts" |
|
I moved this PR as draft. I will update it once testing framework is ready |
A Pretty-pretting library with shift/reset aligment operators and true horizontal catenation.