diff --git a/src/xml/mod.rs b/src/xml/mod.rs index d1b9ddf..d22abd6 100644 --- a/src/xml/mod.rs +++ b/src/xml/mod.rs @@ -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>); /// [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>); #[derive(Clone, Debug)] pub enum LiteralData<'s> { diff --git a/src/xml/parsers.rs b/src/xml/parsers.rs index b8b8018..6326593 100644 --- a/src/xml/parsers.rs +++ b/src/xml/parsers.rs @@ -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) } }