From f0f82bf1f9be43b11e355b17f25d276220a600ec Mon Sep 17 00:00:00 2001 From: cel 🌸 Date: Tue, 25 Feb 2025 18:32:58 +0000 Subject: cleanup --- src/xml/parsers_complete.rs | 161 ++++++++++++++++++++++---------------------- 1 file changed, 79 insertions(+), 82 deletions(-) (limited to 'src/xml/parsers_complete.rs') diff --git a/src/xml/parsers_complete.rs b/src/xml/parsers_complete.rs index 900a3dd..cdc4fed 100644 --- a/src/xml/parsers_complete.rs +++ b/src/xml/parsers_complete.rs @@ -29,7 +29,7 @@ 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>; fn parse_full(input: &'s str) -> crate::Result { match ::parse(input) { @@ -49,7 +49,7 @@ pub trait Parser<'s> { 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) @@ -63,7 +63,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) @@ -84,8 +84,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 { @@ -98,7 +98,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) @@ -114,7 +114,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 }, @@ -126,7 +126,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) } } @@ -135,7 +135,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) } } @@ -144,7 +144,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) } } @@ -155,7 +155,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) } } @@ -220,7 +220,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), @@ -233,7 +233,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()), @@ -245,7 +245,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) @@ -256,7 +256,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, @@ -272,7 +272,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( @@ -321,7 +321,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( @@ -357,7 +357,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('"')), @@ -375,7 +375,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('"')), @@ -411,7 +411,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("<&"), @@ -426,7 +426,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("