Skip to content

Commit

Permalink
Allow many ':' in attributes
Browse files Browse the repository at this point in the history
To do this, "try_namespace_name" now looks for nested namespaces.
Because 'try_name' gets called, another Ident must be consumed to
prevent and early return, which means that "::" would not be valid,
but "a:b-c:d" would be fine.
  • Loading branch information
RedPhoenixQ committed Oct 10, 2023
1 parent d1cfde5 commit f2b6795
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
10 changes: 10 additions & 0 deletions maud/tests/basic_syntax.rs
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,16 @@ fn hyphens_in_attribute_names() {
);
}

#[test]
fn many_colons_in_names() {
let result =
html! { namespace:other-namespace:this is:some:sentence="false" of:course:it:is {} };
assert_eq!(
result.into_string(),
r#"<namespace:other-namespace:this is:some:sentence="false" of:course:it:is></namespace:other-namespace:this>"#
);
}

#[test]
fn class_shorthand() {
let result = html! { p { "Hi, " span.name { "Lyra" } "!" } };
Expand Down
4 changes: 3 additions & 1 deletion maud_macros/src/parse.rs
Original file line number Diff line number Diff line change
Expand Up @@ -731,11 +731,13 @@ impl Parser {
/// if necessary.
fn try_namespaced_name(&mut self) -> Option<TokenStream> {
let mut result = vec![self.try_name()?];
if let Some(TokenTree::Punct(ref punct)) = self.peek() {
while let Some(TokenTree::Punct(ref punct)) = self.peek() {
if punct.as_char() == ':' {
self.advance();
result.push(TokenStream::from(TokenTree::Punct(punct.clone())));
result.push(self.try_name()?);
} else {
break;
}
}
Some(result.into_iter().collect())
Expand Down

0 comments on commit f2b6795

Please sign in to comment.