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/// Extractors for resolving values from proc macro input.
10pub mod extract;
11/// Internal identifier generation for template expansion.
12pub mod ident;
13/// Types and implementations for marking spans.
14pub mod mark;
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 extract::*;
31pub use mark::*;
32pub use meta::*;
33pub use template::Template;
34pub use types::Input;
35
36/// Parses tokens or string literals into a type. Wraps `syn::parse_str` and `syn::parse2`.
37#[macro_export]
38macro_rules! parse {
39    ($s:literal => $ty:ty) => {
40        $crate::syn::parse_str::<$ty>($s)
41    };
42    ($s:literal) => {
43        $crate::syn::parse_str($s)
44    };
45    ($ts:expr => $ty:ty) => {
46        $crate::syn::parse2::<$ty>($ts)
47    };
48    ($ts:expr) => {
49        $crate::syn::parse2($ts)
50    };
51}
52
53/// Parses a `proc_macro::TokenStream` in a proc macro entry point. Wraps `syn::parse_macro_input!`.
54#[macro_export]
55macro_rules! parse_input {
56    ($($tt:tt)*) => { $crate::syn::parse_macro_input!($($tt)*) }
57}
58
59pub use proc_macro2::{Span, TokenStream};
60pub use quote::{ToTokens, format_ident};
61
62pub use proc_macro2;
63pub use quote;
64pub use syn;
65
66/// Internal trait for AST node expansion. Not part of the public API.
67pub trait Expand {
68    fn expand(
69        &self,
70        output: &proc_macro2::Ident,
71        idents: &mut ident::Iter,
72    ) -> proc_macro2::TokenStream;
73}
74
75/// Implemented by `#[zyn::element]` types. Renders the element with the given `Input` context.
76pub trait Render {
77    fn render(&self, input: &types::Input) -> proc_macro2::TokenStream;
78}
79
80/// Implemented by `#[zyn::pipe]` types. Transforms a value in a pipe chain.
81pub trait Pipe {
82    type Input;
83    type Output: quote::ToTokens;
84
85    fn pipe(&self, input: Self::Input) -> Self::Output;
86}