Skip to main content

zyn_core/ast/
tokens_node.rs

1use proc_macro2::Ident;
2use proc_macro2::Span;
3use proc_macro2::TokenStream;
4
5use quote::quote;
6
7use crate::Expand;
8
9/// Literal Rust tokens passed through unchanged in a zyn template.
10///
11/// In `zyn! { fn {{ name }}() {} }`, the tokens `fn`, `(`, `)`, `{`, `}` each
12/// contribute to a `TokensNode`.
13pub struct TokensNode {
14    /// Source span.
15    pub span: Span,
16    /// The literal token stream.
17    pub stream: TokenStream,
18}
19
20impl TokensNode {
21    pub fn span(&self) -> Span {
22        self.span
23    }
24}
25
26impl Expand for TokensNode {
27    fn expand(&self, output: &Ident, _idents: &mut crate::ident::Iter) -> TokenStream {
28        let stream = &self.stream;
29        quote! {
30            #output.extend(::zyn::quote::quote!(#stream));
31        }
32    }
33}