Skip to content

Commit 2dc60b1

Browse files
committed
Refactor TokenStream.
1 parent ec29011 commit 2dc60b1

File tree

19 files changed

+424
-1288
lines changed

19 files changed

+424
-1288
lines changed

mk/crates.mk

+1-1
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ DEPS_syntax_ext := syntax syntax_pos rustc_errors fmt_macros proc_macro
103103
DEPS_proc_macro := syntax syntax_pos rustc_plugin log
104104
DEPS_syntax_pos := serialize
105105
DEPS_proc_macro_tokens := syntax syntax_pos log
106-
DEPS_proc_macro_plugin := syntax syntax_pos rustc_plugin log proc_macro_tokens
106+
DEPS_proc_macro_plugin := syntax syntax_pos rustc_plugin
107107

108108
DEPS_rustc_const_math := std syntax log serialize rustc_i128
109109
DEPS_rustc_const_eval := rustc_const_math rustc syntax log serialize \

src/Cargo.lock

+1-2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/libproc_macro/lib.rs

+6-5
Original file line numberDiff line numberDiff line change
@@ -82,14 +82,15 @@ pub mod __internal {
8282
use syntax::ast;
8383
use syntax::ptr::P;
8484
use syntax::parse::{self, token, ParseSess};
85-
use syntax::tokenstream::TokenStream as TokenStream_;
85+
use syntax::tokenstream::{TokenTree, TokenStream as TokenStream_};
8686

8787
use super::{TokenStream, LexError};
8888

8989
pub fn new_token_stream(item: P<ast::Item>) -> TokenStream {
90-
TokenStream { inner: TokenStream_::from_tokens(vec![
91-
token::Interpolated(Rc::new(token::NtItem(item)))
92-
])}
90+
TokenStream {
91+
inner: TokenTree::Token(item.span, token::Interpolated(Rc::new(token::NtItem(item))))
92+
.into()
93+
}
9394
}
9495

9596
pub fn token_stream_wrap(inner: TokenStream_) -> TokenStream {
@@ -175,7 +176,7 @@ impl FromStr for TokenStream {
175176
let tts = try!(parse::parse_tts_from_source_str(name, src, sess)
176177
.map_err(parse_to_lex_err));
177178

178-
Ok(__internal::token_stream_wrap(TokenStream_::from_tts(tts)))
179+
Ok(__internal::token_stream_wrap(tts.into_iter().collect()))
179180
})
180181
}
181182
}

src/libproc_macro_plugin/Cargo.toml

+1-2
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ path = "lib.rs"
88
crate-type = ["dylib"]
99

1010
[dependencies]
11-
log = { path = "../liblog" }
1211
rustc_plugin = { path = "../librustc_plugin" }
1312
syntax = { path = "../libsyntax" }
14-
proc_macro_tokens = { path = "../libproc_macro_tokens" }
13+
syntax_pos = { path = "../libsyntax_pos" }

src/libproc_macro_plugin/lib.rs

+7-9
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,8 @@
1515
//! ## Usage
1616
//! This crate provides the `qquote!` macro for syntax creation.
1717
//!
18-
//! The `qquote!` macro imports `syntax::ext::proc_macro_shim::prelude::*`, so you
19-
//! will need to `extern crate syntax` for usage. (This is a temporary solution until more
20-
//! of the external API in libproc_macro_tokens is stabilized to support the token construction
21-
//! operations that the qausiquoter relies on.) The shim file also provides additional
22-
//! operations, such as `build_block_emitter` (as used in the `cond` example below).
18+
//! The `qquote!` macro uses the crate `syntax`, so users must declare `extern crate syntax;`
19+
//! at the crate root. This is a temporary solution until we have better hygiene.
2320
//!
2421
//! ## Quasiquotation
2522
//!
@@ -88,19 +85,20 @@
8885

8986
extern crate rustc_plugin;
9087
extern crate syntax;
91-
extern crate proc_macro_tokens;
92-
#[macro_use] extern crate log;
88+
extern crate syntax_pos;
9389

9490
mod qquote;
95-
9691
use qquote::qquote;
9792

9893
use rustc_plugin::Registry;
94+
use syntax::ext::base::SyntaxExtension;
95+
use syntax::symbol::Symbol;
9996

10097
// ____________________________________________________________________________________________
10198
// Main macro definition
10299

103100
#[plugin_registrar]
104101
pub fn plugin_registrar(reg: &mut Registry) {
105-
reg.register_macro("qquote", qquote);
102+
reg.register_syntax_extension(Symbol::intern("qquote"),
103+
SyntaxExtension::ProcMacro(Box::new(qquote)));
106104
}

0 commit comments

Comments
 (0)