Skip to main content

zyn_core/
lib.rs

1//! Core library for zyn — AST, traits, types, and utilities for procedural macro development.
2
3/// Template AST node types.
4pub mod ast;
5/// Case conversion utilities.
6pub mod case;
7/// Debug formatting and printing for template expansions.
8pub mod debug;
9/// Diagnostic accumulation and emission.
10pub mod diagnostic;
11/// Extractors for resolving values from proc macro input.
12pub mod extract;
13/// Internal identifier generation for template expansion.
14pub mod ident;
15/// Attribute argument parsing types.
16pub mod meta;
17/// Built-in pipe types for template value transforms.
18pub mod pipes;
19/// Template parsing and expansion.
20pub mod template;
21/// Proc macro input types.
22pub mod types;
23
24/// Extension traits for `syn::Attribute` parsing.
25#[cfg(feature = "ext")]
26pub mod ext;
27
28pub use diagnostic::*;
29pub use extract::*;
30pub use meta::*;
31pub use template::Template;
32pub use types::Input;
33
34/// A specialized [`Result`](std::result::Result) type for zyn diagnostics.
35pub type Result<T> = diagnostic::Result<T>;
36
37/// Parses tokens or string literals into a type. Wraps `syn::parse_str` and `syn::parse2`.
38#[macro_export]
39macro_rules! parse {
40    ($s:literal => $ty:ty) => {
41        $crate::syn::parse_str::<$ty>($s)
42    };
43    ($s:literal) => {
44        $crate::syn::parse_str($s)
45    };
46    ($ts:expr => $ty:ty) => {
47        $crate::syn::parse2::<$ty>($ts)
48    };
49    ($ts:expr) => {
50        $crate::syn::parse2($ts)
51    };
52}
53
54/// Parses a `proc_macro::TokenStream` in a proc macro entry point. Wraps `syn::parse_macro_input!`.
55#[macro_export]
56macro_rules! parse_input {
57    ($($tt:tt)*) => { $crate::syn::parse_macro_input!($($tt)*) }
58}
59
60pub use proc_macro2::{Span, TokenStream};
61pub use quote::{ToTokens, format_ident};
62
63pub use proc_macro2;
64pub use quote;
65pub use syn;
66
67/// Internal trait for AST node expansion. Not part of the public API.
68pub trait Expand {
69    fn expand(
70        &self,
71        output: &proc_macro2::Ident,
72        idents: &mut ident::Iter,
73    ) -> proc_macro2::TokenStream;
74}
75
76/// Implemented by `#[zyn::element]` types. Renders the element with the given `Input` context.
77pub trait Render {
78    fn render(&self, input: &types::Input) -> proc_macro2::TokenStream;
79}
80
81/// Implemented by `#[zyn::pipe]` types. Transforms a value in a pipe chain.
82pub trait Pipe {
83    type Input;
84    type Output: quote::ToTokens;
85
86    fn pipe(&self, input: Self::Input) -> Self::Output;
87}