xso-proc: add support for namespaced attributes

This commit is contained in:
Jonas Schäfer 2024-06-24 07:28:04 +02:00
commit 84de7fc248
4 changed files with 98 additions and 10 deletions

View file

@ -204,6 +204,9 @@ pub(crate) enum XmlFieldMeta {
/// This is useful for error messages.
span: Span,
/// The XML namespace supplied.
namespace: Option<NamespaceRef>,
/// The XML name supplied.
name: Option<NameRef>,
},
@ -222,10 +225,12 @@ impl XmlFieldMeta {
Ok(Self::Attribute {
span: meta.path.span(),
name: Some(meta.value()?.parse()?),
namespace: None,
})
} else if meta.input.peek(syn::token::Paren) {
// full syntax
let mut name: Option<NameRef> = None;
let mut namespace: Option<NamespaceRef> = None;
meta.parse_nested_meta(|meta| {
if meta.path.is_ident("name") {
if name.is_some() {
@ -233,6 +238,12 @@ impl XmlFieldMeta {
}
name = Some(meta.value()?.parse()?);
Ok(())
} else if meta.path.is_ident("namespace") {
if namespace.is_some() {
return Err(Error::new_spanned(meta.path, "duplicate `namespace` key"));
}
namespace = Some(meta.value()?.parse()?);
Ok(())
} else {
Err(Error::new_spanned(meta.path, "unsupported key"))
}
@ -240,12 +251,14 @@ impl XmlFieldMeta {
Ok(Self::Attribute {
span: meta.path.span(),
name,
namespace,
})
} else {
// argument-less syntax
Ok(Self::Attribute {
span: meta.path.span(),
name: None,
namespace: None,
})
}
}