This commit is contained in:
cel 🌸 2025-02-25 18:32:58 +00:00
parent fe389c38ca
commit f0f82bf1f9
9 changed files with 175 additions and 214 deletions

View File

@ -1,18 +1,13 @@
// elements resemble a final tree, including inherited namespace information
#![feature(drain_filter)]
/// elements resemble a final tree, including inherited namespace information
use std::{
collections::{vec_deque, HashMap, HashSet, VecDeque},
convert::Infallible,
collections::{HashMap, HashSet, VecDeque},
str::FromStr,
};
use tracing::debug;
use tracing::trace;
use crate::{
error::{DeserializeError, Error},
xml::{self, parsers_complete::Parser, Attribute},
Result,
};
@ -330,16 +325,16 @@ impl Element {
let mut children = Vec::new();
loop {
let child = self.content.front();
debug!("child: {:?}", child);
trace!("child: {:?}", child);
if let Some(child) = child {
match child {
Content::Element(element) => {
if let Ok(child) = <T as FromElement>::from_element(element.clone()) {
debug!("parsed child");
trace!("parsed child");
children.push(child);
self.content.pop_front();
} else {
debug!("failed to parse child");
trace!("failed to parse child");
return Ok(children);
}
}

View File

@ -1,12 +0,0 @@
// tags, declaration, comments, text. individual bits and what they contain, e.g. tag contains attributes and namespace declarations, lang, ONLY within the tag
pub enum Event<'s> {
StartTag(Vec<Event<'s>>),
EmptyTag(Vec<Event>),
Attribute(())
CData(&'s str),
Comment(&'s str),
Declaration(Vec<Attribute<'s>>),
Attribute((&'str))
EndTag,
}

View File

@ -1,9 +0,0 @@
// lexer: tokenizes to bits like '<', '<?', '"', etc.
pub enum Token {
Whitespace,
OpenTag,
CloseTag,
Slash,
Text(String),
}

View File

@ -1,14 +1,10 @@
use circular::Buffer;
use futures::{FutureExt, Stream};
use nom::Err;
use std::{
collections::{hash_set, BTreeMap, HashMap, HashSet, VecDeque},
future::Future,
path::Prefix,
pin::{pin, Pin},
str::{self, FromStr},
collections::{HashMap, HashSet, VecDeque},
str,
};
use tokio::io::{AsyncBufRead, AsyncBufReadExt, AsyncRead, AsyncReadExt};
use tokio::io::{AsyncRead, AsyncReadExt};
use tracing::debug;
use crate::{
@ -732,11 +728,11 @@ impl<R> Reader<R> {
char_data.map(|char_data| text.as_mut().map(|s| s.push_str(*char_data)));
}
// TODO: is this important?
xml::ContentItem::PI(pi) => {
xml::ContentItem::PI(_pi) => {
char_data.map(|char_data| text.as_mut().map(|s| s.push_str(*char_data)));
}
// TODO: comments?
xml::ContentItem::Comment(comment) => {
xml::ContentItem::Comment(_comment) => {
char_data.map(|char_data| text.as_mut().map(|s| s.push_str(*char_data)));
}
}

View File

@ -1,13 +1,6 @@
use std::{
collections::{HashSet, VecDeque},
pin::pin,
str::FromStr,
task::Poll,
};
use std::collections::HashSet;
use async_recursion::async_recursion;
use circular::Buffer;
use futures::{Future, FutureExt, Sink, SinkExt};
use tokio::io::{AsyncWrite, AsyncWriteExt};
use crate::{
@ -15,7 +8,7 @@ use crate::{
element::{escape_str, Content, Element, IntoContent, IntoElement, Name, NamespaceDeclaration},
endable::Endable,
error::Error,
xml::{self, composers::Composer, parsers_complete::Parser, ETag, XMLDecl},
xml::{self, composers::Composer, parsers_complete::Parser},
Result, XMLNS_NS, XML_NS,
};

View File

@ -19,7 +19,7 @@ use super::{
/// Compact Composer trait, can create different trait later for pretty composition
pub trait Composer<'s> {
async fn write<W>(&self, writer: &mut W) -> io::Result<()>
fn write<W>(&self, writer: &mut W) -> impl std::future::Future<Output = io::Result<()>>
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?;

View File

@ -1,4 +1,4 @@
use std::{char, convert::Infallible, ops::Deref, str::FromStr};
use std::{char, ops::Deref};
use parsers_complete::Parser;

View File

@ -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("<!--"),
@ -432,7 +432,7 @@ impl<'s> Parser<'s> for Comment<'s> {
impl<'s> Parser<'s> for PI<'s> {
type Output = PI<'s>;
fn parse(input: &'s str) -> IResult<&str, PI<'s>> {
fn parse(input: &'s str) -> IResult<&'s str, PI<'s>> {
map(
delimited(
tag("<?"),
@ -457,7 +457,7 @@ impl<'s> Parser<'s> for PI<'s> {
impl<'s> Parser<'s> for PITarget<'s> {
type Output = PITarget<'s>;
fn parse(input: &'s str) -> IResult<&str, PITarget<'s>> {
fn parse(input: &'s str) -> IResult<&'s str, PITarget<'s>> {
let (rest, name) = Name::parse(input)?;
if name.0.to_lowercase() == "xml" {
return Err(Err::Error(Error {
@ -475,7 +475,7 @@ impl<'s> Parser<'s> for PITarget<'s> {
impl<'s> Parser<'s> for CDSect<'s> {
type Output = CDSect<'s>;
fn parse(input: &'s str) -> IResult<&str, CDSect<'s>> {
fn parse(input: &'s str) -> IResult<&'s str, CDSect<'s>> {
map(
delimited(CDStart::parse, CData::parse, CDEnd::parse),
|c_data| CDSect(c_data),
@ -496,7 +496,7 @@ impl Parser<'_> for CDStart {
impl<'s> Parser<'s> for CData<'s> {
type Output = CData<'s>;
fn parse(input: &'s str) -> IResult<&str, CData<'s>> {
fn parse(input: &'s str) -> IResult<&'s str, CData<'s>> {
map(
recognize(many_till(Char::parse, peek(tag("]]>")))),
|c_data| CData(c_data),
@ -517,7 +517,7 @@ impl Parser<'_> for CDEnd {
impl<'s> Parser<'s> for Prolog<'s> {
type Output = Prolog<'s>;
fn parse(input: &'s str) -> IResult<&str, Prolog<'s>> {
fn parse(input: &'s str) -> IResult<&'s str, Prolog<'s>> {
tuple((
opt(XMLDecl::parse),
many0(Misc::parse),
@ -530,7 +530,7 @@ impl<'s> Parser<'s> for Prolog<'s> {
impl<'s> Parser<'s> for XMLDecl<'s> {
type Output = XMLDecl<'s>;
fn parse(input: &'s str) -> IResult<&str, XMLDecl<'s>> {
fn parse(input: &'s str) -> IResult<&'s str, XMLDecl<'s>> {
map(
delimited(
tag("<?xml"),
@ -602,7 +602,7 @@ impl Parser<'_> for VersionNum {
impl<'s> Parser<'s> for Misc<'s> {
type Output = Misc<'s>;
fn parse(input: &'s str) -> IResult<&str, Misc<'s>> {
fn parse(input: &'s str) -> IResult<&'s str, Misc<'s>> {
alt((
map(Comment::parse, |comment| Misc::Comment(comment)),
map(PI::parse, |pi| Misc::PI(pi)),
@ -616,7 +616,7 @@ impl<'s> Parser<'s> for Misc<'s> {
impl<'s> Parser<'s> for DoctypeDecl<'s> {
type Output = DoctypeDecl<'s>;
fn parse(input: &'s str) -> IResult<&str, DoctypeDecl<'s>> {
fn parse(input: &'s str) -> IResult<&'s str, DoctypeDecl<'s>> {
map(
delimited(
pair(tag("<!DOCTYPE"), S::parse),
@ -646,7 +646,7 @@ impl<'s> Parser<'s> for DoctypeDecl<'s> {
impl<'s> Parser<'s> for DeclSep<'s> {
type Output = DeclSep<'s>;
fn parse(input: &'s str) -> IResult<&str, DeclSep<'s>> {
fn parse(input: &'s str) -> IResult<&'s str, DeclSep<'s>> {
alt((
map(PEReference::parse, |pe_reference| {
DeclSep::PEReference(pe_reference)
@ -660,7 +660,7 @@ impl<'s> Parser<'s> for DeclSep<'s> {
impl<'s> Parser<'s> for IntSubset<'s> {
type Output = IntSubset<'s>;
fn parse(input: &'s str) -> IResult<&str, IntSubset<'s>> {
fn parse(input: &'s str) -> IResult<&'s str, IntSubset<'s>> {
many0(alt((
map(MarkupDecl::parse, |markup_decl| {
IntSubsetDeclaration::MarkupDecl(markup_decl)
@ -676,7 +676,7 @@ impl<'s> Parser<'s> for IntSubset<'s> {
impl<'s> Parser<'s> for MarkupDecl<'s> {
type Output = MarkupDecl<'s>;
fn parse(input: &'s str) -> IResult<&str, MarkupDecl<'s>> {
fn parse(input: &'s str) -> IResult<&'s str, MarkupDecl<'s>> {
alt((
map(Elementdecl::parse, |elementdecl| {
MarkupDecl::Elementdecl(elementdecl)
@ -700,7 +700,7 @@ impl<'s> Parser<'s> for MarkupDecl<'s> {
impl<'s> Parser<'s> for ExtSubset<'s> {
type Output = ExtSubset<'s>;
fn parse(input: &'s str) -> IResult<&str, ExtSubset<'s>> {
fn parse(input: &'s str) -> IResult<&'s str, ExtSubset<'s>> {
map(
pair(opt(TextDecl::parse), ExtSubsetDecl::parse),
|(text_decl, ext_subset_decl)| ExtSubset {
@ -715,7 +715,7 @@ impl<'s> Parser<'s> for ExtSubset<'s> {
impl<'s> Parser<'s> for ExtSubsetDecl<'s> {
type Output = ExtSubsetDecl<'s>;
fn parse(input: &'s str) -> IResult<&str, ExtSubsetDecl<'s>> {
fn parse(input: &'s str) -> IResult<&'s str, ExtSubsetDecl<'s>> {
many0(alt((
map(MarkupDecl::parse, |markup_decl| {
ExtSubsetDeclaration::MarkupDecl(markup_decl)
@ -765,7 +765,7 @@ impl Parser<'_> for SDDecl {
impl<'s> Parser<'s> for Element<'s> {
type Output = Element<'s>;
fn parse(input: &'s str) -> IResult<&str, Element<'s>> {
fn parse(input: &'s str) -> IResult<&'s str, Element<'s>> {
alt((
map(EmptyElemTag::parse, |empty_elem_tag| {
Element::Empty(empty_elem_tag)
@ -783,7 +783,7 @@ impl<'s> Parser<'s> for Element<'s> {
impl<'s> Parser<'s> for STag<'s> {
type Output = STag<'s>;
fn parse(input: &'s str) -> IResult<&str, STag<'s>> {
fn parse(input: &'s str) -> IResult<&'s str, STag<'s>> {
map(
delimited(
tag("<"),
@ -799,7 +799,7 @@ impl<'s> Parser<'s> for STag<'s> {
impl<'s> Parser<'s> for Attribute<'s> {
type Output = Attribute<'s>;
fn parse(input: &'s str) -> IResult<&str, Attribute<'s>> {
fn parse(input: &'s str) -> IResult<&'s str, Attribute<'s>> {
alt((
map(
separated_pair(NSAttName::parse, Eq::parse, AttValue::parse),
@ -814,7 +814,7 @@ impl<'s> Parser<'s> for Attribute<'s> {
}
// pub type Attribute<'s> = (Name<'s>, AttValue<'s>);
/// [41] Attribute ::= Name Eq AttValue
// pub fn attribute(input: &str) -> IResult<&str, Attribute> {
// pub fn attribute(input: &str) -> IResult<&'s str, Attribute> {
// separated_pair(name, eq, att_value)(input)
// }
@ -823,7 +823,7 @@ impl<'s> Parser<'s> for Attribute<'s> {
impl<'s> Parser<'s> for ETag<'s> {
type Output = ETag<'s>;
fn parse(input: &'s str) -> IResult<&str, ETag<'s>> {
fn parse(input: &'s str) -> IResult<&'s str, ETag<'s>> {
map(
delimited(tag("</"), QName::parse, pair(opt(S::parse), tag(">"))),
|name| ETag { name },
@ -834,7 +834,7 @@ impl<'s> Parser<'s> for ETag<'s> {
impl<'s> Parser<'s> for ContentItem<'s> {
type Output = ContentItem<'s>;
fn parse(input: &'s str) -> IResult<&str, ContentItem<'s>> {
fn parse(input: &'s str) -> IResult<&'s str, ContentItem<'s>> {
alt((
map(Element::parse, |element| ContentItem::Element(element)),
map(Reference::parse, |reference| {
@ -851,7 +851,7 @@ impl<'s> Parser<'s> for ContentItem<'s> {
impl<'s> Parser<'s> for Content<'s> {
type Output = Content<'s>;
fn parse(input: &'s str) -> IResult<&str, Content<'s>> {
fn parse(input: &'s str) -> IResult<&'s str, Content<'s>> {
map(
pair(
opt(CharData::parse),
@ -878,7 +878,7 @@ impl<'s> Parser<'s> for Content<'s> {
impl<'s> Parser<'s> for EmptyElemTag<'s> {
type Output = EmptyElemTag<'s>;
fn parse(input: &'s str) -> IResult<&str, EmptyElemTag<'s>> {
fn parse(input: &'s str) -> IResult<&'s str, EmptyElemTag<'s>> {
map(
delimited(
tag("<"),
@ -895,7 +895,7 @@ impl<'s> Parser<'s> for EmptyElemTag<'s> {
impl<'s> Parser<'s> for Elementdecl<'s> {
type Output = Elementdecl<'s>;
fn parse(input: &'s str) -> IResult<&str, Elementdecl> {
fn parse(input: &'s str) -> IResult<&'s str, Elementdecl<'s>> {
map(
delimited(
pair(tag("<!ELEMENT"), S::parse),
@ -911,7 +911,7 @@ impl<'s> Parser<'s> for Elementdecl<'s> {
impl<'s> Parser<'s> for Contentspec<'s> {
type Output = Contentspec<'s>;
fn parse(input: &'s str) -> IResult<&str, Contentspec<'s>> {
fn parse(input: &'s str) -> IResult<&'s str, Contentspec<'s>> {
alt((
value(Contentspec::Empty, tag("EMPTY")),
value(Contentspec::Any, tag("ANY")),
@ -942,7 +942,7 @@ impl Parser<'_> for Occurence {
impl<'s> Parser<'s> for Children<'s> {
type Output = Children<'s>;
fn parse(input: &'s str) -> IResult<&str, Children<'s>> {
fn parse(input: &'s str) -> IResult<&'s str, Children<'s>> {
map(
pair(
alt((
@ -961,7 +961,7 @@ impl<'s> Parser<'s> for Children<'s> {
impl<'s> Parser<'s> for Cp<'s> {
type Output = Cp<'s>;
fn parse(input: &'s str) -> IResult<&str, Cp<'s>> {
fn parse(input: &'s str) -> IResult<&'s str, Cp<'s>> {
map(
pair(
alt((
@ -980,7 +980,7 @@ impl<'s> Parser<'s> for Cp<'s> {
impl<'s> Parser<'s> for Choice<'s> {
type Output = Choice<'s>;
fn parse(input: &'s str) -> IResult<&str, Choice<'s>> {
fn parse(input: &'s str) -> IResult<&'s str, Choice<'s>> {
map(
delimited(
pair(tag("("), opt(S::parse)),
@ -1005,7 +1005,7 @@ impl<'s> Parser<'s> for Choice<'s> {
impl<'s> Parser<'s> for Seq<'s> {
type Output = Seq<'s>;
fn parse(input: &'s str) -> IResult<&str, Seq<'s>> {
fn parse(input: &'s str) -> IResult<&'s str, Seq<'s>> {
map(
delimited(
pair(tag("("), opt(S::parse)),
@ -1031,7 +1031,7 @@ impl<'s> Parser<'s> for Seq<'s> {
impl<'s> Parser<'s> for Mixed<'s> {
type Output = Mixed<'s>;
fn parse(input: &'s str) -> IResult<&str, Mixed<'s>> {
fn parse(input: &'s str) -> IResult<&'s str, Mixed<'s>> {
alt((
map(
delimited(
@ -1063,7 +1063,7 @@ impl<'s> Parser<'s> for Mixed<'s> {
impl<'s> Parser<'s> for AttlistDecl<'s> {
type Output = AttlistDecl<'s>;
fn parse(input: &'s str) -> IResult<&str, AttlistDecl<'s>> {
fn parse(input: &'s str) -> IResult<&'s str, AttlistDecl<'s>> {
map(
delimited(
pair(tag("<!ATTLIST"), S::parse),
@ -1083,7 +1083,7 @@ impl<'s> Parser<'s> for AttlistDecl<'s> {
impl<'s> Parser<'s> for AttDef<'s> {
type Output = AttDef<'s>;
fn parse(input: &'s str) -> IResult<&str, AttDef<'s>> {
fn parse(input: &'s str) -> IResult<&'s str, AttDef<'s>> {
map(
tuple((
preceded(
@ -1111,7 +1111,7 @@ impl<'s> Parser<'s> for AttDef<'s> {
impl<'s> Parser<'s> for AttType<'s> {
type Output = AttType<'s>;
fn parse(input: &'s str) -> IResult<&str, AttType<'s>> {
fn parse(input: &'s str) -> IResult<&'s str, AttType<'s>> {
alt((
value(AttType::StringType, StringType::parse),
map(TokenizedType::parse, |tokenized_type| {
@ -1157,7 +1157,7 @@ impl Parser<'_> for TokenizedType {
impl<'s> Parser<'s> for EnumeratedType<'s> {
type Output = EnumeratedType<'s>;
fn parse(input: &'s str) -> IResult<&str, EnumeratedType<'s>> {
fn parse(input: &'s str) -> IResult<&'s str, EnumeratedType<'s>> {
alt((
map(NotationType::parse, |notation_type| {
EnumeratedType::NotationType(notation_type)
@ -1173,7 +1173,7 @@ impl<'s> Parser<'s> for EnumeratedType<'s> {
impl<'s> Parser<'s> for NotationType<'s> {
type Output = NotationType<'s>;
fn parse(input: &'s str) -> IResult<&str, NotationType<'s>> {
fn parse(input: &'s str) -> IResult<&'s str, NotationType<'s>> {
map(
delimited(
tuple((tag("NOTATION"), S::parse, tag("("), opt(S::parse))),
@ -1198,7 +1198,7 @@ impl<'s> Parser<'s> for NotationType<'s> {
impl<'s> Parser<'s> for Enumeration<'s> {
type Output = Enumeration<'s>;
fn parse(input: &'s str) -> IResult<&str, Enumeration<'s>> {
fn parse(input: &'s str) -> IResult<&'s str, Enumeration<'s>> {
map(
delimited(
pair(tag("("), opt(S::parse)),
@ -1223,7 +1223,7 @@ impl<'s> Parser<'s> for Enumeration<'s> {
impl<'s> Parser<'s> for DefaultDecl<'s> {
type Output = DefaultDecl<'s>;
fn parse(input: &'s str) -> IResult<&str, DefaultDecl<'s>> {
fn parse(input: &'s str) -> IResult<&'s str, DefaultDecl<'s>> {
alt((
value(DefaultDecl::Required, tag("#REQUIRED")),
value(DefaultDecl::Implied, tag("#IMPLIED")),
@ -1239,7 +1239,7 @@ impl<'s> Parser<'s> for DefaultDecl<'s> {
impl<'s> Parser<'s> for ConditionalSect<'s> {
type Output = ConditionalSect<'s>;
fn parse(input: &'s str) -> IResult<&str, ConditionalSect<'s>> {
fn parse(input: &'s str) -> IResult<&'s str, ConditionalSect<'s>> {
alt((
map(IncludeSect::parse, |include_sect| {
ConditionalSect::IncludeSect(include_sect)
@ -1255,7 +1255,7 @@ impl<'s> Parser<'s> for ConditionalSect<'s> {
impl<'s> Parser<'s> for IncludeSect<'s> {
type Output = IncludeSect<'s>;
fn parse(input: &'s str) -> IResult<&str, IncludeSect<'s>> {
fn parse(input: &'s str) -> IResult<&'s str, IncludeSect<'s>> {
map(
delimited(
tuple((
@ -1277,7 +1277,7 @@ impl<'s> Parser<'s> for IncludeSect<'s> {
impl<'s> Parser<'s> for IgnoreSect<'s> {
type Output = IgnoreSect<'s>;
fn parse(input: &'s str) -> IResult<&str, IgnoreSect<'s>> {
fn parse(input: &'s str) -> IResult<&'s str, IgnoreSect<'s>> {
map(
delimited(
tuple((
@ -1299,7 +1299,7 @@ impl<'s> Parser<'s> for IgnoreSect<'s> {
impl<'s> Parser<'s> for IgnoreSectContents<'s> {
type Output = IgnoreSectContents<'s>;
fn parse(input: &'s str) -> IResult<&str, IgnoreSectContents<'s>> {
fn parse(input: &'s str) -> IResult<&'s str, IgnoreSectContents<'s>> {
map(
pair(
Ignore::parse,
@ -1320,7 +1320,7 @@ impl<'s> Parser<'s> for IgnoreSectContents<'s> {
impl<'s> Parser<'s> for Ignore<'s> {
type Output = Ignore<'s>;
fn parse(input: &'s str) -> IResult<&str, Ignore<'s>> {
fn parse(input: &'s str) -> IResult<&'s str, Ignore<'s>> {
map(
recognize(many_till(Char::parse, peek(alt((tag("<!["), tag("]]>")))))),
|ignore| Ignore(ignore),
@ -1332,7 +1332,7 @@ impl<'s> Parser<'s> for Ignore<'s> {
impl<'s> Parser<'s> for CharRef<'s> {
type Output = CharRef<'s>;
fn parse(input: &'s str) -> IResult<&str, CharRef<'s>> {
fn parse(input: &'s str) -> IResult<&'s str, CharRef<'s>> {
alt((
delimited(
tag("&#"),
@ -1357,7 +1357,7 @@ impl<'s> Parser<'s> for CharRef<'s> {
impl<'s> Parser<'s> for Reference<'s> {
type Output = Reference<'s>;
fn parse(input: &'s str) -> IResult<&str, Reference<'s>> {
fn parse(input: &'s str) -> IResult<&'s str, Reference<'s>> {
alt((
map(EntityRef::parse, |entity_ref| {
Reference::EntityRef(entity_ref)
@ -1371,7 +1371,7 @@ impl<'s> Parser<'s> for Reference<'s> {
impl<'s> Parser<'s> for EntityRef<'s> {
type Output = EntityRef<'s>;
fn parse(input: &'s str) -> IResult<&str, EntityRef<'s>> {
fn parse(input: &'s str) -> IResult<&'s str, EntityRef<'s>> {
map(delimited(tag("&"), Name::parse, tag(";")), |entity_ref| {
EntityRef(entity_ref)
})(input)
@ -1382,7 +1382,7 @@ impl<'s> Parser<'s> for EntityRef<'s> {
impl<'s> Parser<'s> for PEReference<'s> {
type Output = PEReference<'s>;
fn parse(input: &'s str) -> IResult<&str, PEReference<'s>> {
fn parse(input: &'s str) -> IResult<&'s str, PEReference<'s>> {
map(delimited(tag("%"), Name::parse, tag(";")), |pe_reference| {
PEReference(pe_reference)
})(input)
@ -1393,7 +1393,7 @@ impl<'s> Parser<'s> for PEReference<'s> {
impl<'s> Parser<'s> for EntityDecl<'s> {
type Output = EntityDecl<'s>;
fn parse(input: &'s str) -> IResult<&str, EntityDecl<'s>> {
fn parse(input: &'s str) -> IResult<&'s str, EntityDecl<'s>> {
alt((
map(GEDecl::parse, |ge_decl| EntityDecl::GEDecl(ge_decl)),
map(PEDecl::parse, |pe_decl| EntityDecl::PEDecl(pe_decl)),
@ -1405,7 +1405,7 @@ impl<'s> Parser<'s> for EntityDecl<'s> {
impl<'s> Parser<'s> for GEDecl<'s> {
type Output = GEDecl<'s>;
fn parse(input: &'s str) -> IResult<&str, GEDecl<'s>> {
fn parse(input: &'s str) -> IResult<&'s str, GEDecl<'s>> {
map(
delimited(
pair(tag("<!ENTITY"), S::parse),
@ -1421,7 +1421,7 @@ impl<'s> Parser<'s> for GEDecl<'s> {
impl<'s> Parser<'s> for PEDecl<'s> {
type Output = PEDecl<'s>;
fn parse(input: &'s str) -> IResult<&str, PEDecl<'s>> {
fn parse(input: &'s str) -> IResult<&'s str, PEDecl<'s>> {
map(
delimited(
tuple((tag("<!ENTITY"), S::parse, tag("%"), S::parse)),
@ -1437,7 +1437,7 @@ impl<'s> Parser<'s> for PEDecl<'s> {
impl<'s> Parser<'s> for EntityDef<'s> {
type Output = EntityDef<'s>;
fn parse(input: &'s str) -> IResult<&str, EntityDef<'s>> {
fn parse(input: &'s str) -> IResult<&'s str, EntityDef<'s>> {
alt((
map(EntityValue::parse, |entity_value| {
EntityDef::EntityValue(entity_value)
@ -1457,7 +1457,7 @@ impl<'s> Parser<'s> for EntityDef<'s> {
impl<'s> Parser<'s> for PEDef<'s> {
type Output = PEDef<'s>;
fn parse(input: &'s str) -> IResult<&str, PEDef<'s>> {
fn parse(input: &'s str) -> IResult<&'s str, PEDef<'s>> {
alt((
map(EntityValue::parse, |entity_value| {
PEDef::EntityValue(entity_value)
@ -1470,11 +1470,11 @@ impl<'s> Parser<'s> for PEDef<'s> {
}
/// [75] ExternalID ::= 'SYSTEM' S SystemLiteral | 'PUBLIC' S PubidLiteral S SystemLiteral
// pub fn external_id(input: &str) -> IResult<&str, ExternalID> {
// pub fn external_id(input: &str) -> IResult<&'s str, ExternalID> {
impl<'s> Parser<'s> for ExternalID<'s> {
type Output = ExternalID<'s>;
fn parse(input: &'s str) -> IResult<&str, ExternalID<'s>> {
fn parse(input: &'s str) -> IResult<&'s str, ExternalID<'s>> {
alt((
map(
preceded(pair(tag("SYSTEM"), S::parse), SystemLiteral::parse),
@ -1498,7 +1498,7 @@ impl<'s> Parser<'s> for ExternalID<'s> {
impl<'s> Parser<'s> for NDataDecl<'s> {
type Output = NDataDecl<'s>;
fn parse(input: &'s str) -> IResult<&str, NDataDecl<'s>> {
fn parse(input: &'s str) -> IResult<&'s str, NDataDecl<'s>> {
map(
preceded(tuple((S::parse, tag("NDATA"), S::parse)), Name::parse),
|n_data_decl| NDataDecl(n_data_decl),
@ -1510,7 +1510,7 @@ impl<'s> Parser<'s> for NDataDecl<'s> {
impl<'s> Parser<'s> for TextDecl<'s> {
type Output = TextDecl<'s>;
fn parse(input: &'s str) -> IResult<&str, TextDecl<'s>> {
fn parse(input: &'s str) -> IResult<&'s str, TextDecl<'s>> {
map(
delimited(
tag("<?xml"),
@ -1532,7 +1532,7 @@ impl<'s> Parser<'s> for TextDecl<'s> {
impl<'s> Parser<'s> for ExtParsedEnt<'s> {
type Output = ExtParsedEnt<'s>;
fn parse(input: &'s str) -> IResult<&str, ExtParsedEnt<'s>> {
fn parse(input: &'s str) -> IResult<&'s str, ExtParsedEnt<'s>> {
map(
pair(opt(TextDecl::parse), Content::parse),
|(text_decl, content)| ExtParsedEnt { text_decl, content },
@ -1544,7 +1544,7 @@ impl<'s> Parser<'s> for ExtParsedEnt<'s> {
impl<'s> Parser<'s> for EncodingDecl<'s> {
type Output = EncodingDecl<'s>;
fn parse(input: &'s str) -> IResult<&str, EncodingDecl<'s>> {
fn parse(input: &'s str) -> IResult<&'s str, EncodingDecl<'s>> {
map(
preceded(
tuple((S::parse, tag("encoding"), Eq::parse)),
@ -1562,7 +1562,7 @@ impl<'s> Parser<'s> for EncodingDecl<'s> {
impl<'s> Parser<'s> for EncName<'s> {
type Output = EncName<'s>;
fn parse(input: &'s str) -> IResult<&str, EncName<'s>> {
fn parse(input: &'s str) -> IResult<&'s str, EncName<'s>> {
map(
recognize(pair(
satisfy(|c| matches!(c, 'A'..='Z' | 'a'..='z' )),
@ -1579,7 +1579,7 @@ impl<'s> Parser<'s> for EncName<'s> {
impl<'s> Parser<'s> for NotationDecl<'s> {
type Output = NotationDecl<'s>;
fn parse(input: &'s str) -> IResult<&str, NotationDecl<'s>> {
fn parse(input: &'s str) -> IResult<&'s str, NotationDecl<'s>> {
map(
delimited(
pair(tag("<!NOTATION"), S::parse),
@ -1606,7 +1606,7 @@ impl<'s> Parser<'s> for NotationDecl<'s> {
impl<'s> Parser<'s> for PublicID<'s> {
type Output = PublicID<'s>;
fn parse(input: &'s str) -> IResult<&str, PublicID<'s>> {
fn parse(input: &'s str) -> IResult<&'s str, PublicID<'s>> {
map(
preceded(pair(tag("PUBLIC"), S::parse), PubidLiteral::parse),
|public_id| PublicID(public_id),

View File

@ -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<Self::Output> {
match <Self as Parser>::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("<!--"),
@ -442,7 +442,7 @@ impl<'s> Parser<'s> for Comment<'s> {
impl<'s> Parser<'s> for PI<'s> {
type Output = PI<'s>;
fn parse(input: &'s str) -> IResult<&str, PI<'s>> {
fn parse(input: &'s str) -> IResult<&'s str, PI<'s>> {
map(
delimited(
tag("<?"),
@ -467,7 +467,7 @@ impl<'s> Parser<'s> for PI<'s> {
impl<'s> Parser<'s> for PITarget<'s> {
type Output = PITarget<'s>;
fn parse(input: &'s str) -> IResult<&str, PITarget<'s>> {
fn parse(input: &'s str) -> IResult<&'s str, PITarget<'s>> {
let (rest, name) = Name::parse(input)?;
if name.0.to_lowercase() == "xml" {
return Err(Err::Error(Error {
@ -485,7 +485,7 @@ impl<'s> Parser<'s> for PITarget<'s> {
impl<'s> Parser<'s> for CDSect<'s> {
type Output = CDSect<'s>;
fn parse(input: &'s str) -> IResult<&str, CDSect<'s>> {
fn parse(input: &'s str) -> IResult<&'s str, CDSect<'s>> {
map(
delimited(CDStart::parse, CData::parse, CDEnd::parse),
|c_data| CDSect(c_data),
@ -506,7 +506,7 @@ impl Parser<'_> for CDStart {
impl<'s> Parser<'s> for CData<'s> {
type Output = CData<'s>;
fn parse(input: &'s str) -> IResult<&str, CData<'s>> {
fn parse(input: &'s str) -> IResult<&'s str, CData<'s>> {
map(
recognize(many_till(Char::parse, peek(tag("]]>")))),
|c_data| CData(c_data),
@ -527,7 +527,7 @@ impl Parser<'_> for CDEnd {
impl<'s> Parser<'s> for Prolog<'s> {
type Output = Prolog<'s>;
fn parse(input: &'s str) -> IResult<&str, Prolog<'s>> {
fn parse(input: &'s str) -> IResult<&'s str, Prolog<'s>> {
tuple((
opt(XMLDecl::parse),
many0(Misc::parse),
@ -540,7 +540,7 @@ impl<'s> Parser<'s> for Prolog<'s> {
impl<'s> Parser<'s> for XMLDecl<'s> {
type Output = XMLDecl<'s>;
fn parse(input: &'s str) -> IResult<&str, XMLDecl<'s>> {
fn parse(input: &'s str) -> IResult<&'s str, XMLDecl<'s>> {
map(
delimited(
tag("<?xml"),
@ -612,7 +612,7 @@ impl Parser<'_> for VersionNum {
impl<'s> Parser<'s> for Misc<'s> {
type Output = Misc<'s>;
fn parse(input: &'s str) -> IResult<&str, Misc<'s>> {
fn parse(input: &'s str) -> IResult<&'s str, Misc<'s>> {
alt((
map(Comment::parse, |comment| Misc::Comment(comment)),
map(PI::parse, |pi| Misc::PI(pi)),
@ -626,7 +626,7 @@ impl<'s> Parser<'s> for Misc<'s> {
impl<'s> Parser<'s> for DoctypeDecl<'s> {
type Output = DoctypeDecl<'s>;
fn parse(input: &'s str) -> IResult<&str, DoctypeDecl<'s>> {
fn parse(input: &'s str) -> IResult<&'s str, DoctypeDecl<'s>> {
map(
delimited(
pair(tag("<!DOCTYPE"), S::parse),
@ -656,7 +656,7 @@ impl<'s> Parser<'s> for DoctypeDecl<'s> {
impl<'s> Parser<'s> for DeclSep<'s> {
type Output = DeclSep<'s>;
fn parse(input: &'s str) -> IResult<&str, DeclSep<'s>> {
fn parse(input: &'s str) -> IResult<&'s str, DeclSep<'s>> {
alt((
map(PEReference::parse, |pe_reference| {
DeclSep::PEReference(pe_reference)
@ -670,7 +670,7 @@ impl<'s> Parser<'s> for DeclSep<'s> {
impl<'s> Parser<'s> for IntSubset<'s> {
type Output = IntSubset<'s>;
fn parse(input: &'s str) -> IResult<&str, IntSubset<'s>> {
fn parse(input: &'s str) -> IResult<&'s str, IntSubset<'s>> {
many0(alt((
map(MarkupDecl::parse, |markup_decl| {
IntSubsetDeclaration::MarkupDecl(markup_decl)
@ -686,7 +686,7 @@ impl<'s> Parser<'s> for IntSubset<'s> {
impl<'s> Parser<'s> for MarkupDecl<'s> {
type Output = MarkupDecl<'s>;
fn parse(input: &'s str) -> IResult<&str, MarkupDecl<'s>> {
fn parse(input: &'s str) -> IResult<&'s str, MarkupDecl<'s>> {
alt((
map(Elementdecl::parse, |elementdecl| {
MarkupDecl::Elementdecl(elementdecl)
@ -710,7 +710,7 @@ impl<'s> Parser<'s> for MarkupDecl<'s> {
impl<'s> Parser<'s> for ExtSubset<'s> {
type Output = ExtSubset<'s>;
fn parse(input: &'s str) -> IResult<&str, ExtSubset<'s>> {
fn parse(input: &'s str) -> IResult<&'s str, ExtSubset<'s>> {
map(
pair(opt(TextDecl::parse), ExtSubsetDecl::parse),
|(text_decl, ext_subset_decl)| ExtSubset {
@ -725,7 +725,7 @@ impl<'s> Parser<'s> for ExtSubset<'s> {
impl<'s> Parser<'s> for ExtSubsetDecl<'s> {
type Output = ExtSubsetDecl<'s>;
fn parse(input: &'s str) -> IResult<&str, ExtSubsetDecl<'s>> {
fn parse(input: &'s str) -> IResult<&'s str, ExtSubsetDecl<'s>> {
many0(alt((
map(MarkupDecl::parse, |markup_decl| {
ExtSubsetDeclaration::MarkupDecl(markup_decl)
@ -775,7 +775,7 @@ impl Parser<'_> for SDDecl {
impl<'s> Parser<'s> for Element<'s> {
type Output = Element<'s>;
fn parse(input: &'s str) -> IResult<&str, Element<'s>> {
fn parse(input: &'s str) -> IResult<&'s str, Element<'s>> {
alt((
map(EmptyElemTag::parse, |empty_elem_tag| {
Element::Empty(empty_elem_tag)
@ -793,7 +793,7 @@ impl<'s> Parser<'s> for Element<'s> {
impl<'s> Parser<'s> for STag<'s> {
type Output = STag<'s>;
fn parse(input: &'s str) -> IResult<&str, STag<'s>> {
fn parse(input: &'s str) -> IResult<&'s str, STag<'s>> {
map(
delimited(
tag("<"),
@ -809,7 +809,7 @@ impl<'s> Parser<'s> for STag<'s> {
impl<'s> Parser<'s> for Attribute<'s> {
type Output = Attribute<'s>;
fn parse(input: &'s str) -> IResult<&str, Attribute<'s>> {
fn parse(input: &'s str) -> IResult<&'s str, Attribute<'s>> {
alt((
map(
separated_pair(NSAttName::parse, Eq::parse, AttValue::parse),
@ -824,7 +824,7 @@ impl<'s> Parser<'s> for Attribute<'s> {
}
// pub type Attribute<'s> = (Name<'s>, AttValue<'s>);
/// [41] Attribute ::= Name Eq AttValue
// pub fn attribute(input: &str) -> IResult<&str, Attribute> {
// pub fn attribute(input: &str) -> IResult<&'s str, Attribute> {
// separated_pair(name, eq, att_value)(input)
// }
@ -833,7 +833,7 @@ impl<'s> Parser<'s> for Attribute<'s> {
impl<'s> Parser<'s> for ETag<'s> {
type Output = ETag<'s>;
fn parse(input: &'s str) -> IResult<&str, ETag<'s>> {
fn parse(input: &'s str) -> IResult<&'s str, ETag<'s>> {
map(
delimited(tag("</"), QName::parse, pair(opt(S::parse), tag(">"))),
|name| ETag { name },
@ -844,7 +844,7 @@ impl<'s> Parser<'s> for ETag<'s> {
impl<'s> Parser<'s> for ContentItem<'s> {
type Output = ContentItem<'s>;
fn parse(input: &'s str) -> IResult<&str, ContentItem<'s>> {
fn parse(input: &'s str) -> IResult<&'s str, ContentItem<'s>> {
alt((
map(Element::parse, |element| ContentItem::Element(element)),
map(Reference::parse, |reference| {
@ -861,7 +861,7 @@ impl<'s> Parser<'s> for ContentItem<'s> {
impl<'s> Parser<'s> for Content<'s> {
type Output = Content<'s>;
fn parse(input: &'s str) -> IResult<&str, Content<'s>> {
fn parse(input: &'s str) -> IResult<&'s str, Content<'s>> {
map(
pair(
opt(CharData::parse),
@ -888,7 +888,7 @@ impl<'s> Parser<'s> for Content<'s> {
impl<'s> Parser<'s> for EmptyElemTag<'s> {
type Output = EmptyElemTag<'s>;
fn parse(input: &'s str) -> IResult<&str, EmptyElemTag<'s>> {
fn parse(input: &'s str) -> IResult<&'s str, EmptyElemTag<'s>> {
map(
delimited(
tag("<"),
@ -905,7 +905,7 @@ impl<'s> Parser<'s> for EmptyElemTag<'s> {
impl<'s> Parser<'s> for Elementdecl<'s> {
type Output = Elementdecl<'s>;
fn parse(input: &'s str) -> IResult<&str, Elementdecl> {
fn parse(input: &'s str) -> IResult<&'s str, Elementdecl<'s>> {
map(
delimited(
pair(tag("<!ELEMENT"), S::parse),
@ -921,7 +921,7 @@ impl<'s> Parser<'s> for Elementdecl<'s> {
impl<'s> Parser<'s> for Contentspec<'s> {
type Output = Contentspec<'s>;
fn parse(input: &'s str) -> IResult<&str, Contentspec<'s>> {
fn parse(input: &'s str) -> IResult<&'s str, Contentspec<'s>> {
alt((
value(Contentspec::Empty, tag("EMPTY")),
value(Contentspec::Any, tag("ANY")),
@ -952,7 +952,7 @@ impl Parser<'_> for Occurence {
impl<'s> Parser<'s> for Children<'s> {
type Output = Children<'s>;
fn parse(input: &'s str) -> IResult<&str, Children<'s>> {
fn parse(input: &'s str) -> IResult<&'s str, Children<'s>> {
map(
pair(
alt((
@ -971,7 +971,7 @@ impl<'s> Parser<'s> for Children<'s> {
impl<'s> Parser<'s> for Cp<'s> {
type Output = Cp<'s>;
fn parse(input: &'s str) -> IResult<&str, Cp<'s>> {
fn parse(input: &'s str) -> IResult<&'s str, Cp<'s>> {
map(
pair(
alt((
@ -990,7 +990,7 @@ impl<'s> Parser<'s> for Cp<'s> {
impl<'s> Parser<'s> for Choice<'s> {
type Output = Choice<'s>;
fn parse(input: &'s str) -> IResult<&str, Choice<'s>> {
fn parse(input: &'s str) -> IResult<&'s str, Choice<'s>> {
map(
delimited(
pair(tag("("), opt(S::parse)),
@ -1015,7 +1015,7 @@ impl<'s> Parser<'s> for Choice<'s> {
impl<'s> Parser<'s> for Seq<'s> {
type Output = Seq<'s>;
fn parse(input: &'s str) -> IResult<&str, Seq<'s>> {
fn parse(input: &'s str) -> IResult<&'s str, Seq<'s>> {
map(
delimited(
pair(tag("("), opt(S::parse)),
@ -1041,7 +1041,7 @@ impl<'s> Parser<'s> for Seq<'s> {
impl<'s> Parser<'s> for Mixed<'s> {
type Output = Mixed<'s>;
fn parse(input: &'s str) -> IResult<&str, Mixed<'s>> {
fn parse(input: &'s str) -> IResult<&'s str, Mixed<'s>> {
alt((
map(
delimited(
@ -1073,7 +1073,7 @@ impl<'s> Parser<'s> for Mixed<'s> {
impl<'s> Parser<'s> for AttlistDecl<'s> {
type Output = AttlistDecl<'s>;
fn parse(input: &'s str) -> IResult<&str, AttlistDecl<'s>> {
fn parse(input: &'s str) -> IResult<&'s str, AttlistDecl<'s>> {
map(
delimited(
pair(tag("<!ATTLIST"), S::parse),
@ -1093,7 +1093,7 @@ impl<'s> Parser<'s> for AttlistDecl<'s> {
impl<'s> Parser<'s> for AttDef<'s> {
type Output = AttDef<'s>;
fn parse(input: &'s str) -> IResult<&str, AttDef<'s>> {
fn parse(input: &'s str) -> IResult<&'s str, AttDef<'s>> {
map(
tuple((
preceded(
@ -1121,7 +1121,7 @@ impl<'s> Parser<'s> for AttDef<'s> {
impl<'s> Parser<'s> for AttType<'s> {
type Output = AttType<'s>;
fn parse(input: &'s str) -> IResult<&str, AttType<'s>> {
fn parse(input: &'s str) -> IResult<&'s str, AttType<'s>> {
alt((
value(AttType::StringType, StringType::parse),
map(TokenizedType::parse, |tokenized_type| {
@ -1150,7 +1150,6 @@ impl Parser<'_> for TokenizedType {
fn parse(input: &'_ str) -> IResult<&str, TokenizedType> {
alt((
value(TokenizedType::ID, tag("ID")),
// TODO: check if this is required
// try idrefs first to avoid losing 'S'
value(TokenizedType::IDRefs, tag("IDREFS")),
value(TokenizedType::IDRef, tag("IDREF")),
@ -1167,7 +1166,7 @@ impl Parser<'_> for TokenizedType {
impl<'s> Parser<'s> for EnumeratedType<'s> {
type Output = EnumeratedType<'s>;
fn parse(input: &'s str) -> IResult<&str, EnumeratedType<'s>> {
fn parse(input: &'s str) -> IResult<&'s str, EnumeratedType<'s>> {
alt((
map(NotationType::parse, |notation_type| {
EnumeratedType::NotationType(notation_type)
@ -1183,7 +1182,7 @@ impl<'s> Parser<'s> for EnumeratedType<'s> {
impl<'s> Parser<'s> for NotationType<'s> {
type Output = NotationType<'s>;
fn parse(input: &'s str) -> IResult<&str, NotationType<'s>> {
fn parse(input: &'s str) -> IResult<&'s str, NotationType<'s>> {
map(
delimited(
tuple((tag("NOTATION"), S::parse, tag("("), opt(S::parse))),
@ -1208,7 +1207,7 @@ impl<'s> Parser<'s> for NotationType<'s> {
impl<'s> Parser<'s> for Enumeration<'s> {
type Output = Enumeration<'s>;
fn parse(input: &'s str) -> IResult<&str, Enumeration<'s>> {
fn parse(input: &'s str) -> IResult<&'s str, Enumeration<'s>> {
map(
delimited(
pair(tag("("), opt(S::parse)),
@ -1233,7 +1232,7 @@ impl<'s> Parser<'s> for Enumeration<'s> {
impl<'s> Parser<'s> for DefaultDecl<'s> {
type Output = DefaultDecl<'s>;
fn parse(input: &'s str) -> IResult<&str, DefaultDecl<'s>> {
fn parse(input: &'s str) -> IResult<&'s str, DefaultDecl<'s>> {
alt((
value(DefaultDecl::Required, tag("#REQUIRED")),
value(DefaultDecl::Implied, tag("#IMPLIED")),
@ -1249,7 +1248,7 @@ impl<'s> Parser<'s> for DefaultDecl<'s> {
impl<'s> Parser<'s> for ConditionalSect<'s> {
type Output = ConditionalSect<'s>;
fn parse(input: &'s str) -> IResult<&str, ConditionalSect<'s>> {
fn parse(input: &'s str) -> IResult<&'s str, ConditionalSect<'s>> {
alt((
map(IncludeSect::parse, |include_sect| {
ConditionalSect::IncludeSect(include_sect)
@ -1265,7 +1264,7 @@ impl<'s> Parser<'s> for ConditionalSect<'s> {
impl<'s> Parser<'s> for IncludeSect<'s> {
type Output = IncludeSect<'s>;
fn parse(input: &'s str) -> IResult<&str, IncludeSect<'s>> {
fn parse(input: &'s str) -> IResult<&'s str, IncludeSect<'s>> {
map(
delimited(
tuple((
@ -1287,7 +1286,7 @@ impl<'s> Parser<'s> for IncludeSect<'s> {
impl<'s> Parser<'s> for IgnoreSect<'s> {
type Output = IgnoreSect<'s>;
fn parse(input: &'s str) -> IResult<&str, IgnoreSect<'s>> {
fn parse(input: &'s str) -> IResult<&'s str, IgnoreSect<'s>> {
map(
delimited(
tuple((
@ -1309,7 +1308,7 @@ impl<'s> Parser<'s> for IgnoreSect<'s> {
impl<'s> Parser<'s> for IgnoreSectContents<'s> {
type Output = IgnoreSectContents<'s>;
fn parse(input: &'s str) -> IResult<&str, IgnoreSectContents<'s>> {
fn parse(input: &'s str) -> IResult<&'s str, IgnoreSectContents<'s>> {
map(
pair(
Ignore::parse,
@ -1330,7 +1329,7 @@ impl<'s> Parser<'s> for IgnoreSectContents<'s> {
impl<'s> Parser<'s> for Ignore<'s> {
type Output = Ignore<'s>;
fn parse(input: &'s str) -> IResult<&str, Ignore<'s>> {
fn parse(input: &'s str) -> IResult<&'s str, Ignore<'s>> {
map(
recognize(many_till(Char::parse, peek(alt((tag("<!["), tag("]]>")))))),
|ignore| Ignore(ignore),
@ -1342,7 +1341,7 @@ impl<'s> Parser<'s> for Ignore<'s> {
impl<'s> Parser<'s> for CharRef<'s> {
type Output = CharRef<'s>;
fn parse(input: &'s str) -> IResult<&str, CharRef<'s>> {
fn parse(input: &'s str) -> IResult<&'s str, CharRef<'s>> {
alt((
delimited(
tag("&#"),
@ -1367,7 +1366,7 @@ impl<'s> Parser<'s> for CharRef<'s> {
impl<'s> Parser<'s> for Reference<'s> {
type Output = Reference<'s>;
fn parse(input: &'s str) -> IResult<&str, Reference<'s>> {
fn parse(input: &'s str) -> IResult<&'s str, Reference<'s>> {
alt((
map(EntityRef::parse, |entity_ref| {
Reference::EntityRef(entity_ref)
@ -1381,7 +1380,7 @@ impl<'s> Parser<'s> for Reference<'s> {
impl<'s> Parser<'s> for EntityRef<'s> {
type Output = EntityRef<'s>;
fn parse(input: &'s str) -> IResult<&str, EntityRef<'s>> {
fn parse(input: &'s str) -> IResult<&'s str, EntityRef<'s>> {
map(delimited(tag("&"), Name::parse, tag(";")), |entity_ref| {
EntityRef(entity_ref)
})(input)
@ -1392,7 +1391,7 @@ impl<'s> Parser<'s> for EntityRef<'s> {
impl<'s> Parser<'s> for PEReference<'s> {
type Output = PEReference<'s>;
fn parse(input: &'s str) -> IResult<&str, PEReference<'s>> {
fn parse(input: &'s str) -> IResult<&'s str, PEReference<'s>> {
map(delimited(tag("%"), Name::parse, tag(";")), |pe_reference| {
PEReference(pe_reference)
})(input)
@ -1403,7 +1402,7 @@ impl<'s> Parser<'s> for PEReference<'s> {
impl<'s> Parser<'s> for EntityDecl<'s> {
type Output = EntityDecl<'s>;
fn parse(input: &'s str) -> IResult<&str, EntityDecl<'s>> {
fn parse(input: &'s str) -> IResult<&'s str, EntityDecl<'s>> {
alt((
map(GEDecl::parse, |ge_decl| EntityDecl::GEDecl(ge_decl)),
map(PEDecl::parse, |pe_decl| EntityDecl::PEDecl(pe_decl)),
@ -1415,7 +1414,7 @@ impl<'s> Parser<'s> for EntityDecl<'s> {
impl<'s> Parser<'s> for GEDecl<'s> {
type Output = GEDecl<'s>;
fn parse(input: &'s str) -> IResult<&str, GEDecl<'s>> {
fn parse(input: &'s str) -> IResult<&'s str, GEDecl<'s>> {
map(
delimited(
pair(tag("<!ENTITY"), S::parse),
@ -1431,7 +1430,7 @@ impl<'s> Parser<'s> for GEDecl<'s> {
impl<'s> Parser<'s> for PEDecl<'s> {
type Output = PEDecl<'s>;
fn parse(input: &'s str) -> IResult<&str, PEDecl<'s>> {
fn parse(input: &'s str) -> IResult<&'s str, PEDecl<'s>> {
map(
delimited(
tuple((tag("<!ENTITY"), S::parse, tag("%"), S::parse)),
@ -1447,7 +1446,7 @@ impl<'s> Parser<'s> for PEDecl<'s> {
impl<'s> Parser<'s> for EntityDef<'s> {
type Output = EntityDef<'s>;
fn parse(input: &'s str) -> IResult<&str, EntityDef<'s>> {
fn parse(input: &'s str) -> IResult<&'s str, EntityDef<'s>> {
alt((
map(EntityValue::parse, |entity_value| {
EntityDef::EntityValue(entity_value)
@ -1467,7 +1466,7 @@ impl<'s> Parser<'s> for EntityDef<'s> {
impl<'s> Parser<'s> for PEDef<'s> {
type Output = PEDef<'s>;
fn parse(input: &'s str) -> IResult<&str, PEDef<'s>> {
fn parse(input: &'s str) -> IResult<&'s str, PEDef<'s>> {
alt((
map(EntityValue::parse, |entity_value| {
PEDef::EntityValue(entity_value)
@ -1480,11 +1479,11 @@ impl<'s> Parser<'s> for PEDef<'s> {
}
/// [75] ExternalID ::= 'SYSTEM' S SystemLiteral | 'PUBLIC' S PubidLiteral S SystemLiteral
// pub fn external_id(input: &str) -> IResult<&str, ExternalID> {
// pub fn external_id(input: &str) -> IResult<&'s str, ExternalID> {
impl<'s> Parser<'s> for ExternalID<'s> {
type Output = ExternalID<'s>;
fn parse(input: &'s str) -> IResult<&str, ExternalID<'s>> {
fn parse(input: &'s str) -> IResult<&'s str, ExternalID<'s>> {
alt((
map(
preceded(pair(tag("SYSTEM"), S::parse), SystemLiteral::parse),
@ -1508,7 +1507,7 @@ impl<'s> Parser<'s> for ExternalID<'s> {
impl<'s> Parser<'s> for NDataDecl<'s> {
type Output = NDataDecl<'s>;
fn parse(input: &'s str) -> IResult<&str, NDataDecl<'s>> {
fn parse(input: &'s str) -> IResult<&'s str, NDataDecl<'s>> {
map(
preceded(tuple((S::parse, tag("NDATA"), S::parse)), Name::parse),
|n_data_decl| NDataDecl(n_data_decl),
@ -1520,7 +1519,7 @@ impl<'s> Parser<'s> for NDataDecl<'s> {
impl<'s> Parser<'s> for TextDecl<'s> {
type Output = TextDecl<'s>;
fn parse(input: &'s str) -> IResult<&str, TextDecl<'s>> {
fn parse(input: &'s str) -> IResult<&'s str, TextDecl<'s>> {
map(
delimited(
tag("<?xml"),
@ -1542,7 +1541,7 @@ impl<'s> Parser<'s> for TextDecl<'s> {
impl<'s> Parser<'s> for ExtParsedEnt<'s> {
type Output = ExtParsedEnt<'s>;
fn parse(input: &'s str) -> IResult<&str, ExtParsedEnt<'s>> {
fn parse(input: &'s str) -> IResult<&'s str, ExtParsedEnt<'s>> {
map(
pair(opt(TextDecl::parse), Content::parse),
|(text_decl, content)| ExtParsedEnt { text_decl, content },
@ -1554,7 +1553,7 @@ impl<'s> Parser<'s> for ExtParsedEnt<'s> {
impl<'s> Parser<'s> for EncodingDecl<'s> {
type Output = EncodingDecl<'s>;
fn parse(input: &'s str) -> IResult<&str, EncodingDecl<'s>> {
fn parse(input: &'s str) -> IResult<&'s str, EncodingDecl<'s>> {
map(
preceded(
tuple((S::parse, tag("encoding"), Eq::parse)),
@ -1572,7 +1571,7 @@ impl<'s> Parser<'s> for EncodingDecl<'s> {
impl<'s> Parser<'s> for EncName<'s> {
type Output = EncName<'s>;
fn parse(input: &'s str) -> IResult<&str, EncName<'s>> {
fn parse(input: &'s str) -> IResult<&'s str, EncName<'s>> {
map(
recognize(pair(
satisfy(|c| matches!(c, 'A'..='Z' | 'a'..='z' )),
@ -1589,7 +1588,7 @@ impl<'s> Parser<'s> for EncName<'s> {
impl<'s> Parser<'s> for NotationDecl<'s> {
type Output = NotationDecl<'s>;
fn parse(input: &'s str) -> IResult<&str, NotationDecl<'s>> {
fn parse(input: &'s str) -> IResult<&'s str, NotationDecl<'s>> {
map(
delimited(
pair(tag("<!NOTATION"), S::parse),
@ -1616,7 +1615,7 @@ impl<'s> Parser<'s> for NotationDecl<'s> {
impl<'s> Parser<'s> for PublicID<'s> {
type Output = PublicID<'s>;
fn parse(input: &'s str) -> IResult<&str, PublicID<'s>> {
fn parse(input: &'s str) -> IResult<&'s str, PublicID<'s>> {
map(
preceded(pair(tag("PUBLIC"), S::parse), PubidLiteral::parse),
|public_id| PublicID(public_id),
@ -1626,8 +1625,6 @@ impl<'s> Parser<'s> for PublicID<'s> {
#[cfg(test)]
mod tests {
use std::num::NonZero;
use super::*;
#[test]