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/// Dot-separated path type for navigating nested `syn` metadata.
18pub mod path;
19/// Built-in pipe types for template value transforms.
20pub mod pipes;
21/// Template parsing and expansion.
22pub mod template;
23/// Proc macro input types.
24pub mod types;
25
26/// Extension traits for common `syn` AST types.
27#[cfg(feature = "ext")]
28pub mod ext;
29
30pub use diagnostic::*;
31pub use extract::*;
32pub use meta::*;
33pub use template::Template;
34pub use types::Input;
35
36/// A specialized [`Result`](std::result::Result) type for zyn diagnostics.
37pub type Result<T> = diagnostic::Result<T>;
38
39/// Parses tokens or string literals into a type. Wraps `syn::parse_str` and `syn::parse2`.
40#[macro_export]
41macro_rules! parse {
42    ($s:literal => $ty:ty) => {
43        $crate::syn::parse_str::<$ty>($s)
44    };
45    ($s:literal) => {
46        $crate::syn::parse_str($s)
47    };
48    ($ts:expr => $ty:ty) => {
49        $crate::syn::parse2::<$ty>($ts)
50    };
51    ($ts:expr) => {
52        $crate::syn::parse2($ts)
53    };
54}
55
56/// Parses a `proc_macro::TokenStream` in a proc macro entry point. Wraps `syn::parse_macro_input!`.
57#[macro_export]
58macro_rules! parse_input {
59    ($($tt:tt)*) => { $crate::syn::parse_macro_input!($($tt)*) }
60}
61
62pub use proc_macro2::{Span, TokenStream};
63pub use quote::{ToTokens, format_ident};
64
65pub use proc_macro2;
66pub use quote;
67pub use syn;
68
69/// Internal trait for AST node expansion. Not part of the public API.
70pub trait Expand {
71    fn expand(
72        &self,
73        output: &proc_macro2::Ident,
74        idents: &mut ident::Iter,
75    ) -> proc_macro2::TokenStream;
76}
77
78/// Implemented by `#[zyn::element]` types. Renders the element with the given `Input` context.
79pub trait Render {
80    fn render(&self, input: &types::Input) -> proc_macro2::TokenStream;
81}
82
83/// Implemented by `#[zyn::pipe]` types. Transforms a value in a pipe chain.
84pub trait Pipe {
85    type Input;
86    type Output: quote::ToTokens;
87
88    fn pipe(&self, input: Self::Input) -> Self::Output;
89}