@@ -176,15 +176,9 @@ impl Token {
176
176
}
177
177
178
178
#[ derive( Copy , Clone ) ]
179
- enum PrintStackBreak {
179
+ enum PrintFrame {
180
180
Fits ,
181
- Broken ( Breaks ) ,
182
- }
183
-
184
- #[ derive( Copy , Clone ) ]
185
- struct PrintStackElem {
186
- offset : isize ,
187
- pbreak : PrintStackBreak ,
181
+ Broken { offset : isize , breaks : Breaks } ,
188
182
}
189
183
190
184
const SIZE_INFINITY : isize = 0xffff ;
@@ -209,7 +203,7 @@ pub struct Printer {
209
203
/// advancing.
210
204
scan_stack : VecDeque < usize > ,
211
205
/// Stack of blocks-in-progress being flushed by print
212
- print_stack : Vec < PrintStackElem > ,
206
+ print_stack : Vec < PrintFrame > ,
213
207
/// Buffered indentation to avoid writing trailing whitespace
214
208
pending_indentation : isize ,
215
209
/// The token most recently popped from the left boundary of the
@@ -380,21 +374,19 @@ impl Printer {
380
374
self . pending_indentation += amount;
381
375
}
382
376
383
- fn get_top ( & self ) -> PrintStackElem {
384
- * self . print_stack . last ( ) . unwrap_or ( {
385
- & PrintStackElem { offset : 0 , pbreak : PrintStackBreak :: Broken ( Breaks :: Inconsistent ) }
386
- } )
377
+ fn get_top ( & self ) -> PrintFrame {
378
+ * self
379
+ . print_stack
380
+ . last ( )
381
+ . unwrap_or ( & PrintFrame :: Broken { offset : 0 , breaks : Breaks :: Inconsistent } )
387
382
}
388
383
389
384
fn print_begin ( & mut self , token : BeginToken , size : isize ) {
390
385
if size > self . space {
391
386
let col = self . margin - self . space + token. offset ;
392
- self . print_stack . push ( PrintStackElem {
393
- offset : col,
394
- pbreak : PrintStackBreak :: Broken ( token. breaks ) ,
395
- } ) ;
387
+ self . print_stack . push ( PrintFrame :: Broken { offset : col, breaks : token. breaks } ) ;
396
388
} else {
397
- self . print_stack . push ( PrintStackElem { offset : 0 , pbreak : PrintStackBreak :: Fits } ) ;
389
+ self . print_stack . push ( PrintFrame :: Fits ) ;
398
390
}
399
391
}
400
392
@@ -403,20 +395,19 @@ impl Printer {
403
395
}
404
396
405
397
fn print_break ( & mut self , token : BreakToken , size : isize ) {
406
- let top = self . get_top ( ) ;
407
- match top. pbreak {
408
- PrintStackBreak :: Fits => {
409
- self . space -= token. blank_space ;
398
+ match self . get_top ( ) {
399
+ PrintFrame :: Fits => {
410
400
self . indent ( token. blank_space ) ;
401
+ self . space -= token. blank_space ;
411
402
}
412
- PrintStackBreak :: Broken ( Breaks :: Consistent ) => {
413
- self . print_newline ( top . offset + token. offset ) ;
414
- self . space = self . margin - ( top . offset + token. offset ) ;
403
+ PrintFrame :: Broken { offset , breaks : Breaks :: Consistent } => {
404
+ self . print_newline ( offset + token. offset ) ;
405
+ self . space = self . margin - ( offset + token. offset ) ;
415
406
}
416
- PrintStackBreak :: Broken ( Breaks :: Inconsistent ) => {
407
+ PrintFrame :: Broken { offset , breaks : Breaks :: Inconsistent } => {
417
408
if size > self . space {
418
- self . print_newline ( top . offset + token. offset ) ;
419
- self . space = self . margin - ( top . offset + token. offset ) ;
409
+ self . print_newline ( offset + token. offset ) ;
410
+ self . space = self . margin - ( offset + token. offset ) ;
420
411
} else {
421
412
self . indent ( token. blank_space ) ;
422
413
self . space -= token. blank_space ;
0 commit comments