diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-17 12:02:58 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-17 12:02:58 +0000 |
commit | 698f8c2f01ea549d77d7dc3338a12e04c11057b9 (patch) | |
tree | 173a775858bd501c378080a10dca74132f05bc50 /compiler/rustc_ast_pretty/src/helpers.rs | |
parent | Initial commit. (diff) | |
download | rustc-698f8c2f01ea549d77d7dc3338a12e04c11057b9.tar.xz rustc-698f8c2f01ea549d77d7dc3338a12e04c11057b9.zip |
Adding upstream version 1.64.0+dfsg1.upstream/1.64.0+dfsg1
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'compiler/rustc_ast_pretty/src/helpers.rs')
-rw-r--r-- | compiler/rustc_ast_pretty/src/helpers.rs | 48 |
1 files changed, 48 insertions, 0 deletions
diff --git a/compiler/rustc_ast_pretty/src/helpers.rs b/compiler/rustc_ast_pretty/src/helpers.rs new file mode 100644 index 000000000..5ec71cddf --- /dev/null +++ b/compiler/rustc_ast_pretty/src/helpers.rs @@ -0,0 +1,48 @@ +use crate::pp::Printer; +use std::borrow::Cow; + +impl Printer { + pub fn word_space<W: Into<Cow<'static, str>>>(&mut self, w: W) { + self.word(w); + self.space(); + } + + pub fn popen(&mut self) { + self.word("("); + } + + pub fn pclose(&mut self) { + self.word(")"); + } + + 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 fn nbsp(&mut self) { + self.word(" ") + } + + pub fn word_nbsp<S: Into<Cow<'static, str>>>(&mut self, w: S) { + self.word(w); + self.nbsp() + } + + // 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("*/") + } +} |