Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add a feature for linking to proc_macro. #363

Merged
merged 1 commit into from
Mar 31, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
9 changes: 5 additions & 4 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ path = "examples/dump-syntax/main.rs"
required-features = ["full", "parsing", "extra-traits"]

[features]
default = ["derive", "parsing", "printing", "clone-impls"]
default = ["derive", "parsing", "printing", "clone-impls", "proc-macro"]
derive = []
full = []
parsing = []
Expand All @@ -25,11 +25,12 @@ visit-mut = []
fold = []
clone-impls = []
extra-traits = []
proc-macro = ["proc-macro2/proc-macro", "quote/proc-macro"]

[dependencies]
proc-macro2 = "0.3"
#quote = { version = "0.5", optional = true }
quote = { git = 'https://github.com/dtolnay/quote', optional = true }
proc-macro2 = { version = "0.3", default-features = false }
#quote = { version = "0.5", optional = true, default-features = false }
quote = { git = 'https://github.com/dtolnay/quote', optional = true, default-features = false }
unicode-xid = "0.1"

[dev-dependencies]
Expand Down
2 changes: 2 additions & 0 deletions src/buffer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,7 @@
// and caution should be used when editing it. The public-facing interface is
// 100% safe but the implementation is fragile internally.

#[cfg(feature = "proc-macro")]
use proc_macro as pm;
use proc_macro2::{Delimiter, Literal, Span, Term, TokenStream};
use proc_macro2::{Group, TokenTree, Op};
Expand Down Expand Up @@ -219,6 +220,7 @@ impl TokenBuffer {

/// Creates a `TokenBuffer` containing all the tokens from the input
/// `TokenStream`.
#[cfg(feature = "proc-macro")]
pub fn new(stream: pm::TokenStream) -> TokenBuffer {
Self::new2(stream.into())
}
Expand Down
3 changes: 2 additions & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -262,6 +262,7 @@
redundant_closure, needless_pass_by_value, redundant_field_names))]

extern crate proc_macro2;
#[cfg(feature = "proc-macro")]
extern crate proc_macro;
extern crate unicode_xid;

Expand Down Expand Up @@ -572,7 +573,7 @@ pub use error::parse_error;
/// #
/// # fn main() {}
/// ```
#[cfg(feature = "parsing")]
#[cfg(all(feature = "parsing", feature = "proc-macro"))]
pub fn parse<T>(tokens: proc_macro::TokenStream) -> Result<T, ParseError>
where
T: Synom,
Expand Down
2 changes: 2 additions & 0 deletions src/synom.rs
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,7 @@
//!
//! *This module is available if Syn is built with the `"parsing"` feature.*

#[cfg(feature = "proc-macro")]
use proc_macro;
use proc_macro2;

Expand Down Expand Up @@ -225,6 +226,7 @@ pub trait Parser: Sized {
fn parse2(self, tokens: proc_macro2::TokenStream) -> Result<Self::Output, ParseError>;

/// Parse tokens of source code into the chosen syntax tree node.
#[cfg(feature = "proc-macro")]
fn parse(self, tokens: proc_macro::TokenStream) -> Result<Self::Output, ParseError> {
self.parse2(tokens.into())
}
Expand Down