1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
//! # Typeset: A DSL for Pretty Printing
//!
//! Typeset is a powerful embedded domain-specific language (DSL) for defining source code pretty printers.
//! It provides a clean, compositional approach to formatting structured data with automatic line breaking,
//! indentation, and layout optimization.
//!
//! ## Quick Start
//!
//! ```rust
//! use typeset::{compile, render, text, comp, nest, grp};
//!
//! // Create a simple layout
//! let layout = comp(
//! text("function".to_string()),
//! nest(comp(
//! text("name()".to_string()),
//! text("{ body }".to_string()),
//! true, false
//! )),
//! true, false
//! );
//!
//! // Compile and render
//! let doc = compile(layout);
//! let output = render(doc, 2, 40);
//! println!("{}", output);
//! ```
//!
//! ## Core Concepts
//!
//! ### Layout Constructors
//!
//! Typeset provides several fundamental constructors for building layouts:
//!
//! - **[`text()`]** - Text literals that form the visible content
//! - **[`comp()`]** - Compositions that can break into multiple lines
//! - **[`line()`]** - Forced line breaks
//! - **[`nest()`]** - Indentation for nested content
//! - **[`pack()`]** - Alignment to first element position
//! - **[`grp()`]** - Groups that break together
//! - **[`seq()`]** - Sequences where if one breaks, all break
//! - **[`fix()`]** - Fixed content that never breaks
//!
//! ### Compilation Pipeline
//!
//! The library uses a sophisticated multi-pass compiler that transforms layouts through
//! several intermediate representations:
//!
//! ```text
//! Layout → Edsl → Serial → LinearDoc → FixedDoc → RebuildDoc →
//! DenullDoc → FinalDoc → Doc → String
//! ```
//!
//! This pipeline ensures optimal layout decisions and efficient memory usage.
//!
//! ## Architecture Overview
//!
//! The typeset library is organized into several key modules:
//!
//! - **Constructors** - Functions for building layout trees ([`text()`], [`comp()`], [`nest()`], etc.)
//! - **Compiler** - Multi-pass compilation pipeline that optimizes layouts
//! - **Types** - Core data structures for layouts and intermediate representations
//! - **Render** - Final rendering engine that produces formatted strings
//! - **Memory** - Efficient bump allocation for zero-copy transformations
//!
//! ## Error Handling
//!
//! The library provides both safe and unsafe compilation modes:
//!
//! - **[`compile()`]** - Fast compilation (may panic on stack overflow)
//! - **[`compile_safe()`]** - Safe compilation with error handling
//! - **[`compile_safe_with_depth()`]** - Safe compilation with custom recursion limits
//!
//! ## Performance
//!
//! Typeset is designed for high performance:
//!
//! - Zero-copy transformations using bump allocation
//! - Optimal line breaking algorithms
//! - Efficient memory management with controlled recursion
//! - Support for large documents without stack overflow
//!
//! ## Examples
//!
//! ### Basic Usage
//!
//! ```rust
//! use typeset::*;
//!
//! let layout = join_with_spaces(vec![
//! text("Hello".to_string()),
//! text("world!".to_string()),
//! ]);
//!
//! let result = format_layout(layout, 2, 80);
//! assert_eq!(result, "Hello world!");
//! ```
//!
//! ### Complex Formatting
//!
//! ```rust
//! use typeset::*;
//!
//! let json_object = braces(
//! join_with_commas(vec![
//! comp(text("\"name\"".to_string()), text("\"John\"".to_string()), true, false),
//! comp(text("\"age\"".to_string()), text("30".to_string()), true, false),
//! ])
//! );
//!
//! let result = format_layout(json_object, 2, 40);
//! // Output will adapt to width constraints automatically
//! ```
//!
//! ### With Parser (Optional)
//!
//! For more concise syntax, use the optional parser crate:
//!
//! ```ignore
//! use typeset_parser::layout;
//!
//! let my_layout = layout! {
//! nest ("function" + "name()")
//! pack ("{ body }")
//! };
//! ```
//!
//! ## Rust Version Compatibility
//!
//! This crate works on stable Rust (MSRV: 1.89.0). The test suite includes some components
//! that use unstable features like `box_patterns`, but the core library and procedural
//! macro work perfectly on stable Rust.
//!
//! ## Version 2.0 Changes
//!
//! Version 2.0 introduced a major architectural refactoring:
//!
//! - **Modular compiler passes** - Each compilation phase is now separate and testable
//! - **Improved error handling** - Better stack overflow protection and error reporting
//! - **Enhanced performance** - More efficient memory management and faster compilation
//! - **Better testing** - Comprehensive test suite with integration and performance tests
//!
//! The public API remains unchanged, ensuring seamless migration from v1.x.
pub use ;
// Re-export constructor functions
pub use ;
// Tests are now in the dedicated tests/ directory