Skip to main content

zyn_core/
lib.rs

1pub mod ast;
2pub mod case;
3pub mod debug;
4pub mod diagnostic;
5pub mod extract;
6pub mod ident;
7pub mod meta;
8pub mod pipes;
9pub mod template;
10pub mod types;
11
12#[cfg(feature = "ext")]
13pub mod ext;
14
15pub use diagnostic::*;
16pub use extract::*;
17pub use meta::*;
18pub use template::Template;
19pub use types::Input;
20
21pub type Result<T> = diagnostic::Result<T>;
22
23/// Parses tokens or string literals into a type. Wraps `syn::parse_str` and `syn::parse2`.
24#[macro_export]
25macro_rules! parse {
26    ($s:literal => $ty:ty) => {
27        $crate::syn::parse_str::<$ty>($s)
28    };
29    ($s:literal) => {
30        $crate::syn::parse_str($s)
31    };
32    ($ts:expr => $ty:ty) => {
33        $crate::syn::parse2::<$ty>($ts)
34    };
35    ($ts:expr) => {
36        $crate::syn::parse2($ts)
37    };
38}
39
40/// Parses a `proc_macro::TokenStream` in a proc macro entry point. Wraps `syn::parse_macro_input!`.
41#[macro_export]
42macro_rules! parse_input {
43    ($($tt:tt)*) => { $crate::syn::parse_macro_input!($($tt)*) }
44}
45
46pub use proc_macro2::{Span, TokenStream};
47pub use quote::{ToTokens, format_ident};
48
49pub use proc_macro2;
50pub use quote;
51pub use syn;
52
53/// Internal trait for AST node expansion. Not part of the public API.
54pub trait Expand {
55    fn expand(
56        &self,
57        output: &proc_macro2::Ident,
58        idents: &mut ident::Iter,
59    ) -> proc_macro2::TokenStream;
60}
61
62/// Implemented by `#[zyn::element]` types. Renders the element with the given `Input` context.
63pub trait Render {
64    fn render(&self, input: &types::Input) -> proc_macro2::TokenStream;
65}
66
67/// Implemented by `#[zyn::pipe]` types. Transforms a value in a pipe chain.
68pub trait Pipe {
69    type Input;
70    type Output: quote::ToTokens;
71
72    fn pipe(&self, input: Self::Input) -> Self::Output;
73}