Expand description
§Parse the root tokens in the rsx! { } macro
This parsing path emerges directly from the macro call, with RsxRender
being the primary entrance into parsing.
This feature must support:
-
Optionally rendering if the
in XYZ
pattern is present - Fragments as top-level element (through ambiguous)
- Components as top-level element (through ambiguous)
- Tags as top-level elements (through ambiguous)
- Good errors if parsing fails
Any errors in using rsx! will likely occur when people start using it, so the first errors must be really helpful.
§Completions
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
Eg, if a macro expands to this:
ⓘ
struct MyStruct;
// macro expansion
My
Then the analyzer will try to match the start of the identifier “My” to an identifier in the current scope (MyStruct in this case).
In dioxus, our macros expand to the completions module if we know the identifier is incomplete:
ⓘ
// In the root of the macro, identifiers must be elements
// rsx! { di }
dioxus_elements::elements::di
// Before the first child element, every following identifier is either an attribute or an element
// rsx! { div { ta } }
// Isolate completions scope
mod completions__ {
// import both the attributes and elements this could complete to
use dioxus_elements::elements::div::*;
use dioxus_elements::elements::*;
fn complete() {
ta;
}
}
// After the first child element, every following identifier is another element
// rsx! { div { attribute: value, child {} di } }
dioxus_elements::elements::di
Structs§
- Attribute
- A property value in the from of a
name: value
pair with an optional comma. Note that the colon and value are optional in the case of shorthand attributes. We keep them around to support “lossless” parsing in case that ever might be useful. - Call
Body - The Callbody is the contents of the rsx! macro
- Component
- Diagnostics
- A collection of diagnostics
- DynIdx
- A simple idx in the code that can be used to track back to the original source location
- Element
- Parse the VNode::Element type
- Expr
Node - ForLoop
- Formatted
Segment - HotReload
Formatted Segment - A formatted segment that can be hot reloaded
- IfAttribute
Value - A if else chain attribute value
- IfChain
- Ifmt
Input - A hot-reloadable formatted string, boolean, number or other literal
- Partial
Closure - A closure whose body might not be valid rust code but we want to interpret it regardless. This lets us provide expansions in way more cases than normal closures at the expense of an increased mainteance burden and complexity.
- Partial
Expr - A raw expression potentially wrapped in curly braces that is parsed from the input stream.
- RsxBlock
- An item in the form of
- Spread
- Template
Body - A set of nodes in a template position
- Text
Node
Enums§
- Attribute
Name - Attribute
Value - Body
Node - Element
Name - Formatted
Segment Type - HotLiteral
- A literal value in the rsx! macro
- RsxItem
- Segment
Functions§
- parse_
raw_ ident - Parse a raw ident and return a new ident with the r# prefix added