wip: more upgades to html parser
This commit is contained in:
1 parent
160d86abbe
commit
22f894e6b9
3 files changed
+165
-128
No files matched your search
@@ -16,41 +16,12 @@ pub struct RsxBody<const AS: HTML_OR_RSX> {
|
|||||||
/// The custom rusty variant of parsing rsx!
|
/// The custom rusty variant of parsing rsx!
|
||||||
impl Parse for RsxBody<AS_RSX> {
|
impl Parse for RsxBody<AS_RSX> {
|
||||||
fn parse(input: ParseStream) -> Result<Self> {
|
fn parse(input: ParseStream) -> Result<Self> {
|
||||||
// if input.peek(LitStr) {
|
let custom_context = try_parse_custom_context(input)?;
|
||||||
// return input.parse::<LitStr>()?.parse::<RsxRender>();
|
let (_, roots, _) =
|
||||||
// }
|
BodyParseConfig::<AS_RSX>::new_as_body().parse_component_body(&input)?;
|
||||||
|
|
||||||
// try to parse the first ident and comma
|
|
||||||
let custom_context =
|
|
||||||
if input.peek(Token![in]) && input.peek2(Ident) && input.peek3(Token![,]) {
|
|
||||||
let _ = input.parse::<Token![in]>()?;
|
|
||||||
let name = input.parse::<Ident>()?;
|
|
||||||
if is_valid_tag(&name.to_string()) {
|
|
||||||
return Err(Error::new(
|
|
||||||
input.span(),
|
|
||||||
"Custom context cannot be an html element name",
|
|
||||||
));
|
|
||||||
} else {
|
|
||||||
input.parse::<Token![,]>().unwrap();
|
|
||||||
Some(name)
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
None
|
|
||||||
};
|
|
||||||
|
|
||||||
let mut body = Vec::new();
|
|
||||||
let mut children = Vec::new();
|
|
||||||
let mut manual_props = None;
|
|
||||||
let cfg: BodyParseConfig<AS_RSX> = BodyParseConfig {
|
|
||||||
allow_children: true,
|
|
||||||
allow_fields: false,
|
|
||||||
allow_manual_props: false,
|
|
||||||
};
|
|
||||||
cfg.parse_component_body(input, &mut body, &mut children, &mut manual_props)?;
|
|
||||||
|
|
||||||
Ok(Self {
|
Ok(Self {
|
||||||
roots: children,
|
|
||||||
custom_context,
|
custom_context,
|
||||||
|
roots,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -58,46 +29,28 @@ impl Parse for RsxBody<AS_RSX> {
|
|||||||
/// The HTML variant of parsing rsx!
|
/// The HTML variant of parsing rsx!
|
||||||
impl Parse for RsxBody<AS_HTML> {
|
impl Parse for RsxBody<AS_HTML> {
|
||||||
fn parse(input: ParseStream) -> Result<Self> {
|
fn parse(input: ParseStream) -> Result<Self> {
|
||||||
// if input.peek(LitStr) {
|
let custom_context = try_parse_custom_context(input)?;
|
||||||
// return input.parse::<LitStr>()?.parse::<RsxRender>();
|
let (_, roots, _) =
|
||||||
// }
|
BodyParseConfig::<AS_HTML>::new_as_body().parse_component_body(&input)?;
|
||||||
|
|
||||||
// try to parse the first ident and comma
|
|
||||||
let custom_context =
|
|
||||||
if input.peek(Token![in]) && input.peek2(Ident) && input.peek3(Token![,]) {
|
|
||||||
let _ = input.parse::<Token![in]>()?;
|
|
||||||
let name = input.parse::<Ident>()?;
|
|
||||||
if is_valid_tag(&name.to_string()) {
|
|
||||||
return Err(Error::new(
|
|
||||||
input.span(),
|
|
||||||
"Custom context cannot be an html element name",
|
|
||||||
));
|
|
||||||
} else {
|
|
||||||
input.parse::<Token![,]>().unwrap();
|
|
||||||
Some(name)
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
None
|
|
||||||
};
|
|
||||||
|
|
||||||
let mut body = Vec::new();
|
|
||||||
let mut children = Vec::new();
|
|
||||||
let mut manual_props = None;
|
|
||||||
|
|
||||||
let cfg: BodyParseConfig<AS_HTML> = BodyParseConfig {
|
|
||||||
allow_children: true,
|
|
||||||
allow_fields: false,
|
|
||||||
allow_manual_props: false,
|
|
||||||
};
|
|
||||||
cfg.parse_component_body(input, &mut body, &mut children, &mut manual_props)?;
|
|
||||||
|
|
||||||
Ok(Self {
|
Ok(Self {
|
||||||
roots: children,
|
|
||||||
custom_context,
|
custom_context,
|
||||||
|
roots,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn try_parse_custom_context(input: ParseStream) -> Result<Option<Ident>> {
|
||||||
|
let res = if input.peek(Token![in]) && input.peek2(Ident) && input.peek3(Token![,]) {
|
||||||
|
let _ = input.parse::<Token![in]>()?;
|
||||||
|
let name = input.parse::<Ident>()?;
|
||||||
|
input.parse::<Token![,]>()?;
|
||||||
|
Some(name)
|
||||||
|
} else {
|
||||||
|
None
|
||||||
|
};
|
||||||
|
Ok(res)
|
||||||
|
}
|
||||||
|
|
||||||
/// Serialize the same way, regardless of flavor
|
/// Serialize the same way, regardless of flavor
|
||||||
impl<const A: HTML_OR_RSX> ToTokens for RsxBody<A> {
|
impl<const A: HTML_OR_RSX> ToTokens for RsxBody<A> {
|
||||||
fn to_tokens(&self, out_tokens: &mut TokenStream2) {
|
fn to_tokens(&self, out_tokens: &mut TokenStream2) {
|
||||||
@@ -113,7 +66,7 @@ impl<const A: HTML_OR_RSX> ToTokens for RsxBody<A> {
|
|||||||
// The `in cx` pattern allows directly rendering
|
// The `in cx` pattern allows directly rendering
|
||||||
Some(ident) => out_tokens.append_all(quote! {
|
Some(ident) => out_tokens.append_all(quote! {
|
||||||
#ident.render(dioxus::prelude::LazyNodes::new(move |__cx: NodeFactory|{
|
#ident.render(dioxus::prelude::LazyNodes::new(move |__cx: NodeFactory|{
|
||||||
use dioxus_elements::GlobalAttributes;
|
use dioxus_elements::{GlobalAttributes, SvgAttributes};
|
||||||
|
|
||||||
#inner
|
#inner
|
||||||
}))
|
}))
|
||||||
@@ -121,7 +74,7 @@ impl<const A: HTML_OR_RSX> ToTokens for RsxBody<A> {
|
|||||||
// Otherwise we just build the LazyNode wrapper
|
// Otherwise we just build the LazyNode wrapper
|
||||||
None => out_tokens.append_all(quote! {
|
None => out_tokens.append_all(quote! {
|
||||||
dioxus::prelude::LazyNodes::new(move |__cx: NodeFactory|{
|
dioxus::prelude::LazyNodes::new(move |__cx: NodeFactory|{
|
||||||
use dioxus_elements::GlobalAttributes;
|
use dioxus_elements::{GlobalAttributes, SvgAttributes};
|
||||||
|
|
||||||
#inner
|
#inner
|
||||||
})
|
})
|
||||||
|
|||||||
@@ -41,17 +41,13 @@ impl Parse for Component<AS_RSX> {
|
|||||||
let content: ParseBuffer;
|
let content: ParseBuffer;
|
||||||
syn::braced!(content in stream);
|
syn::braced!(content in stream);
|
||||||
|
|
||||||
let mut body: Vec<ComponentField<AS_RSX>> = Vec::new();
|
|
||||||
let mut children: Vec<BodyNode<AS_RSX>> = Vec::new();
|
|
||||||
let mut manual_props = None;
|
|
||||||
|
|
||||||
let cfg: BodyParseConfig<AS_RSX> = BodyParseConfig {
|
let cfg: BodyParseConfig<AS_RSX> = BodyParseConfig {
|
||||||
allow_children: true,
|
allow_children: true,
|
||||||
allow_fields: true,
|
allow_fields: true,
|
||||||
allow_manual_props: true,
|
allow_manual_props: true,
|
||||||
};
|
};
|
||||||
|
|
||||||
cfg.parse_component_body(&content, &mut body, &mut children, &mut manual_props)?;
|
let (body, children, manual_props) = cfg.parse_component_body(&content)?;
|
||||||
|
|
||||||
Ok(Self {
|
Ok(Self {
|
||||||
name,
|
name,
|
||||||
@@ -69,17 +65,13 @@ impl Parse for Component<AS_HTML> {
|
|||||||
let content: ParseBuffer;
|
let content: ParseBuffer;
|
||||||
syn::braced!(content in stream);
|
syn::braced!(content in stream);
|
||||||
|
|
||||||
let mut body: Vec<ComponentField<AS_HTML>> = Vec::new();
|
|
||||||
let mut children: Vec<BodyNode<AS_HTML>> = Vec::new();
|
|
||||||
let mut manual_props = None;
|
|
||||||
|
|
||||||
let cfg: BodyParseConfig<AS_HTML> = BodyParseConfig {
|
let cfg: BodyParseConfig<AS_HTML> = BodyParseConfig {
|
||||||
allow_children: true,
|
allow_children: true,
|
||||||
allow_fields: true,
|
allow_fields: true,
|
||||||
allow_manual_props: true,
|
allow_manual_props: true,
|
||||||
};
|
};
|
||||||
|
|
||||||
cfg.parse_component_body(&content, &mut body, &mut children, &mut manual_props)?;
|
let (body, children, manual_props) = cfg.parse_component_body(&content)?;
|
||||||
|
|
||||||
Ok(Self {
|
Ok(Self {
|
||||||
name,
|
name,
|
||||||
@@ -95,16 +87,33 @@ pub struct BodyParseConfig<const AS: HTML_OR_RSX> {
|
|||||||
pub allow_children: bool,
|
pub allow_children: bool,
|
||||||
pub allow_manual_props: bool,
|
pub allow_manual_props: bool,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl<const AS: HTML_OR_RSX> BodyParseConfig<AS> {
|
||||||
|
/// The configuration to parse the root
|
||||||
|
pub fn new_as_body() -> Self {
|
||||||
|
Self {
|
||||||
|
allow_children: true,
|
||||||
|
allow_fields: false,
|
||||||
|
allow_manual_props: false,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
impl BodyParseConfig<AS_RSX> {
|
impl BodyParseConfig<AS_RSX> {
|
||||||
// todo: unify this body parsing for both elements and components
|
// todo: unify this body parsing for both elements and components
|
||||||
// both are style rather ad-hoc, though components are currently more configured
|
// both are style rather ad-hoc, though components are currently more configured
|
||||||
pub fn parse_component_body(
|
pub fn parse_component_body(
|
||||||
&self,
|
&self,
|
||||||
content: &ParseBuffer,
|
content: &ParseBuffer,
|
||||||
body: &mut Vec<ComponentField<AS_RSX>>,
|
) -> Result<(
|
||||||
children: &mut Vec<BodyNode<AS_RSX>>,
|
Vec<ComponentField<AS_RSX>>,
|
||||||
manual_props: &mut Option<Expr>,
|
Vec<BodyNode<AS_RSX>>,
|
||||||
) -> Result<()> {
|
Option<Expr>,
|
||||||
|
)> {
|
||||||
|
let mut body = Vec::new();
|
||||||
|
let mut children = Vec::new();
|
||||||
|
let mut manual_props = None;
|
||||||
|
|
||||||
'parsing: loop {
|
'parsing: loop {
|
||||||
// [1] Break if empty
|
// [1] Break if empty
|
||||||
if content.is_empty() {
|
if content.is_empty() {
|
||||||
@@ -119,7 +128,7 @@ impl BodyParseConfig<AS_RSX> {
|
|||||||
));
|
));
|
||||||
}
|
}
|
||||||
content.parse::<Token![..]>()?;
|
content.parse::<Token![..]>()?;
|
||||||
*manual_props = Some(content.parse::<Expr>()?);
|
manual_props = Some(content.parse::<Expr>()?);
|
||||||
} else if content.peek(Ident) && content.peek2(Token![:]) && !content.peek3(Token![:]) {
|
} else if content.peek(Ident) && content.peek2(Token![:]) && !content.peek3(Token![:]) {
|
||||||
if !self.allow_fields {
|
if !self.allow_fields {
|
||||||
return Err(Error::new(
|
return Err(Error::new(
|
||||||
@@ -144,7 +153,7 @@ impl BodyParseConfig<AS_RSX> {
|
|||||||
let _ = content.parse::<Token![,]>();
|
let _ = content.parse::<Token![,]>();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Ok(())
|
Ok((body, children, manual_props))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
impl BodyParseConfig<AS_HTML> {
|
impl BodyParseConfig<AS_HTML> {
|
||||||
@@ -153,10 +162,15 @@ impl BodyParseConfig<AS_HTML> {
|
|||||||
pub fn parse_component_body(
|
pub fn parse_component_body(
|
||||||
&self,
|
&self,
|
||||||
content: &ParseBuffer,
|
content: &ParseBuffer,
|
||||||
body: &mut Vec<ComponentField<AS_HTML>>,
|
) -> Result<(
|
||||||
children: &mut Vec<BodyNode<AS_HTML>>,
|
Vec<ComponentField<AS_HTML>>,
|
||||||
manual_props: &mut Option<Expr>,
|
Vec<BodyNode<AS_HTML>>,
|
||||||
) -> Result<()> {
|
Option<Expr>,
|
||||||
|
)> {
|
||||||
|
let mut body = Vec::new();
|
||||||
|
let mut children = Vec::new();
|
||||||
|
let mut manual_props = None;
|
||||||
|
|
||||||
'parsing: loop {
|
'parsing: loop {
|
||||||
// [1] Break if empty
|
// [1] Break if empty
|
||||||
if content.is_empty() {
|
if content.is_empty() {
|
||||||
@@ -171,7 +185,7 @@ impl BodyParseConfig<AS_HTML> {
|
|||||||
));
|
));
|
||||||
}
|
}
|
||||||
content.parse::<Token![..]>()?;
|
content.parse::<Token![..]>()?;
|
||||||
*manual_props = Some(content.parse::<Expr>()?);
|
manual_props = Some(content.parse::<Expr>()?);
|
||||||
} else if content.peek(Ident) && content.peek2(Token![:]) && !content.peek3(Token![:]) {
|
} else if content.peek(Ident) && content.peek2(Token![:]) && !content.peek3(Token![:]) {
|
||||||
if !self.allow_fields {
|
if !self.allow_fields {
|
||||||
return Err(Error::new(
|
return Err(Error::new(
|
||||||
@@ -196,7 +210,7 @@ impl BodyParseConfig<AS_HTML> {
|
|||||||
let _ = content.parse::<Token![,]>();
|
let _ = content.parse::<Token![,]>();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Ok(())
|
Ok((body, children, manual_props))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -14,8 +14,8 @@ use syn::{
|
|||||||
pub struct Element<const AS: HTML_OR_RSX> {
|
pub struct Element<const AS: HTML_OR_RSX> {
|
||||||
name: Ident,
|
name: Ident,
|
||||||
key: Option<AttrType>,
|
key: Option<AttrType>,
|
||||||
attributes: Vec<ElementAttr>,
|
attributes: Vec<ElementAttr<AS>>,
|
||||||
listeners: Vec<ElementAttr>,
|
listeners: Vec<ElementAttr<AS>>,
|
||||||
children: Vec<BodyNode<AS>>,
|
children: Vec<BodyNode<AS>>,
|
||||||
is_static: bool,
|
is_static: bool,
|
||||||
}
|
}
|
||||||
@@ -28,8 +28,8 @@ impl Parse for Element<AS_RSX> {
|
|||||||
let content: ParseBuffer;
|
let content: ParseBuffer;
|
||||||
syn::braced!(content in stream);
|
syn::braced!(content in stream);
|
||||||
|
|
||||||
let mut attributes: Vec<ElementAttr> = vec![];
|
let mut attributes: Vec<ElementAttr<AS_RSX>> = vec![];
|
||||||
let mut listeners: Vec<ElementAttr> = vec![];
|
let mut listeners: Vec<ElementAttr<AS_RSX>> = vec![];
|
||||||
let mut children: Vec<BodyNode<AS_RSX>> = vec![];
|
let mut children: Vec<BodyNode<AS_RSX>> = vec![];
|
||||||
let mut key = None;
|
let mut key = None;
|
||||||
|
|
||||||
@@ -40,7 +40,7 @@ impl Parse for Element<AS_RSX> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if content.peek(Ident) && content.peek2(Token![:]) && !content.peek3(Token![:]) {
|
if content.peek(Ident) && content.peek2(Token![:]) && !content.peek3(Token![:]) {
|
||||||
parse_element_body(
|
parse_rsx_element_field(
|
||||||
&content,
|
&content,
|
||||||
&mut attributes,
|
&mut attributes,
|
||||||
&mut listeners,
|
&mut listeners,
|
||||||
@@ -71,45 +71,114 @@ impl Parse for Element<AS_RSX> {
|
|||||||
|
|
||||||
impl Parse for Element<AS_HTML> {
|
impl Parse for Element<AS_HTML> {
|
||||||
fn parse(stream: ParseStream) -> Result<Self> {
|
fn parse(stream: ParseStream) -> Result<Self> {
|
||||||
let name = Ident::parse(stream)?;
|
let l_tok = stream.parse::<Token![<]>()?;
|
||||||
|
let el_name = Ident::parse(stream)?;
|
||||||
|
|
||||||
// parse the guts
|
// parse the guts
|
||||||
let content: ParseBuffer;
|
// let content: ParseBuffer;
|
||||||
syn::braced!(content in stream);
|
// syn::braced!(content in stream);
|
||||||
|
|
||||||
let mut attributes: Vec<ElementAttr> = vec![];
|
let mut attributes: Vec<ElementAttr<AS_HTML>> = vec![];
|
||||||
let mut listeners: Vec<ElementAttr> = vec![];
|
let mut listeners: Vec<ElementAttr<AS_HTML>> = vec![];
|
||||||
let mut children: Vec<BodyNode<AS_HTML>> = vec![];
|
let mut children: Vec<BodyNode<AS_HTML>> = vec![];
|
||||||
let mut key = None;
|
let mut key = None;
|
||||||
|
|
||||||
'parsing: loop {
|
// loop {
|
||||||
// [1] Break if empty
|
// if stream.peek(Token![>]) {
|
||||||
if content.is_empty() {
|
// break;
|
||||||
break 'parsing;
|
// } else {
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
while !stream.peek(Token![>]) {
|
||||||
|
// self-closing
|
||||||
|
if stream.peek(Token![/]) {
|
||||||
|
stream.parse::<Token![/]>()?;
|
||||||
|
stream.parse::<Token![>]>()?;
|
||||||
|
|
||||||
|
return Ok(Self {
|
||||||
|
name: el_name,
|
||||||
|
key: None,
|
||||||
|
attributes,
|
||||||
|
is_static: false,
|
||||||
|
listeners,
|
||||||
|
children,
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
if content.peek(Ident) && content.peek2(Token![:]) && !content.peek3(Token![:]) {
|
let name = Ident::parse_any(stream)?;
|
||||||
parse_element_body(
|
let name_str = name.to_string();
|
||||||
&content,
|
stream.parse::<Token![=]>()?;
|
||||||
&mut attributes,
|
if name_str.starts_with("on") {
|
||||||
&mut listeners,
|
todo!()
|
||||||
&mut key,
|
|
||||||
name.clone(),
|
|
||||||
)?;
|
|
||||||
} else {
|
} else {
|
||||||
children.push(content.parse::<BodyNode<AS_HTML>>()?);
|
match name_str.as_str() {
|
||||||
}
|
"style" => todo!(),
|
||||||
|
"key" => todo!(),
|
||||||
|
"classes" => todo!(),
|
||||||
|
"namespace" => todo!(),
|
||||||
|
"ref" => todo!(),
|
||||||
|
_ => {
|
||||||
|
let ty = if stream.peek(LitStr) {
|
||||||
|
let rawtext = stream.parse::<LitStr>().unwrap();
|
||||||
|
AttrType::BumpText(rawtext)
|
||||||
|
} else {
|
||||||
|
let toks = stream.parse::<Expr>()?;
|
||||||
|
AttrType::FieldTokens(toks)
|
||||||
|
};
|
||||||
|
attributes.push(ElementAttr {
|
||||||
|
element_name: el_name.clone(),
|
||||||
|
name,
|
||||||
|
value: ty,
|
||||||
|
namespace: None,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
// if stream.peek(LitStr) {
|
||||||
|
|
||||||
// consume comma if it exists
|
// } else {
|
||||||
// we don't actually care if there *are* commas after elements/text
|
// }
|
||||||
if content.peek(Token![,]) {
|
// if name_str.starts_with("on") {}
|
||||||
let _ = content.parse::<Token![,]>();
|
|
||||||
}
|
// attributes.push(stream.parse()?);
|
||||||
}
|
}
|
||||||
|
stream.parse::<Token![>]>()?;
|
||||||
|
|
||||||
|
// closing element
|
||||||
|
stream.parse::<Token![<]>()?;
|
||||||
|
stream.parse::<Token![/]>()?;
|
||||||
|
let close = Ident::parse_any(stream)?;
|
||||||
|
if close.to_string() != el_name.to_string() {
|
||||||
|
return Err(Error::new_spanned(
|
||||||
|
close,
|
||||||
|
"closing element does not match opening",
|
||||||
|
));
|
||||||
|
}
|
||||||
|
stream.parse::<Token![>]>()?;
|
||||||
|
// 'parsing: loop {
|
||||||
|
// // if stream.peek(Token![>]) {}
|
||||||
|
|
||||||
|
// // // [1] Break if empty
|
||||||
|
// // if content.is_empty() {
|
||||||
|
// // break 'parsing;
|
||||||
|
// // }
|
||||||
|
|
||||||
|
// if content.peek(Ident) && content.peek2(Token![:]) && !content.peek3(Token![:]) {
|
||||||
|
// parse_element_body(
|
||||||
|
// &content,
|
||||||
|
// &mut attributes,
|
||||||
|
// &mut listeners,
|
||||||
|
// &mut key,
|
||||||
|
// name.clone(),
|
||||||
|
// )?;
|
||||||
|
// } else {
|
||||||
|
// children.push(stream.parse::<BodyNode<AS_HTML>>()?);
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
|
||||||
Ok(Self {
|
Ok(Self {
|
||||||
key,
|
key,
|
||||||
name,
|
name: el_name,
|
||||||
attributes,
|
attributes,
|
||||||
children,
|
children,
|
||||||
listeners,
|
listeners,
|
||||||
@@ -140,7 +209,7 @@ impl<const AS: HTML_OR_RSX> ToTokens for Element<AS> {
|
|||||||
/// =======================================
|
/// =======================================
|
||||||
/// Parse a VElement's Attributes
|
/// Parse a VElement's Attributes
|
||||||
/// =======================================
|
/// =======================================
|
||||||
struct ElementAttr {
|
struct ElementAttr<const AS: HTML_OR_RSX> {
|
||||||
element_name: Ident,
|
element_name: Ident,
|
||||||
name: Ident,
|
name: Ident,
|
||||||
value: AttrType,
|
value: AttrType,
|
||||||
@@ -157,14 +226,14 @@ enum AttrType {
|
|||||||
// We parse attributes and dump them into the attribute vec
|
// We parse attributes and dump them into the attribute vec
|
||||||
// This is because some tags might be namespaced (IE style)
|
// This is because some tags might be namespaced (IE style)
|
||||||
// These dedicated tags produce multiple name-spaced attributes
|
// These dedicated tags produce multiple name-spaced attributes
|
||||||
fn parse_element_body(
|
fn parse_rsx_element_field(
|
||||||
stream: ParseStream,
|
stream: ParseStream,
|
||||||
attrs: &mut Vec<ElementAttr>,
|
attrs: &mut Vec<ElementAttr<AS_RSX>>,
|
||||||
listeners: &mut Vec<ElementAttr>,
|
listeners: &mut Vec<ElementAttr<AS_RSX>>,
|
||||||
key: &mut Option<AttrType>,
|
key: &mut Option<AttrType>,
|
||||||
element_name: Ident,
|
element_name: Ident,
|
||||||
) -> Result<()> {
|
) -> Result<()> {
|
||||||
let mut name = Ident::parse_any(stream)?;
|
let name = Ident::parse_any(stream)?;
|
||||||
let name_str = name.to_string();
|
let name_str = name.to_string();
|
||||||
stream.parse::<Token![:]>()?;
|
stream.parse::<Token![:]>()?;
|
||||||
|
|
||||||
@@ -199,7 +268,8 @@ fn parse_element_body(
|
|||||||
|
|
||||||
let ty: AttrType = match name_str.as_str() {
|
let ty: AttrType = match name_str.as_str() {
|
||||||
// short circuit early if style is using the special syntax
|
// short circuit early if style is using the special syntax
|
||||||
"style" if stream.peek(token::Brace) => {
|
"style" if stream.peek(Token![:]) => {
|
||||||
|
stream.parse::<Token![:]>().unwrap();
|
||||||
let inner;
|
let inner;
|
||||||
syn::braced!(inner in stream);
|
syn::braced!(inner in stream);
|
||||||
|
|
||||||
@@ -267,7 +337,7 @@ fn parse_element_body(
|
|||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
impl ToTokens for ElementAttr {
|
impl<const AS: HTML_OR_RSX> ToTokens for ElementAttr<AS> {
|
||||||
fn to_tokens(&self, tokens: &mut TokenStream2) {
|
fn to_tokens(&self, tokens: &mut TokenStream2) {
|
||||||
let el_name = &self.element_name;
|
let el_name = &self.element_name;
|
||||||
let name_str = self.name.to_string();
|
let name_str = self.name.to_string();
|
||||||
|
|||||||
Reference in new issue
Block a user