@@ -309,10 +309,12 @@ impl<'a> Printer<'a> {
309
309
pub fn last_token ( & mut self ) -> Token {
310
310
self . buf [ self . right ] . token . clone ( )
311
311
}
312
- /// be very careful with this!
312
+
313
+ /// Be very careful with this!
313
314
pub fn replace_last_token ( & mut self , t : Token ) {
314
315
self . buf [ self . right ] . token = t;
315
316
}
317
+
316
318
pub fn pretty_print ( & mut self , token : Token ) -> io:: Result < ( ) > {
317
319
debug ! ( "pp Vec<{},{}>" , self . left, self . right) ;
318
320
match token {
@@ -387,6 +389,7 @@ impl<'a> Printer<'a> {
387
389
}
388
390
}
389
391
}
392
+
390
393
pub fn check_stream ( & mut self ) -> io:: Result < ( ) > {
391
394
debug ! ( "check_stream Vec<{}, {}> with left_total={}, right_total={}" ,
392
395
self . left, self . right, self . left_total, self . right_total) ;
@@ -405,19 +408,24 @@ impl<'a> Printer<'a> {
405
408
}
406
409
Ok ( ( ) )
407
410
}
411
+
408
412
pub fn scan_push ( & mut self , x : usize ) {
409
413
debug ! ( "scan_push {}" , x) ;
410
414
self . scan_stack . push_front ( x) ;
411
415
}
416
+
412
417
pub fn scan_pop ( & mut self ) -> usize {
413
418
self . scan_stack . pop_front ( ) . unwrap ( )
414
419
}
420
+
415
421
pub fn scan_top ( & mut self ) -> usize {
416
422
* self . scan_stack . front ( ) . unwrap ( )
417
423
}
424
+
418
425
pub fn scan_pop_bottom ( & mut self ) -> usize {
419
426
self . scan_stack . pop_back ( ) . unwrap ( )
420
427
}
428
+
421
429
pub fn advance_right ( & mut self ) {
422
430
self . right += 1 ;
423
431
self . right %= self . buf_max_len ;
@@ -427,6 +435,7 @@ impl<'a> Printer<'a> {
427
435
}
428
436
assert_ne ! ( self . right, self . left) ;
429
437
}
438
+
430
439
pub fn advance_left ( & mut self ) -> io:: Result < ( ) > {
431
440
debug ! ( "advance_left Vec<{},{}>, sizeof({})={}" , self . left, self . right,
432
441
self . left, self . buf[ self . left] . size) ;
@@ -461,6 +470,7 @@ impl<'a> Printer<'a> {
461
470
462
471
Ok ( ( ) )
463
472
}
473
+
464
474
pub fn check_stack ( & mut self , k : isize ) {
465
475
if !self . scan_stack . is_empty ( ) {
466
476
let x = self . scan_top ( ) ;
@@ -488,17 +498,20 @@ impl<'a> Printer<'a> {
488
498
}
489
499
}
490
500
}
501
+
491
502
pub fn print_newline ( & mut self , amount : isize ) -> io:: Result < ( ) > {
492
503
debug ! ( "NEWLINE {}" , amount) ;
493
504
let ret = write ! ( self . out, "\n " ) ;
494
505
self . pending_indentation = 0 ;
495
506
self . indent ( amount) ;
496
507
ret
497
508
}
509
+
498
510
pub fn indent ( & mut self , amount : isize ) {
499
511
debug ! ( "INDENT {}" , amount) ;
500
512
self . pending_indentation += amount;
501
513
}
514
+
502
515
pub fn get_top ( & mut self ) -> PrintStackElem {
503
516
match self . print_stack . last ( ) {
504
517
Some ( el) => * el,
@@ -508,13 +521,15 @@ impl<'a> Printer<'a> {
508
521
}
509
522
}
510
523
}
524
+
511
525
pub fn print_str ( & mut self , s : & str ) -> io:: Result < ( ) > {
512
526
while self . pending_indentation > 0 {
513
527
write ! ( self . out, " " ) ?;
514
528
self . pending_indentation -= 1 ;
515
529
}
516
530
write ! ( self . out, "{}" , s)
517
531
}
532
+
518
533
pub fn print ( & mut self , token : Token , l : isize ) -> io:: Result < ( ) > {
519
534
debug ! ( "print {} {} (remaining line space={})" , token, l,
520
535
self . space) ;
@@ -633,14 +648,6 @@ impl<'a> Printer<'a> {
633
648
self . pretty_print ( Token :: String ( wrd. to_string ( ) , wrd. len ( ) as isize ) )
634
649
}
635
650
636
- pub fn huge_word ( & mut self , wrd : & str ) -> io:: Result < ( ) > {
637
- self . pretty_print ( Token :: String ( wrd. to_string ( ) , SIZE_INFINITY ) )
638
- }
639
-
640
- pub fn zero_word ( & mut self , wrd : & str ) -> io:: Result < ( ) > {
641
- self . pretty_print ( Token :: String ( wrd. to_string ( ) , 0 ) )
642
- }
643
-
644
651
fn spaces ( & mut self , n : usize ) -> io:: Result < ( ) > {
645
652
self . break_offset ( n, 0 )
646
653
}
0 commit comments