Skip to content

Commit

Permalink
Refactor TokenStream.
Browse files Browse the repository at this point in the history
  • Loading branch information
jseyfried committed Jan 22, 2017
1 parent ec29011 commit 2dc60b1
Show file tree
Hide file tree
Showing 19 changed files with 424 additions and 1,288 deletions.
2 changes: 1 addition & 1 deletion mk/crates.mk
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ DEPS_syntax_ext := syntax syntax_pos rustc_errors fmt_macros proc_macro
DEPS_proc_macro := syntax syntax_pos rustc_plugin log
DEPS_syntax_pos := serialize
DEPS_proc_macro_tokens := syntax syntax_pos log
DEPS_proc_macro_plugin := syntax syntax_pos rustc_plugin log proc_macro_tokens
DEPS_proc_macro_plugin := syntax syntax_pos rustc_plugin

DEPS_rustc_const_math := std syntax log serialize rustc_i128
DEPS_rustc_const_eval := rustc_const_math rustc syntax log serialize \
Expand Down
3 changes: 1 addition & 2 deletions src/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 6 additions & 5 deletions src/libproc_macro/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -82,14 +82,15 @@ pub mod __internal {
use syntax::ast;
use syntax::ptr::P;
use syntax::parse::{self, token, ParseSess};
use syntax::tokenstream::TokenStream as TokenStream_;
use syntax::tokenstream::{TokenTree, TokenStream as TokenStream_};

use super::{TokenStream, LexError};

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

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

Ok(__internal::token_stream_wrap(TokenStream_::from_tts(tts)))
Ok(__internal::token_stream_wrap(tts.into_iter().collect()))
})
}
}
Expand Down
3 changes: 1 addition & 2 deletions src/libproc_macro_plugin/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ path = "lib.rs"
crate-type = ["dylib"]

[dependencies]
log = { path = "../liblog" }
rustc_plugin = { path = "../librustc_plugin" }
syntax = { path = "../libsyntax" }
proc_macro_tokens = { path = "../libproc_macro_tokens" }
syntax_pos = { path = "../libsyntax_pos" }
16 changes: 7 additions & 9 deletions src/libproc_macro_plugin/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,8 @@
//! ## Usage
//! This crate provides the `qquote!` macro for syntax creation.
//!
//! The `qquote!` macro imports `syntax::ext::proc_macro_shim::prelude::*`, so you
//! will need to `extern crate syntax` for usage. (This is a temporary solution until more
//! of the external API in libproc_macro_tokens is stabilized to support the token construction
//! operations that the qausiquoter relies on.) The shim file also provides additional
//! operations, such as `build_block_emitter` (as used in the `cond` example below).
//! The `qquote!` macro uses the crate `syntax`, so users must declare `extern crate syntax;`
//! at the crate root. This is a temporary solution until we have better hygiene.
//!
//! ## Quasiquotation
//!
Expand Down Expand Up @@ -88,19 +85,20 @@

extern crate rustc_plugin;
extern crate syntax;
extern crate proc_macro_tokens;
#[macro_use] extern crate log;
extern crate syntax_pos;

mod qquote;

use qquote::qquote;

use rustc_plugin::Registry;
use syntax::ext::base::SyntaxExtension;
use syntax::symbol::Symbol;

// ____________________________________________________________________________________________
// Main macro definition

#[plugin_registrar]
pub fn plugin_registrar(reg: &mut Registry) {
reg.register_macro("qquote", qquote);
reg.register_syntax_extension(Symbol::intern("qquote"),
SyntaxExtension::ProcMacro(Box::new(qquote)));
}
Loading

0 comments on commit 2dc60b1

Please sign in to comment.