File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 11// SPDX-License-Identifier: GPL-2.0
22
3- use proc_macro2:: { token_stream, Ident , TokenStream , TokenTree } ;
3+ use proc_macro2:: {
4+ Ident ,
5+ TokenStream ,
6+ TokenTree , //
7+ } ;
8+ use syn:: {
9+ parse:: {
10+ Parse ,
11+ ParseStream , //
12+ } ,
13+ Result ,
14+ Token , //
15+ } ;
416
5- use crate :: helpers:: expect_punct;
17+ pub ( crate ) struct Input {
18+ a : Ident ,
19+ _comma : Token ! [ , ] ,
20+ b : Ident ,
21+ }
622
7- fn expect_ident ( it : & mut token_stream:: IntoIter ) -> Ident {
8- if let Some ( TokenTree :: Ident ( ident) ) = it. next ( ) {
9- ident
10- } else {
11- panic ! ( "Expected Ident" )
23+ impl Parse for Input {
24+ fn parse ( input : ParseStream < ' _ > ) -> Result < Self > {
25+ Ok ( Self {
26+ a : input. parse ( ) ?,
27+ _comma : input. parse ( ) ?,
28+ b : input. parse ( ) ?,
29+ } )
1230 }
1331}
1432
15- pub ( crate ) fn concat_idents ( ts : TokenStream ) -> TokenStream {
16- let mut it = ts. into_iter ( ) ;
17- let a = expect_ident ( & mut it) ;
18- assert_eq ! ( expect_punct( & mut it) , ',' ) ;
19- let b = expect_ident ( & mut it) ;
20- assert ! ( it. next( ) . is_none( ) , "only two idents can be concatenated" ) ;
33+ pub ( crate ) fn concat_idents ( Input { a, b, .. } : Input ) -> TokenStream {
2134 let res = Ident :: new ( & format ! ( "{a}{b}" ) , b. span ( ) ) ;
2235 TokenStream :: from_iter ( [ TokenTree :: Ident ( res) ] )
2336}
Original file line number Diff line number Diff line change 11// SPDX-License-Identifier: GPL-2.0
22
3- use proc_macro2:: {
4- token_stream,
5- TokenStream ,
6- TokenTree , //
7- } ;
3+ use proc_macro2:: TokenStream ;
84use quote:: ToTokens ;
95use syn:: {
106 parse:: {
@@ -16,14 +12,6 @@ use syn::{
1612 Result , //
1713} ;
1814
19- pub ( crate ) fn expect_punct ( it : & mut token_stream:: IntoIter ) -> char {
20- if let TokenTree :: Punct ( punct) = it. next ( ) . expect ( "Reached end of token stream for Punct" ) {
21- punct. as_char ( )
22- } else {
23- panic ! ( "Expected Punct" ) ;
24- }
25- }
26-
2715/// A string literal that is required to have ASCII value only.
2816pub ( crate ) struct AsciiLitStr ( LitStr ) ;
2917
Original file line number Diff line number Diff line change @@ -311,8 +311,8 @@ pub fn fmt(input: TokenStream) -> TokenStream {
311311/// assert_eq!(BR_OK, binder_driver_return_protocol_BR_OK);
312312/// ```
313313#[ proc_macro]
314- pub fn concat_idents ( ts : TokenStream ) -> TokenStream {
315- concat_idents:: concat_idents ( ts . into ( ) ) . into ( )
314+ pub fn concat_idents ( input : TokenStream ) -> TokenStream {
315+ concat_idents:: concat_idents ( parse_macro_input ! ( input ) ) . into ( )
316316}
317317
318318/// Paste identifiers together.
You can’t perform that action at this time.
0 commit comments