Skip to content

Commit

Permalink
Allow splicing more things in quotes
Browse files Browse the repository at this point in the history
  • Loading branch information
Keegan McAllister authored and alexcrichton committed Jun 25, 2014
1 parent 4e26e2d commit 26b2fa0
Showing 1 changed file with 16 additions and 0 deletions.
16 changes: 16 additions & 0 deletions src/libsyntax/ext/quote.rs
Expand Up @@ -32,6 +32,7 @@ use std::gc::Gc;

pub mod rt {
use ast;
use codemap::Spanned;
use ext::base::ExtCtxt;
use parse::token;
use parse;
Expand All @@ -48,12 +49,25 @@ pub mod rt {
fn to_tokens(&self, _cx: &ExtCtxt) -> Vec<TokenTree> ;
}

impl ToTokens for TokenTree {
fn to_tokens(&self, _cx: &ExtCtxt) -> Vec<TokenTree> {
vec!(self.clone())
}
}

impl ToTokens for Vec<TokenTree> {
fn to_tokens(&self, _cx: &ExtCtxt) -> Vec<TokenTree> {
(*self).clone()
}
}

impl<T: ToTokens> ToTokens for Spanned<T> {
fn to_tokens(&self, cx: &ExtCtxt) -> Vec<TokenTree> {
// FIXME: use the span?
self.node.to_tokens(cx)
}
}

/* Should be (when bugs in default methods are fixed):
trait ToSource : ToTokens {
Expand Down Expand Up @@ -121,6 +135,7 @@ pub mod rt {
impl_to_source!(Generics, generics_to_str)
impl_to_source!(Gc<ast::Item>, item_to_str)
impl_to_source!(Gc<ast::Expr>, expr_to_str)
impl_to_source!(Gc<ast::Pat>, pat_to_str)
impl_to_source_slice!(ast::Ty, ", ")
impl_to_source_slice!(Gc<ast::Item>, "\n\n")

Expand Down Expand Up @@ -207,6 +222,7 @@ pub mod rt {

impl_to_tokens!(ast::Ident)
impl_to_tokens!(Gc<ast::Item>)
impl_to_tokens!(Gc<ast::Pat>)
impl_to_tokens_lifetime!(&'a [Gc<ast::Item>])
impl_to_tokens!(ast::Ty)
impl_to_tokens_lifetime!(&'a [ast::Ty])
Expand Down

0 comments on commit 26b2fa0

Please sign in to comment.