diff options
| author | David Tolnay <dtolnay@gmail.com> | 2018-10-13 14:37:07 -0700 |
|---|---|---|
| committer | David Tolnay <dtolnay@gmail.com> | 2018-10-13 14:58:25 -0700 |
| commit | f98865f0bb77cd1189840fbd76f3625ade7393f2 (patch) | |
| tree | b70fe2dbd4848eac9e707d88a03b9d85cd8cd5e3 /src/lib.rs | |
| parent | f2b744b44e21c9e9044d1b6cfa5931fa33d3c49e (diff) | |
| download | platform_external_rust_crates_syn-f98865f0bb77cd1189840fbd76f3625ade7393f2.tar.gz platform_external_rust_crates_syn-f98865f0bb77cd1189840fbd76f3625ade7393f2.tar.bz2 platform_external_rust_crates_syn-f98865f0bb77cd1189840fbd76f3625ade7393f2.zip | |
Move parse_macro_input to a different trait
Diffstat (limited to 'src/lib.rs')
| -rw-r--r-- | src/lib.rs | 64 |
1 files changed, 9 insertions, 55 deletions
@@ -446,6 +446,15 @@ mod tt; #[doc(hidden)] pub mod parse_quote; +// Not public API except the `parse_macro_input!` macro. +#[cfg(all( + not(all(target_arch = "wasm32", target_os = "unknown")), + feature = "parsing", + feature = "proc-macro" +))] +#[doc(hidden)] +pub mod parse_macro_input; + #[cfg(all(feature = "parsing", feature = "printing"))] pub mod spanned; @@ -763,58 +772,3 @@ pub fn parse_file(mut content: &str) -> Result<File, Error> { file.shebang = shebang; Ok(file) } - -/// Parse the input TokenStream of a macro, triggering a compile error if the -/// tokens fail to parse. -/// -/// Refer to the [`parse` module] documentation for more details about parsing -/// in Syn. -/// -/// [`parse` module]: parse/index.html -/// -/// # Intended usage -/// -/// ```rust -/// #[macro_use] -/// extern crate syn; -/// -/// extern crate proc_macro; -/// -/// use proc_macro::TokenStream; -/// use syn::parse::{Parse, ParseStream, Result}; -/// -/// struct MyMacroInput { -/// /* ... */ -/// } -/// -/// impl Parse for MyMacroInput { -/// fn parse(input: ParseStream) -> Result<Self> { -/// /* ... */ -/// # Ok(MyMacroInput {}) -/// } -/// } -/// -/// # const IGNORE: &str = stringify! { -/// #[proc_macro] -/// # }; -/// pub fn my_macro(tokens: TokenStream) -> TokenStream { -/// let input = parse_macro_input!(tokens as MyMacroInput); -/// -/// /* ... */ -/// # "".parse().unwrap() -/// } -/// # -/// # fn main() {} -/// ``` -#[cfg(feature = "proc-macro")] -#[macro_export] -macro_rules! parse_macro_input { - ($tokenstream:ident as $ty:ty) => { - match $crate::parse::<$ty>($tokenstream) { - $crate::export::Ok(data) => data, - $crate::export::Err(err) => { - return $crate::export::TokenStream::from(err.to_compile_error()); - } - }; - }; -} |
