From f0f82bf1f9be43b11e355b17f25d276220a600ec Mon Sep 17 00:00:00 2001 From: cel 🌸 Date: Tue, 25 Feb 2025 18:32:58 +0000 Subject: cleanup --- src/xml/composers.rs | 5 +- src/xml/mod.rs | 2 +- src/xml/parsers.rs | 158 +++++++++++++++++++++---------------------- src/xml/parsers_complete.rs | 161 ++++++++++++++++++++++---------------------- 4 files changed, 162 insertions(+), 164 deletions(-) (limited to 'src/xml') diff --git a/src/xml/composers.rs b/src/xml/composers.rs index b8fbe13..8299708 100644 --- a/src/xml/composers.rs +++ b/src/xml/composers.rs @@ -19,7 +19,7 @@ use super::{ /// Compact Composer trait, can create different trait later for pretty composition pub trait Composer<'s> { - async fn write(&self, writer: &mut W) -> io::Result<()> + fn write(&self, writer: &mut W) -> impl std::future::Future> where W: Unpin + AsyncWrite; } @@ -817,7 +817,8 @@ impl<'s> Composer<'s> for Content<'s> { ContentItem::CDSect(cd_sect) => cd_sect.write(writer).await?, ContentItem::PI(pi) => pi.write(writer).await?, ContentItem::Comment(comment) => comment.write(writer).await?, - _ => todo!("verify no split chardata"), + // TODO: verify no split chardata + // _ => todo!("verify no split chardata"), } if let Some(char_data) = char_data { char_data.write(writer).await?; diff --git a/src/xml/mod.rs b/src/xml/mod.rs index 3982070..3f7dc79 100644 --- a/src/xml/mod.rs +++ b/src/xml/mod.rs @@ -1,4 +1,4 @@ -use std::{char, convert::Infallible, ops::Deref, str::FromStr}; +use std::{char, ops::Deref}; use parsers_complete::Parser; diff --git a/src/xml/parsers.rs b/src/xml/parsers.rs index 773302f..87858a1 100644 --- a/src/xml/parsers.rs +++ b/src/xml/parsers.rs @@ -32,14 +32,14 @@ use super::{ pub trait Parser<'s> { type Output; - fn parse(input: &'s str) -> IResult<&str, Self::Output>; + fn parse(input: &'s str) -> IResult<&'s str, Self::Output>; } /// [1] NSAttName ::= PrefixedAttName | DefaultAttName impl<'s> Parser<'s> for NSAttName<'s> { type Output = NSAttName<'s>; - fn parse(input: &'s str) -> IResult<&str, Self::Output> { + fn parse(input: &'s str) -> IResult<&'s str, Self::Output> { alt(( map(PrefixedAttName::parse, |prefixed_att_name| { NSAttName::PrefixedAttName(prefixed_att_name) @@ -53,7 +53,7 @@ impl<'s> Parser<'s> for NSAttName<'s> { impl<'s> Parser<'s> for PrefixedAttName<'s> { type Output = PrefixedAttName<'s>; - fn parse(input: &'s str) -> IResult<&str, PrefixedAttName<'s>> { + fn parse(input: &'s str) -> IResult<&'s str, PrefixedAttName<'s>> { map(preceded(tag("xmlns:"), NCName::parse), |nc_name| { PrefixedAttName(nc_name) })(input) @@ -74,8 +74,8 @@ impl Parser<'_> for DefaultAttName { impl<'s> Parser<'s> for NCName<'s> { type Output = NCName<'s>; - fn parse(input: &'s str) -> IResult<&str, NCName<'s>> { - let (rest, name) = peek(recognize(Name::parse))(input)?; + fn parse(input: &'s str) -> IResult<&'s str, NCName<'s>> { + let (_rest, name) = peek(recognize(Name::parse))(input)?; if let Some(char) = name.find(':') { map(take(char), |nc_name| NCName(nc_name))(input) } else { @@ -88,7 +88,7 @@ impl<'s> Parser<'s> for NCName<'s> { impl<'s> Parser<'s> for QName<'s> { type Output = QName<'s>; - fn parse(input: &'s str) -> IResult<&str, QName<'s>> { + fn parse(input: &'s str) -> IResult<&'s str, QName<'s>> { alt(( map(PrefixedName::parse, |prefixed_name| { QName::PrefixedName(prefixed_name) @@ -104,7 +104,7 @@ impl<'s> Parser<'s> for QName<'s> { impl<'s> Parser<'s> for PrefixedName<'s> { type Output = PrefixedName<'s>; - fn parse(input: &'s str) -> IResult<&str, PrefixedName<'s>> { + fn parse(input: &'s str) -> IResult<&'s str, PrefixedName<'s>> { map( separated_pair(Prefix::parse, char(':'), LocalPart::parse), |(prefix, local_part)| PrefixedName { prefix, local_part }, @@ -116,7 +116,7 @@ impl<'s> Parser<'s> for PrefixedName<'s> { impl<'s> Parser<'s> for UnprefixedName<'s> { type Output = UnprefixedName<'s>; - fn parse(input: &'s str) -> IResult<&str, UnprefixedName<'s>> { + fn parse(input: &'s str) -> IResult<&'s str, UnprefixedName<'s>> { map(LocalPart::parse, |local_part| UnprefixedName(local_part))(input) } } @@ -125,7 +125,7 @@ impl<'s> Parser<'s> for UnprefixedName<'s> { impl<'s> Parser<'s> for Prefix<'s> { type Output = Prefix<'s>; - fn parse(input: &'s str) -> IResult<&str, Prefix<'s>> { + fn parse(input: &'s str) -> IResult<&'s str, Prefix<'s>> { map(NCName::parse, |nc_name| Prefix(nc_name))(input) } } @@ -134,7 +134,7 @@ impl<'s> Parser<'s> for Prefix<'s> { impl<'s> Parser<'s> for LocalPart<'s> { type Output = LocalPart<'s>; - fn parse(input: &'s str) -> IResult<&str, LocalPart<'s>> { + fn parse(input: &'s str) -> IResult<&'s str, LocalPart<'s>> { map(NCName::parse, |nc_name| LocalPart(nc_name))(input) } } @@ -145,7 +145,7 @@ impl<'s> Parser<'s> for LocalPart<'s> { impl<'s> Parser<'s> for Document<'s> { type Output = Document<'s>; - fn parse(input: &'s str) -> IResult<&str, Document<'s>> { + fn parse(input: &'s str) -> IResult<&'s str, Document<'s>> { tuple((Prolog::parse, Element::parse, many0(Misc::parse)))(input) } } @@ -210,7 +210,7 @@ impl Parser<'_> for NameChar { impl<'s> Parser<'s> for Name<'s> { type Output = Name<'s>; - fn parse(input: &'s str) -> IResult<&str, Name<'s>> { + fn parse(input: &'s str) -> IResult<&'s str, Name<'s>> { map( recognize(pair(NameStartChar::parse, many0(NameChar::parse))), |name| Name(name), @@ -223,7 +223,7 @@ impl<'s> Parser<'s> for Names<'s> { type Output = Names<'s>; // TODO: fix - fn parse(input: &'s str) -> IResult<&str, Names<'s>> { + fn parse(input: &'s str) -> IResult<&'s str, Names<'s>> { map( pair(Name::parse, many0(preceded(char('\u{20}'), Name::parse))), |(head, tail)| Names(vec![vec![head], tail].concat()), @@ -235,7 +235,7 @@ impl<'s> Parser<'s> for Names<'s> { impl<'s> Parser<'s> for Nmtoken<'s> { type Output = Nmtoken<'s>; - fn parse(input: &'s str) -> IResult<&str, Nmtoken<'s>> { + fn parse(input: &'s str) -> IResult<&'s str, Nmtoken<'s>> { map(recognize(many1(NameChar::parse)), |nmtoken| { Nmtoken(nmtoken) })(input) @@ -246,7 +246,7 @@ impl<'s> Parser<'s> for Nmtoken<'s> { impl<'s> Parser<'s> for Nmtokens<'s> { type Output = Nmtokens<'s>; - fn parse(input: &'s str) -> IResult<&str, Nmtokens<'s>> { + fn parse(input: &'s str) -> IResult<&'s str, Nmtokens<'s>> { map( pair( Nmtoken::parse, @@ -262,7 +262,7 @@ impl<'s> Parser<'s> for Nmtokens<'s> { impl<'s> Parser<'s> for EntityValue<'s> { type Output = EntityValue<'s>; - fn parse(input: &'s str) -> IResult<&str, EntityValue<'s>> { + fn parse(input: &'s str) -> IResult<&'s str, EntityValue<'s>> { alt(( map( delimited( @@ -311,7 +311,7 @@ impl<'s> Parser<'s> for EntityValue<'s> { impl<'s> Parser<'s> for AttValue<'s> { type Output = AttValue<'s>; - fn parse(input: &'s str) -> IResult<&str, AttValue<'s>> { + fn parse(input: &'s str) -> IResult<&'s str, AttValue<'s>> { alt(( map( delimited( @@ -347,7 +347,7 @@ impl<'s> Parser<'s> for AttValue<'s> { impl<'s> Parser<'s> for SystemLiteral<'s> { type Output = SystemLiteral<'s>; - fn parse(input: &'s str) -> IResult<&str, SystemLiteral<'s>> { + fn parse(input: &'s str) -> IResult<&'s str, SystemLiteral<'s>> { alt(( map( delimited(char('"'), recognize(many0(none_of("\""))), char('"')), @@ -365,7 +365,7 @@ impl<'s> Parser<'s> for SystemLiteral<'s> { impl<'s> Parser<'s> for PubidLiteral<'s> { type Output = PubidLiteral<'s>; - fn parse(input: &'s str) -> IResult<&str, PubidLiteral<'s>> { + fn parse(input: &'s str) -> IResult<&'s str, PubidLiteral<'s>> { alt(( map( delimited(char('"'), recognize(many0(PubidChar::parse)), char('"')), @@ -401,7 +401,7 @@ impl Parser<'_> for PubidChar { impl<'s> Parser<'s> for CharData<'s> { type Output = CharData<'s>; - fn parse(input: &'s str) -> IResult<&str, CharData<'s>> { + fn parse(input: &'s str) -> IResult<&'s str, CharData<'s>> { map( recognize(many_till( none_of("<&"), @@ -416,7 +416,7 @@ impl<'s> Parser<'s> for CharData<'s> { impl<'s> Parser<'s> for Comment<'s> { type Output = Comment<'s>; - fn parse(input: &'s str) -> IResult<&str, Comment<'s>> { + fn parse(input: &'s str) -> IResult<&'s str, Comment<'s>> { map( delimited( tag("