brintos

brintos / linux-shallow public Read only

0
0
Text · 712 B · 7e4b450 Raw
24 lines · rust
1// SPDX-License-Identifier: GPL-2.02 3use proc_macro::{token_stream, Ident, TokenStream, TokenTree};4 5use crate::helpers::expect_punct;6 7fn expect_ident(it: &mut token_stream::IntoIter) -> Ident {8    if let Some(TokenTree::Ident(ident)) = it.next() {9        ident10    } else {11        panic!("Expected Ident")12    }13}14 15pub(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");21    let res = Ident::new(&format!("{a}{b}"), b.span());22    TokenStream::from_iter([TokenTree::Ident(res)])23}24