parse-more-macros 0.1.0

Procedural macros for the parse-more crate.
Documentation

parse-more

Parse-more is an extension of the Parse trait from the syn crate, allowing to parse input from procedural macros directly, without having to create a custom structure and implementing the 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.value();
           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)
    }
}

Installation

Add to your Cargo.toml file:

[dependencies]
parse-more = "0.2"

Contribution

Contributions are welcome! Open an issue or a pull request.

License

This project is licensed under the MIT License.