Crate dioxus_rsx

Source
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.
CallBody
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
ExprNode
ForLoop
FormattedSegment
HotReloadFormattedSegment
A formatted segment that can be hot reloaded
IfAttributeValue
A if else chain attribute value
IfChain
IfmtInput
A hot-reloadable formatted string, boolean, number or other literal
PartialClosure
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.
PartialExpr
A raw expression potentially wrapped in curly braces that is parsed from the input stream.
RsxBlock
An item in the form of
Spread
TemplateBody
A set of nodes in a template position
TextNode

Enums§

AttributeName
AttributeValue
BodyNode
ElementName
FormattedSegmentType
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