diff options
| author | Keegan McAllister <mcallister.keegan@gmail.com> | 2014-06-20 18:36:21 -0700 |
|---|---|---|
| committer | Alex Crichton <alex@alexcrichton.com> | 2014-06-24 17:23:21 -0700 |
| commit | 26b2fa052fd25483c73709981deaa78f60cc6ac4 (patch) | |
| tree | 2b55996564bb09e3c458b3a1b9a54a88453dcc52 /src/libsyntax/ext | |
| parent | 4e26e2d8ca0a389280cf9d46297043df9a63ce06 (diff) | |
| download | rust-26b2fa052fd25483c73709981deaa78f60cc6ac4.tar.gz rust-26b2fa052fd25483c73709981deaa78f60cc6ac4.zip | |
Allow splicing more things in quotes
Diffstat (limited to 'src/libsyntax/ext')
| -rw-r--r-- | src/libsyntax/ext/quote.rs | 16 |
1 files changed, 16 insertions, 0 deletions
diff --git a/src/libsyntax/ext/quote.rs b/src/libsyntax/ext/quote.rs index 04c3f699cd7..9174bb65b24 100644 --- a/src/libsyntax/ext/quote.rs +++ b/src/libsyntax/ext/quote.rs @@ -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; @@ -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 { @@ -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") @@ -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]) |
