Skip to main content

uzor_framework_macros/
lib.rs

1//! Procedural macros for `uzor-framework`.
2//!
3//! Exports `view!` — JSX-mimicking DSL that lowers to `lm::*` builder calls
4//! against the existing L3 `LayoutManager`. No new state, no second manager;
5//! pure compile-time text-rewriting.
6//!
7//! The macro expects two implicit identifiers in scope:
8//! - `layout: &mut LayoutManager<P>`
9//! - `render: &mut dyn RenderContext`
10//!
11//! And one prop-supplied rect on the root node (`<row rect={r}>`), from which
12//! children rects are derived via `uzor_framework::layout::row()/col()` flex
13//! helpers.
14
15extern crate proc_macro;
16
17mod parse;
18mod lower;
19
20use proc_macro::TokenStream;
21
22/// JSX-style view tree. Lowers to imperative `uzor_framework::lm::*` calls.
23///
24/// ```ignore
25/// view! {
26///     <col rect={body} gap=8>
27///         <button text="Save" on_click={|| self.save()} />
28///         <checkbox bind={&mut self.dark} label="Dark" />
29///     </col>
30/// }
31/// ```
32#[proc_macro]
33pub fn view(input: TokenStream) -> TokenStream {
34    let node = match syn::parse::<parse::Node>(input) {
35        Ok(n) => n,
36        Err(e) => return e.to_compile_error().into(),
37    };
38    lower::lower_root(&node).into()
39}