change contents of Names and Nmtokens to Vecs

This commit is contained in:
cel 🌸 2024-11-01 13:37:33 +00:00
parent ceb1bca7a4
commit c6c3c1b403
2 changed files with 9 additions and 10 deletions

View File

@ -1,5 +1,6 @@
use std::char;
pub mod composers;
pub mod parsers;
/// [1] NSAttName ::= PrefixedAttName | DefaultAttName
@ -75,8 +76,7 @@ pub struct Name<'s>(&'s str);
/// [6] Names ::= Name (#x20 Name)*
#[repr(transparent)]
// TODO: turn into vec
pub struct Names<'s>(&'s str);
pub struct Names<'s>(Vec<Name<'s>>);
/// [7] Nmtoken ::= (NameChar)+
#[derive(Debug, Clone)]
@ -85,8 +85,7 @@ pub struct Nmtoken<'s>(&'s str);
/// [8] Nmtokens ::= Nmtoken (#x20 Nmtoken)*
#[repr(transparent)]
// TODO: turn into vec
pub struct Nmtokens<'s>(&'s str);
pub struct Nmtokens<'s>(Vec<Nmtoken<'s>>);
#[derive(Clone, Debug)]
pub enum LiteralData<'s> {

View File

@ -189,8 +189,8 @@ impl<'s> Parser<'s, Names<'s>> for Names<'s> {
// TODO: fix
fn parse(input: &'s str) -> IResult<&str, Names<'s>> {
map(
recognize(pair(Name::parse, many0(pair(char('\u{20}'), Name::parse)))),
|names| Names(names),
pair(Name::parse, many0(preceded(char('\u{20}'), Name::parse))),
|(head, tail)| Names(vec![vec![head], tail].concat()),
)(input)
}
}
@ -208,11 +208,11 @@ impl<'s> Parser<'s, Nmtoken<'s>> for Nmtoken<'s> {
impl<'s> Parser<'s, Nmtokens<'s>> for Nmtokens<'s> {
fn parse(input: &'s str) -> IResult<&str, Nmtokens<'s>> {
map(
recognize(pair(
pair(
Nmtoken::parse,
many0(pair(char('\u{20}'), Nmtoken::parse)),
)),
|nmtokens| Nmtokens(nmtokens),
many0(preceded(char('\u{20}'), Nmtoken::parse)),
),
|(head, tail)| Nmtokens(vec![vec![head], tail].concat()),
)(input)
}
}