From 7e3099c915c42ffadb5c6fa1f2813174fe01eb72 Mon Sep 17 00:00:00 2001 From: Dirkjan Ochtman Date: Mon, 1 Apr 2024 13:26:12 +0200 Subject: [PATCH] Enable namespace prefixes containing dashes --- instant-xml-macros/src/meta.rs | 22 ++++++++++++++++------ 1 file changed, 16 insertions(+), 6 deletions(-) diff --git a/instant-xml-macros/src/meta.rs b/instant-xml-macros/src/meta.rs index 8b258a3..ceb48d1 100644 --- a/instant-xml-macros/src/meta.rs +++ b/instant-xml-macros/src/meta.rs @@ -1,7 +1,7 @@ use std::collections::BTreeMap; use std::fmt; -use proc_macro2::{Delimiter, Group, Ident, Literal, Punct, Span, TokenStream, TokenTree}; +use proc_macro2::{Delimiter, Group, Literal, Punct, Span, TokenStream, TokenTree}; use quote::ToTokens; use syn::punctuated::Punctuated; @@ -128,10 +128,20 @@ impl NamespaceMeta { } NsState::PrefixValue { - prefix: segment.ident, + prefix: segment.ident.to_string(), } } - (NsState::Prefix, TokenTree::Ident(id)) => NsState::Eq { prefix: id }, + (NsState::Prefix, TokenTree::Ident(id)) => NsState::Eq { + prefix: id.to_string(), + }, + (NsState::Eq { mut prefix }, TokenTree::Punct(punct)) if punct.as_char() == '-' => { + prefix.push(punct.as_char()); + NsState::Eq { prefix } + } + (NsState::Eq { mut prefix }, TokenTree::Ident(id)) => { + prefix.push_str(&id.to_string()); + NsState::Eq { prefix } + } (NsState::Eq { prefix }, TokenTree::Punct(punct)) if punct.as_char() == '=' => { NsState::PrefixValue { prefix } } @@ -405,13 +415,13 @@ enum NsState { }, Prefix, Eq { - prefix: Ident, + prefix: String, }, PrefixValue { - prefix: Ident, + prefix: String, }, PrefixPath { - prefix: Ident, + prefix: String, colon1: Option, colon2: Option, path: Option,