22//!
33//! E.g. [pushing tokens onto `TokenStream`](TokenStreamExt::push) and [testing
44//! for specific punctuation on `TokenTree` and Punct](TokenTreePunct)
5- #![ warn( clippy:: pedantic) ]
6- #![ deny( missing_docs) ]
5+ #![ warn( clippy:: pedantic, missing_docs) ]
76#![ cfg_attr( docsrs, feature( doc_auto_cfg) ) ]
87
98#[ cfg( feature = "proc-macro" ) ]
@@ -36,18 +35,18 @@ macro_rules! attr {
3635}
3736
3837macro_rules! trait_def {
39- ( $item_attr: tt, $trait: ident, $( $fn_attr: tt, $fn: ident, $args: tt, $( $ret: ty) ?) ,* ) => {
38+ ( $item_attr: tt, $trait: ident, $( $fn_attr: tt, $fn: ident, $( { $ ( $gen : tt ) * } ) ? , $ args: tt, $( $ret: ty) ?) ,* ) => {
4039 attr!( $item_attr,
4140 pub trait $trait {
42- $( attr!( $fn_attr, fn $fn $args $( -> $ret) ?; ) ; ) *
41+ $( attr!( $fn_attr, fn $fn $( $ ( $gen ) * ) ? $ args $( -> $ret) ?; ) ; ) *
4342 } ) ;
4443 } ;
4544}
4645
4746macro_rules! trait_impl {
48- ( $trait: ident, $type: ident, $( $fn_attr: tt, $fn: ident, $args: tt, $( $ret: ty) ?, $stmts: tt) ,* ) => {
47+ ( $trait: ident, $type: ident, $( $fn_attr: tt, $fn: ident, $( { $ ( $gen : tt ) * } ) ? , $ args: tt, $( $ret: ty) ?, $stmts: tt) ,* ) => {
4948 impl $trait for $type {
50- $( attr!( $fn_attr, fn $fn $args $( -> $ret) ? $stmts) ; ) *
49+ $( attr!( $fn_attr, fn $fn $( $ ( $gen ) * ) ? $ args $( -> $ret) ? $stmts) ; ) *
5150 }
5251 } ;
5352}
@@ -60,16 +59,16 @@ macro_rules! impl_via_trait {
6059 fn $fn: ident $args: tt $( -> $ret: ty) ? { $( $stmts: tt) * } ) *
6160 }
6261 ) +) => {
63- once!( $( ( trait_def!( ( $( $trait_attr) * ) , $trait, $( ( $( $fn_attr) * ) , $fn, $args, $( $ret) ?) ,* ) ; ) ) +) ;
62+ once!( $( ( trait_def!( ( $( $trait_attr) * ) , $trait, $( ( $( $fn_attr) * ) , $fn, , $args, $( $ret) ?) ,* ) ; ) ) +) ;
6463 #[ cfg( feature = "proc-macro" ) ]
6564 const _: ( ) = {
6665 use proc_macro:: * ;
67- $( trait_impl!( $trait, $type, $( ( $( $fn_attr) * ) , $fn, $args, $( $ret) ?, { $( $stmts) * } ) ,* ) ; ) +
66+ $( trait_impl!( $trait, $type, $( ( $( $fn_attr) * ) , $fn, , $args, $( $ret) ?, { $( $stmts) * } ) ,* ) ; ) +
6867 } ;
6968 #[ cfg( feature = "proc-macro2" ) ]
7069 const _: ( ) = {
7170 use proc_macro2:: * ;
72- $( trait_impl!( $trait, $type, $( ( $( $fn_attr) * ) , $fn, $args, $( $ret) ?, { $( $stmts) * } ) ,* ) ; ) +
71+ $( trait_impl!( $trait, $type, $( ( $( $fn_attr) * ) , $fn, , $args, $( $ret) ?, { $( $stmts) * } ) ,* ) ; ) +
7372 } ;
7473 } ;
7574 (
@@ -78,7 +77,7 @@ macro_rules! impl_via_trait {
7877 $( #$trait_attr: tt) *
7978 impl $trait: ident$( $doc: literal) ?, $trait2: ident$( $doc2: literal) ? for $type: ident {
8079 $( $( #$fn_attr: tt) *
81- fn $fn: ident $args: tt $( -> $ret: ty) ? { $( $stmts: tt) * } ) *
80+ fn $fn: ident $( { $ ( $gen : tt ) * } ) ? ( $ ( $ args: tt) * ) $( -> $ret: ty) ? { $( $stmts: tt) * } ) *
8281 }
8382 ) +
8483 }
@@ -88,16 +87,16 @@ macro_rules! impl_via_trait {
8887 #[ cfg( feature = "proc-macro" ) ]
8988 mod $mod {
9089 use proc_macro:: * ;
91- once!( $( ( trait_def!( ( $( $trait_attr) * $( [ doc=$doc] ) ?) , $trait, $( ( $( $fn_attr) * ) , $fn, $args, $( $ret) ?) ,* ) ; ) ) +) ;
92- $( trait_impl!( $trait, $type, $( ( $( $fn_attr) * ) , $fn, $args, $( $ret) ?, { $( $stmts) * } ) ,* ) ; ) +
90+ once!( $( ( trait_def!( ( $( $trait_attr) * $( [ doc=$doc] ) ?) , $trait, $( ( $( $fn_attr) * ) , $fn, $( { $ ( $gen ) * } ) ? , ( $ ( $ args) * ) , $( $ret) ?) ,* ) ; ) ) +) ;
91+ $( trait_impl!( $trait, $type, $( ( $( $fn_attr) * ) , $fn, $( { $ ( $gen ) * } ) ? , ( $ ( $ args) * ) , $( $ret) ?, { $( $stmts) * } ) ,* ) ; ) +
9392 }
9493 #[ cfg( feature = "proc-macro2" ) ]
9594 once!( ( $( pub use $mod2:: $trait2; ) +) ) ;
9695 #[ cfg( feature = "proc-macro2" ) ]
9796 mod $mod2 {
9897 use proc_macro2:: * ;
99- once!( $( ( trait_def!( ( $( $trait_attr) * $( [ doc=$doc2] ) ?) , $trait2, $( ( $( $fn_attr) * ) , $fn, $args, $( $ret) ?) ,* ) ; ) ) +) ;
100- $( trait_impl!( $trait2, $type, $( ( $( $fn_attr) * ) , $fn, $args, $( $ret) ?, { $( $stmts) * } ) ,* ) ; ) +
98+ once!( $( ( trait_def!( ( $( $trait_attr) * $( [ doc=$doc2] ) ?) , $trait2, $( ( $( $fn_attr) * ) , $fn, $( { $ ( $gen ) * } ) ? , ( $ ( $ args) * ) , $( $ret) ?) ,* ) ; ) ) +) ;
99+ $( trait_impl!( $trait2, $type, $( ( $( $fn_attr) * ) , $fn, $( { $ ( $gen ) * } ) ? , ( $ ( $ args) * ) , $( $ret) ?, { $( $stmts) * } ) ,* ) ; ) +
101100 }
102101 } ;
103102}
@@ -106,16 +105,25 @@ impl_via_trait! {
106105 mod token_stream_ext, token_stream2_ext {
107106 /// Generic extensions for
108107 impl TokenStreamExt "[`proc_macro::TokenStream`]" , TokenStream2Ext "[`proc_macro2::TokenStream`]" for TokenStream {
109- /// Pushes a single [`TokenTree`] onto the token stream
108+ /// Pushes a single [`TokenTree`] onto the token stream.
110109 fn push( & mut self , token: TokenTree ) {
111110 self . extend( std:: iter:: once( token) )
112111 }
113- /// Creates a [`TokenParser`](crate::TokenParser) from this token stream
112+ /// Creates a [`TokenParser`](crate::TokenParser) from this token stream.
114113 #[ cfg( feature = "parser" ) ]
115114 fn parser( self ) -> crate :: TokenParser <proc_macro2:: token_stream:: IntoIter > {
116115 #[ allow( clippy:: useless_conversion) ]
117116 proc_macro2:: TokenStream :: from( self ) . into( )
118117 }
118+
119+ /// Creates a [`TokenParser`](crate::TokenParser) from this token stream.
120+ ///
121+ /// Allows to specify the length of the [peeker buffer](crate::TokenParser#peeking).
122+ #[ cfg( feature = "parser" ) ]
123+ fn parser_generic{ <const PEEKER_LEN : usize >} ( self ) -> crate :: TokenParser <proc_macro2:: token_stream:: IntoIter , PEEKER_LEN > {
124+ #[ allow( clippy:: useless_conversion) ]
125+ proc_macro2:: TokenStream :: from( self ) . into( )
126+ }
119127 }
120128 }
121129}
0 commit comments