Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
49 changes: 0 additions & 49 deletions compiler/rustc_ast_pretty/src/helpers.rs

This file was deleted.

1 change: 0 additions & 1 deletion compiler/rustc_ast_pretty/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,5 @@
#![feature(negative_impls)]
// tidy-alphabetical-end

mod helpers;
pub mod pp;
pub mod pprust;
135 changes: 134 additions & 1 deletion compiler/rustc_ast_pretty/src/pp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,6 @@
//! methods called `Printer::scan_*`, and the 'PRINT' process is the
//! method called `Printer::print`.

mod convenience;
mod ring;

use std::borrow::Cow;
Expand Down Expand Up @@ -188,6 +187,12 @@ pub(crate) enum Token {
End,
}

impl Token {
pub(crate) fn is_hardbreak_tok(&self) -> bool {
*self == Printer::hardbreak_tok_offset(0)
}
}

#[derive(Copy, Clone)]
enum PrintFrame {
Fits,
Expand Down Expand Up @@ -479,4 +484,132 @@ impl Printer {
self.out.push_str(string);
self.space -= string.len() as isize;
}

/// Synthesizes a comment that was not textually present in the original
/// source file.
pub fn synth_comment(&mut self, text: impl Into<Cow<'static, str>>) {
self.word("/*");
self.space();
self.word(text);
self.space();
self.word("*/")
}

/// "raw box"
pub fn rbox(&mut self, indent: isize, breaks: Breaks) -> BoxMarker {
self.scan_begin(BeginToken { indent: IndentStyle::Block { offset: indent }, breaks })
}

/// Inconsistent breaking box
pub fn ibox(&mut self, indent: isize) -> BoxMarker {
self.rbox(indent, Breaks::Inconsistent)
}

/// Consistent breaking box
pub fn cbox(&mut self, indent: isize) -> BoxMarker {
self.rbox(indent, Breaks::Consistent)
}

pub fn visual_align(&mut self) -> BoxMarker {
self.scan_begin(BeginToken { indent: IndentStyle::Visual, breaks: Breaks::Consistent })
}

pub fn break_offset(&mut self, n: usize, off: isize) {
self.scan_break(BreakToken {
offset: off,
blank_space: n as isize,
..BreakToken::default()
});
}

pub fn end(&mut self, b: BoxMarker) {
self.scan_end(b)
}

pub fn eof(mut self) -> String {
self.scan_eof();
self.out
}

pub fn word<S: Into<Cow<'static, str>>>(&mut self, wrd: S) {
let string = wrd.into();
self.scan_string(string)
}

pub fn word_space<W: Into<Cow<'static, str>>>(&mut self, w: W) {
self.word(w);
self.space();
}

pub fn nbsp(&mut self) {
self.word(" ")
}

pub fn word_nbsp<S: Into<Cow<'static, str>>>(&mut self, w: S) {
self.word(w);
self.nbsp()
}

fn spaces(&mut self, n: usize) {
self.break_offset(n, 0)
}

pub fn zerobreak(&mut self) {
self.spaces(0)
}

pub fn space(&mut self) {
self.spaces(1)
}

pub fn popen(&mut self) {
self.word("(");
}

pub fn pclose(&mut self) {
self.word(")");
}

pub fn hardbreak(&mut self) {
self.spaces(SIZE_INFINITY as usize)
}

pub fn is_beginning_of_line(&self) -> bool {
match self.last_token() {
Some(last_token) => last_token.is_hardbreak_tok(),
None => true,
}
}

pub fn hardbreak_if_not_bol(&mut self) {
if !self.is_beginning_of_line() {
self.hardbreak()
}
}

pub fn space_if_not_bol(&mut self) {
if !self.is_beginning_of_line() {
self.space();
}
}

pub(crate) fn hardbreak_tok_offset(off: isize) -> Token {
Token::Break(BreakToken {
offset: off,
blank_space: SIZE_INFINITY,
..BreakToken::default()
})
}

pub fn trailing_comma(&mut self) {
self.scan_break(BreakToken { pre_break: Some(','), ..BreakToken::default() });
}

pub fn trailing_comma_or_space(&mut self) {
self.scan_break(BreakToken {
blank_space: 1,
pre_break: Some(','),
..BreakToken::default()
});
}
}
97 changes: 0 additions & 97 deletions compiler/rustc_ast_pretty/src/pp/convenience.rs

This file was deleted.

Loading