aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLibravatar cel 🌸 <cel@bunny.garden>2024-11-01 13:37:33 +0000
committerLibravatar cel 🌸 <cel@bunny.garden>2024-11-01 13:37:33 +0000
commitc6c3c1b403ecc70b759b1e1d371f414c63211e82 (patch)
tree174e6e748f8a0f12feab7a27050a80ce05c2ba85
parentceb1bca7a4f1ccf9bfc6a050adc4387e992c9403 (diff)
downloadpeanuts-c6c3c1b403ecc70b759b1e1d371f414c63211e82.tar.gz
peanuts-c6c3c1b403ecc70b759b1e1d371f414c63211e82.tar.bz2
peanuts-c6c3c1b403ecc70b759b1e1d371f414c63211e82.zip
change contents of Names and Nmtokens to Vecs
-rw-r--r--src/xml/mod.rs7
-rw-r--r--src/xml/parsers.rs12
2 files changed, 9 insertions, 10 deletions
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<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> {
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)
}
}