Crate parse_more

Crate parse_more 

Source
Expand description

§parse-more

Parse-more is an extension of the syn::parse::Parse trait from the syn crate, allowing to parse input from procedural macros directly, without having to create a custom structure and implementing the syn::parse::Parse trait on it.

It provides classic syn macros and functions variant, using the ParseMore trait instead.

§Example

use quote::quote;
use parse_more::{parse_more_macro_input, Concat, Braced};
use proc_macro::TokenStream;
use syn::{Expr, Ident, Token, punctuated::Punctuated};

#[proc_macro]
pub fn complex_args(input: TokenStream) -> TokenStream {
   let content = parse_more_macro_input!(
       input as Punctuated<Concat<Ident, Token![=>], Braced<(Ident, Expr)>>, Token![,]>
   );
   content
       .into_iter()
       .map(|concat| {
           // Second item is discarded (it's the => arrow)
           let (ident, _, Braced((other_ident, literal))) = concat.into();
           quote! {
               println!("{}: {} versus other type {}", #literal, (-1i8) as #ident, (-1i8) as #other_ident);
           }
       })
       .collect::<proc_macro2::TokenStream>()
       .into()
}

And then :

complex_args! {
    u8 => {
        (i8, "u8 integer")
    },
    u16 => {
        (i16, "u16 integer")
    },
    Foo => {
        (Bar, 8 + 42)
    }
}

Modules§

syn_types
Implementation of the ParseMore trait for every types from the syn crates implementing syn::parse::Parse.

Macros§

parse_more_auto_impl
This macro auto-implements the ParseMore traits on its arguments, which MUST implement the syn::parse::Parse trait. It allows using custom types inside of any parse-more macros/functions.
parse_more_macro_input
Same as the syn::parse_macro_input macro, but using the ParseMore trait.
parse_more_quote
Same as the syn::parse_quote macro, but using the ParseMore trait.

Structs§

Braced
Parse an item surrounded by braces.
Bracketed
Parse an item surrounded by brackets.
Concat
Parse successive items.
Invalid
Parse an item surrounded by brackets.
Parenthesized
Parse an item surrounded by parenthesis.
ParseMoreWrapper
This wrapper implements syn::parse::Parse when T implements ParseMore. It permits to use this wrapper and a type implementing ParseMore in a parsing function from syn.

Enums§

Either
Parse an item in a given list. If multiple types can be parsed, the first one is chosen.

Traits§

ParseMore
Parsing interface implemented by all types from the syn crate which already implement syn::parse::Parse, and some others usefull ones. Use the parse_more_auto_impl macros to easily implement ParseMore on a type which already implement syn::parse::Parse.

Functions§

parse2_more
Same as the syn::parse2 function, but using the ParseMore trait.
parse_more
Same as the syn::parse() function, but using the ParseMore trait.
parse_more_str
Same as the syn::parse_str function, but using the ParseMore trait.

Attribute Macros§

filler
Re-export proc macro. Parse an additionnal type between two struct fields.
parse_more
Re-export proc macro. Auto-implements the parse_more::ParseMore trait on an item.