Skip to content

Commit

Permalink
Interpolate AST nodes in quasiquote.
Browse files Browse the repository at this point in the history
This changes the `ToTokens` implementations for expressions, statements,
etc. with almost-trivial ones that produce `Interpolated(*Nt(...))`
pseudo-tokens. In this way, quasiquote now works the same way as macros
do: already-parsed AST fragments are used as-is, not reparsed.

The `ToSource` trait is removed. Quasiquote no longer involves
pretty-printing at all, which removes the need for the
`encode_with_hygiene` hack. All associated machinery is removed.

A new `Nonterminal` is added, NtArm, which the parser now interpolates.
This is just for quasiquote, not macros (although it could be in the
future).

`ToTokens` is no longer implemented for `Arg` (although this could be
added again) and `Generics` (which I don't think makes sense).

This breaks any compiler extensions that relied on the ability of
`ToTokens` to turn AST fragments back into inspectable token trees. For
this reason, this closes #16987.

As such, this is a [breaking-change].

Fixes #16472.
Fixes #15962.
Fixes #17397.
Fixes #16617.
  • Loading branch information
goffrie committed Apr 26, 2015
1 parent da62384 commit 2d9831d
Show file tree
Hide file tree
Showing 9 changed files with 227 additions and 543 deletions.
6 changes: 0 additions & 6 deletions src/libsyntax/ast.rs
Expand Up @@ -89,12 +89,6 @@ impl Ident {
pub fn as_str<'a>(&'a self) -> &'a str {
self.name.as_str()
}

pub fn encode_with_hygiene(&self) -> String {
format!("\x00name_{},ctxt_{}\x00",
self.name.usize(),
self.ctxt)
}
}

impl fmt::Debug for Ident {
Expand Down

1 comment on commit 2d9831d

@uorbe001
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@goffrie

This breaks any compiler extensions that relied on the ability of
ToTokens to turn AST fragments back into inspectable token trees. For
this reason, this closes #16987.

Is there any way to do this now? I'm recursively parsing blocks (inside blocks) and this breaks my code, but I can't find out how to do this now.

Please sign in to comment.