Skip to content

Commit

Permalink
Merge pull request #79 from dtolnay/tailcall
Browse files Browse the repository at this point in the history
Pretty-print tail calls (`become`)
  • Loading branch information
dtolnay committed Aug 24, 2024
2 parents 53aac30 + d2881c3 commit 11c45ff
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 2 deletions.
4 changes: 2 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,13 @@ verbatim = ["syn/parsing"]

[dependencies]
proc-macro2 = { version = "1.0.80", default-features = false }
syn = { version = "2.0.59", default-features = false, features = ["full"] }
syn = { version = "2.0.76", default-features = false, features = ["full"] }

[dev-dependencies]
indoc = "2"
proc-macro2 = { version = "1.0.80", default-features = false }
quote = { version = "1.0.35", default-features = false }
syn = { version = "2.0.59", default-features = false, features = ["parsing"] }
syn = { version = "2.0.76", default-features = false, features = ["parsing"] }

[lib]
doc-scrape-examples = false
Expand Down
17 changes: 17 additions & 0 deletions src/expr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -681,10 +681,16 @@ impl Printer {
enum ExprVerbatim {
Empty,
Ellipsis,
Become(Become),
Builtin(Builtin),
RawReference(RawReference),
}

struct Become {
attrs: Vec<Attribute>,
tail_call: Expr,
}

struct Builtin {
attrs: Vec<Attribute>,
name: Ident,
Expand All @@ -709,6 +715,11 @@ impl Printer {
let lookahead = ahead.lookahead1();
if input.is_empty() {
Ok(ExprVerbatim::Empty)
} else if lookahead.peek(Token![become]) {
input.advance_to(&ahead);
input.parse::<Token![become]>()?;
let tail_call: Expr = input.parse()?;
Ok(ExprVerbatim::Become(Become { attrs, tail_call }))
} else if lookahead.peek(kw::builtin) {
input.advance_to(&ahead);
input.parse::<kw::builtin>()?;
Expand Down Expand Up @@ -751,6 +762,12 @@ impl Printer {
ExprVerbatim::Ellipsis => {
self.word("...");
}
ExprVerbatim::Become(expr) => {
self.outer_attrs(&expr.attrs);
self.word("become");
self.nbsp();
self.expr(&expr.tail_call);
}
ExprVerbatim::Builtin(expr) => {
self.outer_attrs(&expr.attrs);
self.word("builtin # ");
Expand Down

0 comments on commit 11c45ff

Please sign in to comment.