Skip to content

Commit

Permalink
implement verbatim in prettyplease
Browse files Browse the repository at this point in the history
  • Loading branch information
Noratrieb committed Jan 22, 2023
1 parent 39c1862 commit 045e766
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 43 deletions.
9 changes: 1 addition & 8 deletions prettyplease-forked/src/expr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -686,13 +686,6 @@ impl Printer {
self.word("}");
}

#[cfg(not(feature = "verbatim"))]
fn expr_verbatim(&mut self, expr: &TokenStream) {
if !expr.is_empty() {
unimplemented!("Expr::Verbatim `{}`", expr);
}
}

#[cfg(feature = "verbatim")]
fn expr_verbatim(&mut self, tokens: &TokenStream) {
use syn::parse::{Parse, ParseStream, Result};
Expand Down Expand Up @@ -803,7 +796,7 @@ impl Printer {

let expr: ExprVerbatim = match syn::parse2(tokens.clone()) {
Ok(expr) => expr,
Err(_) => unimplemented!("Expr::Verbatim `{}`", tokens),
Err(_) => return self.word(tokens.to_string()),
};

match expr {
Expand Down
32 changes: 8 additions & 24 deletions prettyplease-forked/src/item.rs
Original file line number Diff line number Diff line change
Expand Up @@ -351,14 +351,6 @@ impl Printer {
self.hardbreak();
}

#[cfg(not(feature = "verbatim"))]
fn item_verbatim(&mut self, item: &TokenStream) {
if !item.is_empty() {
unimplemented!("Item::Verbatim `{}`", item);
}
self.hardbreak();
}

#[cfg(feature = "verbatim")]
fn item_verbatim(&mut self, tokens: &TokenStream) {
use syn::parse::{Parse, ParseStream, Result};
Expand Down Expand Up @@ -387,7 +379,7 @@ impl Printer {

let item: ItemVerbatim = match syn::parse2(tokens.clone()) {
Ok(item) => item,
Err(_) => unimplemented!("Item::Verbatim `{}`", tokens),
Err(_) => return self.word(tokens.to_string()),
};

match item {
Expand Down Expand Up @@ -532,14 +524,6 @@ impl Printer {
self.hardbreak();
}

#[cfg(not(feature = "verbatim"))]
fn foreign_item_verbatim(&mut self, foreign_item: &TokenStream) {
if !foreign_item.is_empty() {
unimplemented!("ForeignItem::Verbatim `{}`", foreign_item);
}
self.hardbreak();
}

#[cfg(feature = "verbatim")]
fn foreign_item_verbatim(&mut self, tokens: &TokenStream) {
use syn::parse::{Parse, ParseStream, Result};
Expand All @@ -556,7 +540,11 @@ impl Printer {

let foreign_item: ForeignItemVerbatim = match syn::parse2(tokens.clone()) {
Ok(foreign_item) => foreign_item,
Err(_) => unimplemented!("ForeignItem::Verbatim `{}`", tokens),
Err(_) => {
self.word(tokens.to_string());
self.hardbreak();
return;
},
};

match foreign_item {
Expand Down Expand Up @@ -650,9 +638,7 @@ impl Printer {
}

fn trait_item_verbatim(&mut self, trait_item: &TokenStream) {
if !trait_item.is_empty() {
unimplemented!("TraitItem::Verbatim `{}`", trait_item);
}
self.word(trait_item.to_string());
self.hardbreak();
}

Expand Down Expand Up @@ -747,9 +733,7 @@ impl Printer {
}

fn impl_item_verbatim(&mut self, impl_item: &TokenStream) {
if !impl_item.is_empty() {
unimplemented!("ImplItem::Verbatim `{}`", impl_item);
}
self.word(impl_item.to_string());
self.hardbreak();
}

Expand Down
2 changes: 1 addition & 1 deletion prettyplease-forked/src/pat.rs
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@ impl Printer {
}

fn pat_verbatim(&mut self, pat: &TokenStream) {
unimplemented!("Pat::Verbatim `{}`", pat);
self.word(pat.to_string());
}

fn pat_wild(&mut self, pat: &PatWild) {
Expand Down
11 changes: 1 addition & 10 deletions prettyplease-forked/src/ty.rs
Original file line number Diff line number Diff line change
Expand Up @@ -160,15 +160,6 @@ impl Printer {
self.word(")");
}

#[cfg(not(feature = "verbatim"))]
fn type_verbatim(&mut self, ty: &TokenStream) {
if ty.to_string() == "..." {
self.word("...");
} else {
unimplemented!("Type::Verbatim `{}`", ty);
}
}

#[cfg(feature = "verbatim")]
fn type_verbatim(&mut self, tokens: &TokenStream) {
use syn::parse::{Parse, ParseStream, Result};
Expand All @@ -194,7 +185,7 @@ impl Printer {

let ty: TypeVerbatim = match syn::parse2(tokens.clone()) {
Ok(ty) => ty,
Err(_) => unimplemented!("Type::Verbatim `{}`", tokens),
Err(_) => return self.word(tokens.to_string()),
};

match ty {
Expand Down

0 comments on commit 045e766

Please sign in to comment.