1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
//! # iced-markup
//!
//! A declarative markup DSL (Domain-Specific Language) for building
//! [Iced](https://iced.rs) GUI applications in Rust.
//!
//! Instead of writing deeply nested builder chains by hand, you write a
//! concise, JSX-inspired syntax inside the [`view!`] macro and get
//! idiomatic Iced widget code at compile time — zero runtime overhead.
//!
//! ## Quick example
//!
//! ```no_run
//! use iced::widget::{column, row, text, button};
//! use iced_markup::view;
//!
//! #[derive(Clone)]
//! enum Msg { Click }
//!
//! fn view() -> iced::Element<'static, Msg> {
//! view! {
//! column ![spacing: 20, padding: 40] {
//! text("Welcome to Iced!") {},
//! row ![spacing: 10] {
//! button("Increment") ![on_press: Msg::Click] {},
//! button("Decrement") ![on_press: Msg::Click] {},
//! },
//! }
//! }
//! .into()
//! }
//! ```
//!
//! ## Advanced Features
//!
//! `iced_markup` provides several advanced features to simplify complex UIs:
//!
//! ### 1. Native Control Flow
//! Use real `if` and `for` blocks inside your markup:
//!
//! ```no_run
//! # use iced_markup::view;
//! # use iced::widget::{column, text, Column};
//! # use iced::{Theme, Renderer};
//! # let show_admin = true;
//! # let items = vec!["A"];
//! # enum Msg { Item }
//! let _: Column<'_, Msg, Theme, Renderer> = view! {
//! column {
//! if show_admin {
//! text("Admin Panel") {}
//! },
//! for item in items {
//! text(item) {}
//! }
//! }
//! };
//! ```
//!
//! ### 2. Thematic Pipes (`|`)
//! Apply styles or themes with a sleek syntax:
//!
//! ```no_run
//! # use iced_markup::view;
//! # use iced::widget::{text, Column, column};
//! # use iced::{Theme, Renderer};
//! # enum Msg { Item }
//! let _: Column<'_, Msg, Theme, Renderer> = view! {
//! column {
//! text("Hello") | |_: &Theme| iced::widget::text::Style { color: Some(iced::Color::WHITE) } {}
//! }
//! };
//! ```
//!
//! ### 3. Event Shorthands (`+`)
//! Use `+click`, `+input`, or `+submit` for common events:
//!
//! ```no_run
//! # use iced_markup::view;
//! # use iced::widget::{button, Column, column};
//! # use iced::{Theme, Renderer};
//! # #[derive(Clone)] enum Msg { Save }
//! let _: Column<'_, Msg, Theme, Renderer> = view! {
//! column {
//! button("Save") ![+click: Msg::Save] {}
//! }
//! };
//! ```
//!
//! ### 4. Component Slots (`@`)
//! Use named slots for flexible widget configuration:
//!
//! ```no_run
//! # use iced_markup::view;
//! # use iced::widget::{button, Column, column};
//! # use iced::{Theme, Renderer};
//! # #[derive(Clone)] enum Msg { Click }
//! let _: Column<'_, Msg, Theme, Renderer> = view! {
//! column {
//! button("Submit") {
//! @on_press: Msg::Click
//! }
//! }
//! };
//! ```
//!
//! ## Architecture
//!
//! The crate is structured as a classic compiler pipeline:
//!
//! 1. **[`parser`]** — Reads the token stream and produces a typed AST.
//! 2. **[`node`]** — Defines every node type (widgets, attributes, control flow).
//! 3. **[`codegen`]** — Implements `ToTokens` for every AST node, emitting
//! optimized Iced Rust code.
//!
//! The public entry point is the [`view!`] procedural macro defined below.
use TokenStream;
use proc_macro_error;
use ToTokens;
use parse_macro_input;
use crateMarkup;
/// The `view!` procedural macro transforms a declarative, JSX-inspired markup syntax
/// into idiomatic [Iced](https://iced.rs) widget code at compile time.
///
/// This provides a much more readable and maintainable way to define GUI layouts
/// compared to deeply nested builder chains, while maintaining zero runtime overhead.
///
/// # Syntax breakdown
///
/// ```text
/// view! {
/// widget_name(constructor_args) ![attribute: value] {
/// child_widget,
/// }
/// }
/// ```
///
/// - **`widget_name`**: The Iced widget to create (e.g., `column`, `row`, `text`). Only widgets that support `.push()` (like `Column` and `Row`) should have children in `{}` blocks.
/// - **`constructor_args`**: (Optional) Arguments passed to the widget's creation function.
/// - **`attributes`**: (Optional) Modifiers applied via `![...]` (e.g., `![spacing: 10]`).
/// - **`children`**: (Optional) Nested widgets inside `{...}` separated by commas.
///
/// # Example
///
/// ```no_run
/// # use iced_markup::view;
/// # use iced::widget::{column, text, button, Column};
/// # use iced::{Theme, Renderer};
/// # #[derive(Clone)] enum Message { Clicked }
/// let _: Column<'_, Message, Theme, Renderer> = view! {
/// column ![spacing: 20] {
/// text("Hello World") {},
/// button("Click me") ![on_press: Message::Clicked] {},
/// }
/// };
/// ```
///
/// Expands roughly to:
///
/// ```no_run
/// # use iced::widget::{column, text, button, Column};
/// # use iced::{Theme, Renderer};
/// # #[derive(Clone)] enum Message { Clicked }
/// let _: Column<'_, Message, Theme, Renderer> = iced::widget::column([])
/// .spacing(20)
/// .push(iced::widget::text("Hello World"))
/// .push(iced::widget::button("Click me").on_press(Message::Clicked));
/// ```