diff options
Diffstat (limited to 'src/libsyntax/ext')
| -rw-r--r-- | src/libsyntax/ext/expand.rs | 10 | ||||
| -rw-r--r-- | src/libsyntax/ext/proc_macro_shim.rs | 72 |
2 files changed, 4 insertions, 78 deletions
diff --git a/src/libsyntax/ext/expand.rs b/src/libsyntax/ext/expand.rs index d748eec73e8..226625ebc8e 100644 --- a/src/libsyntax/ext/expand.rs +++ b/src/libsyntax/ext/expand.rs @@ -364,10 +364,8 @@ impl<'a, 'b> MacroExpander<'a, 'b> { kind.expect_from_annotatables(items) } SyntaxExtension::AttrProcMacro(ref mac) => { - let attr_toks = TokenStream::from_tts(tts_for_attr_args(&attr, - &self.cx.parse_sess)); - - let item_toks = TokenStream::from_tts(tts_for_item(&item, &self.cx.parse_sess)); + let attr_toks = tts_for_attr_args(&attr, &self.cx.parse_sess).into_iter().collect(); + let item_toks = tts_for_item(&item, &self.cx.parse_sess).into_iter().collect(); let tok_result = mac.expand(self.cx, attr.span, attr_toks, item_toks); self.parse_expansion(tok_result, kind, name, attr.span) @@ -467,7 +465,7 @@ impl<'a, 'b> MacroExpander<'a, 'b> { }, }); - let toks = TokenStream::from_tts(marked_tts); + let toks = marked_tts.into_iter().collect(); let tok_result = expandfun.expand(self.cx, span, toks); Some(self.parse_expansion(tok_result, kind, extname, span)) } @@ -490,7 +488,7 @@ impl<'a, 'b> MacroExpander<'a, 'b> { fn parse_expansion(&mut self, toks: TokenStream, kind: ExpansionKind, name: Name, span: Span) -> Expansion { - let mut parser = self.cx.new_parser_from_tts(&toks.to_tts()); + let mut parser = self.cx.new_parser_from_tts(&toks.trees().cloned().collect::<Vec<_>>()); let expansion = match parser.parse_expansion(kind, false) { Ok(expansion) => expansion, Err(mut err) => { diff --git a/src/libsyntax/ext/proc_macro_shim.rs b/src/libsyntax/ext/proc_macro_shim.rs deleted file mode 100644 index 21ce89a6dd5..00000000000 --- a/src/libsyntax/ext/proc_macro_shim.rs +++ /dev/null @@ -1,72 +0,0 @@ -// Copyright 2016 The Rust Project Developers. See the COPYRIGHT -// file at the top-level directory of this distribution and at -// http://rust-lang.org/COPYRIGHT. -// -// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or -// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license -// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your -// option. This file may not be copied, modified, or distributed -// except according to those terms. - -//! This is a shim file to ease the transition to the final procedural macro interface for -//! Macros 2.0. It currently exposes the `libsyntax` operations that the quasiquoter's -//! output needs to compile correctly, along with the following operators: -//! -//! - `build_block_emitter`, which produces a `block` output macro result from the -//! provided TokenStream. - -use ast; -use codemap::Span; -use parse::parser::Parser; -use ptr::P; -use tokenstream::TokenStream; -use ext::base::*; - -/// Take a `ExtCtxt`, `Span`, and `TokenStream`, and produce a Macro Result that parses -/// the TokenStream as a block and returns it as an `Expr`. -pub fn build_block_emitter<'cx>(cx: &'cx mut ExtCtxt, - sp: Span, - output: TokenStream) - -> Box<MacResult + 'cx> { - let parser = cx.new_parser_from_tts(&output.to_tts()); - - struct Result<'a> { - prsr: Parser<'a>, - span: Span, - }; //FIXME is this the right lifetime - - impl<'a> Result<'a> { - fn block(&mut self) -> P<ast::Block> { - let res = self.prsr.parse_block().unwrap(); - res - } - } - - impl<'a> MacResult for Result<'a> { - fn make_expr(self: Box<Self>) -> Option<P<ast::Expr>> { - let mut me = *self; - Some(P(ast::Expr { - id: ast::DUMMY_NODE_ID, - node: ast::ExprKind::Block(me.block()), - span: me.span, - attrs: ast::ThinVec::new(), - })) - - } - } - - Box::new(Result { - prsr: parser, - span: sp, - }) -} - -pub mod prelude { - pub use super::build_block_emitter; - pub use ast::Ident; - pub use codemap::{DUMMY_SP, Span}; - pub use ext::base::{ExtCtxt, MacResult}; - pub use parse::token::{self, Token, DelimToken}; - pub use symbol::keywords; - pub use tokenstream::{TokenTree, TokenStream}; -} |
