dioxus_rsx/lib.rs
1#![doc(html_logo_url = "https://avatars.githubusercontent.com/u/79236386")]
2#![doc(html_favicon_url = "https://avatars.githubusercontent.com/u/79236386")]
3
4//! Parse the root tokens in the rsx! { } macro
5//! =========================================
6//!
7//! This parsing path emerges directly from the macro call, with `RsxRender` being the primary entrance into parsing.
8//! This feature must support:
9//! - [x] Optionally rendering if the `in XYZ` pattern is present
10//! - [x] Fragments as top-level element (through ambiguous)
11//! - [x] Components as top-level element (through ambiguous)
12//! - [x] Tags as top-level elements (through ambiguous)
13//! - [x] Good errors if parsing fails
14//!
15//! Any errors in using rsx! will likely occur when people start using it, so the first errors must be really helpful.
16//!
17//! # Completions
18//! Rust analyzer completes macros by looking at the expansion of the macro and trying to match the start of identifiers in the macro to identifiers in the current scope
19//!
20//! Eg, if a macro expands to this:
21//! ```rust, ignore
22//! struct MyStruct;
23//!
24//! // macro expansion
25//! My
26//! ```
27//! Then the analyzer will try to match the start of the identifier "My" to an identifier in the current scope (MyStruct in this case).
28//!
29//! In dioxus, our macros expand to the completions module if we know the identifier is incomplete:
30//! ```rust, ignore
31//! // In the root of the macro, identifiers must be elements
32//! // rsx! { di }
33//! dioxus_elements::elements::di
34//!
35//! // Before the first child element, every following identifier is either an attribute or an element
36//! // rsx! { div { ta } }
37//! // Isolate completions scope
38//! mod completions__ {
39//! // import both the attributes and elements this could complete to
40//! use dioxus_elements::elements::div::*;
41//! use dioxus_elements::elements::*;
42//! fn complete() {
43//! ta;
44//! }
45//! }
46//!
47//! // After the first child element, every following identifier is another element
48//! // rsx! { div { attribute: value, child {} di } }
49//! dioxus_elements::elements::di
50//! ```
51
52mod assign_dyn_ids;
53mod attribute;
54mod component;
55mod element;
56mod forloop;
57mod ifchain;
58mod node;
59mod raw_expr;
60mod rsx_block;
61mod rsx_call;
62mod template_body;
63mod text_node;
64
65mod diagnostics;
66mod expr_node;
67mod ifmt;
68mod literal;
69mod location;
70mod partial_closure;
71mod util;
72
73// Re-export the namespaces into each other
74pub use diagnostics::Diagnostics;
75pub use ifmt::*;
76pub use node::*;
77pub use partial_closure::PartialClosure;
78pub use rsx_call::*;
79pub use template_body::TemplateBody;
80
81use quote::{quote, ToTokens, TokenStreamExt};
82use syn::{
83 parse::{Parse, ParseStream},
84 Result, Token,
85};
86
87pub use innerlude::*;
88pub(crate) mod innerlude {
89 pub use crate::attribute::*;
90 pub use crate::component::*;
91 pub use crate::element::*;
92 pub use crate::expr_node::*;
93 pub use crate::forloop::*;
94 pub use crate::ifchain::*;
95 pub use crate::location::*;
96 pub use crate::node::*;
97 pub use crate::raw_expr::*;
98 pub use crate::rsx_block::*;
99 pub use crate::template_body::*;
100 pub use crate::text_node::*;
101
102 pub use crate::diagnostics::*;
103 pub use crate::ifmt::*;
104 pub use crate::literal::*;
105 pub use crate::util::*;
106}