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