Compare commits

..

No commits in common. "4c235b972e2400bd2bb92b74b12558b485dc7142" and "32545d8a6aa167143d0bd4d78f046017de54b614" have entirely different histories.

3 changed files with 93 additions and 1980 deletions

View File

@ -4,7 +4,6 @@ use crate::error::Error;
pub mod composers;
pub mod parsers;
pub mod parsers_complete;
/// [1] NSAttName ::= PrefixedAttName | DefaultAttName
#[derive(Clone, Debug)]

View File

@ -29,17 +29,13 @@ use super::{
TokenizedType, UnprefixedName, VersionInfo, VersionNum, XMLDecl, PI, S,
};
pub trait Parser<'s> {
type Output;
fn parse(input: &'s str) -> IResult<&str, Self::Output>;
pub trait Parser<'s, T> {
fn parse(input: &'s str) -> IResult<&str, T>;
}
/// [1] NSAttName ::= PrefixedAttName | DefaultAttName
impl<'s> Parser<'s> for NSAttName<'s> {
type Output = NSAttName<'s>;
fn parse(input: &'s str) -> IResult<&str, Self::Output> {
impl<'s> Parser<'s, NSAttName<'s>> for NSAttName<'s> {
fn parse(input: &'s str) -> IResult<&str, NSAttName<'s>> {
alt((
map(PrefixedAttName::parse, |prefixed_att_name| {
NSAttName::PrefixedAttName(prefixed_att_name)
@ -50,9 +46,7 @@ impl<'s> Parser<'s> for NSAttName<'s> {
}
/// [2] PrefixedAttName ::= 'xmlns:' NCName
impl<'s> Parser<'s> for PrefixedAttName<'s> {
type Output = PrefixedAttName<'s>;
impl<'s> Parser<'s, PrefixedAttName<'s>> for PrefixedAttName<'s> {
fn parse(input: &'s str) -> IResult<&str, PrefixedAttName<'s>> {
map(preceded(tag("xmlns:"), NCName::parse), |nc_name| {
PrefixedAttName(nc_name)
@ -61,9 +55,7 @@ impl<'s> Parser<'s> for PrefixedAttName<'s> {
}
/// [3] DefaultAttName ::= 'xmlns';
impl Parser<'_> for DefaultAttName {
type Output = DefaultAttName;
impl Parser<'_, DefaultAttName> for DefaultAttName {
fn parse(input: &str) -> IResult<&str, DefaultAttName> {
value(DefaultAttName, tag("xmlns"))(input)
}
@ -71,9 +63,7 @@ impl Parser<'_> for DefaultAttName {
/// [5] Name ::= NameStartChar (NameChar)*
/// [4] NCName ::= Name - (Char* ':' Char*)
impl<'s> Parser<'s> for NCName<'s> {
type Output = NCName<'s>;
impl<'s> Parser<'s, NCName<'s>> for NCName<'s> {
fn parse(input: &'s str) -> IResult<&str, NCName<'s>> {
let (rest, name) = peek(recognize(Name::parse))(input)?;
if let Some(char) = name.find(':') {
@ -85,9 +75,7 @@ impl<'s> Parser<'s> for NCName<'s> {
}
/// [7] QName ::= PrefixedName | UnprefixedName
impl<'s> Parser<'s> for QName<'s> {
type Output = QName<'s>;
impl<'s> Parser<'s, QName<'s>> for QName<'s> {
fn parse(input: &'s str) -> IResult<&str, QName<'s>> {
alt((
map(PrefixedName::parse, |prefixed_name| {
@ -101,9 +89,7 @@ impl<'s> Parser<'s> for QName<'s> {
}
/// [8] PrefixedName ::= Prefix ':' LocalPart
impl<'s> Parser<'s> for PrefixedName<'s> {
type Output = PrefixedName<'s>;
impl<'s> Parser<'s, PrefixedName<'s>> for PrefixedName<'s> {
fn parse(input: &'s str) -> IResult<&str, PrefixedName<'s>> {
map(
separated_pair(Prefix::parse, char(':'), LocalPart::parse),
@ -113,27 +99,21 @@ impl<'s> Parser<'s> for PrefixedName<'s> {
}
/// [9] UnprefixedName ::= LocalPart
impl<'s> Parser<'s> for UnprefixedName<'s> {
type Output = UnprefixedName<'s>;
impl<'s> Parser<'s, UnprefixedName<'s>> for UnprefixedName<'s> {
fn parse(input: &'s str) -> IResult<&str, UnprefixedName<'s>> {
map(LocalPart::parse, |local_part| UnprefixedName(local_part))(input)
}
}
/// [10] Prefix ::= NCName
impl<'s> Parser<'s> for Prefix<'s> {
type Output = Prefix<'s>;
impl<'s> Parser<'s, Prefix<'s>> for Prefix<'s> {
fn parse(input: &'s str) -> IResult<&str, Prefix<'s>> {
map(NCName::parse, |nc_name| Prefix(nc_name))(input)
}
}
/// [11] LocalPart ::= NCName
impl<'s> Parser<'s> for LocalPart<'s> {
type Output = LocalPart<'s>;
impl<'s> Parser<'s, LocalPart<'s>> for LocalPart<'s> {
fn parse(input: &'s str) -> IResult<&str, LocalPart<'s>> {
map(NCName::parse, |nc_name| LocalPart(nc_name))(input)
}
@ -142,18 +122,14 @@ impl<'s> Parser<'s> for LocalPart<'s> {
// xml spec
/// [1] document ::= prolog element Misc*
impl<'s> Parser<'s> for Document<'s> {
type Output = Document<'s>;
impl<'s> Parser<'s, Document<'s>> for Document<'s> {
fn parse(input: &'s str) -> IResult<&str, Document<'s>> {
tuple((Prolog::parse, Element::parse, many0(Misc::parse)))(input)
}
}
/// [2] Char ::= #x9 | #xA | #xD | [#x20-#xD7FF] | [#xE000-#xFFFD] | [#x10000-#x10FFFF] /* any Unicode character, excluding the surrogate blocks, FFFE, and FFFF. */
impl Parser<'_> for Char {
type Output = Char;
impl Parser<'_, Char> for Char {
fn parse(input: &str) -> IResult<&str, Char> {
map(
satisfy(
@ -165,9 +141,7 @@ impl Parser<'_> for Char {
}
/// [3] S ::= (#x20 | #x9 | #xD | #xA)+
impl Parser<'_> for S {
type Output = S;
impl Parser<'_, S> for S {
fn parse(input: &str) -> IResult<&str, S> {
// TODO?: whitespacing
// map(is_a("\u{20}\u{9}\u{D}\u{A}"), |s| S(s))(input)
@ -176,9 +150,7 @@ impl Parser<'_> for S {
}
/// [4] NameStartChar ::= ":" | [A-Z] | "_" | [a-z] | [#xC0-#xD6] | [#xD8-#xF6] | [#xF8-#x2FF] | [#x370-#x37D] | [#x37F-#x1FFF] | [#x200C-#x200D] | [#x2070-#x218F] | [#x2C00-#x2FEF] | [#x3001-#xD7FF] | [#xF900-#xFDCF] | [#xFDF0-#xFFFD] | [#x10000-#xEFFFF]
impl Parser<'_> for NameStartChar {
type Output = NameStartChar;
impl Parser<'_, NameStartChar> for NameStartChar {
fn parse(input: &str) -> IResult<&str, NameStartChar> {
map(
satisfy(
@ -190,9 +162,7 @@ impl Parser<'_> for NameStartChar {
}
/// [4a] NameChar ::= NameStartChar | "-" | "." | [0-9] | #xB7 | [#x0300-#x036F] | [#x203F-#x2040]
impl Parser<'_> for NameChar {
type Output = NameChar;
impl Parser<'_, NameChar> for NameChar {
fn parse(input: &str) -> IResult<&str, NameChar> {
map(
alt((
@ -207,9 +177,7 @@ impl Parser<'_> for NameChar {
}
/// [5] Name ::= NameStartChar (NameChar)*
impl<'s> Parser<'s> for Name<'s> {
type Output = Name<'s>;
impl<'s> Parser<'s, Name<'s>> for Name<'s> {
fn parse(input: &'s str) -> IResult<&str, Name<'s>> {
map(
recognize(pair(NameStartChar::parse, many0(NameChar::parse))),
@ -219,9 +187,7 @@ impl<'s> Parser<'s> for Name<'s> {
}
/// [6] Names ::= Name (#x20 Name)*
impl<'s> Parser<'s> for Names<'s> {
type Output = Names<'s>;
impl<'s> Parser<'s, Names<'s>> for Names<'s> {
// TODO: fix
fn parse(input: &'s str) -> IResult<&str, Names<'s>> {
map(
@ -232,9 +198,7 @@ impl<'s> Parser<'s> for Names<'s> {
}
/// [7] Nmtoken ::= (NameChar)+
impl<'s> Parser<'s> for Nmtoken<'s> {
type Output = Nmtoken<'s>;
impl<'s> Parser<'s, Nmtoken<'s>> for Nmtoken<'s> {
fn parse(input: &'s str) -> IResult<&str, Nmtoken<'s>> {
map(recognize(many1(NameChar::parse)), |nmtoken| {
Nmtoken(nmtoken)
@ -243,9 +207,7 @@ impl<'s> Parser<'s> for Nmtoken<'s> {
}
/// [8] Nmtokens ::= Nmtoken (#x20 Nmtoken)*
impl<'s> Parser<'s> for Nmtokens<'s> {
type Output = Nmtokens<'s>;
impl<'s> Parser<'s, Nmtokens<'s>> for Nmtokens<'s> {
fn parse(input: &'s str) -> IResult<&str, Nmtokens<'s>> {
map(
pair(
@ -259,9 +221,7 @@ impl<'s> Parser<'s> for Nmtokens<'s> {
/// [9] EntityValue ::= '"' ([^%&"] | PEReference | Reference)* '"'
/// | "'" ([^%&'] | PEReference | Reference)* "'"
impl<'s> Parser<'s> for EntityValue<'s> {
type Output = EntityValue<'s>;
impl<'s> Parser<'s, EntityValue<'s>> for EntityValue<'s> {
fn parse(input: &'s str) -> IResult<&str, EntityValue<'s>> {
alt((
map(
@ -308,9 +268,7 @@ impl<'s> Parser<'s> for EntityValue<'s> {
/// [10] AttValue ::= '"' ([^<&"] | Reference)* '"'
/// | "'" ([^<&'] | Reference)* "'"
impl<'s> Parser<'s> for AttValue<'s> {
type Output = AttValue<'s>;
impl<'s> Parser<'s, AttValue<'s>> for AttValue<'s> {
fn parse(input: &'s str) -> IResult<&str, AttValue<'s>> {
alt((
map(
@ -344,9 +302,7 @@ impl<'s> Parser<'s> for AttValue<'s> {
}
/// [11] SystemLiteral ::= ('"' [^"]* '"') | ("'" [^']* "'")
impl<'s> Parser<'s> for SystemLiteral<'s> {
type Output = SystemLiteral<'s>;
impl<'s> Parser<'s, SystemLiteral<'s>> for SystemLiteral<'s> {
fn parse(input: &'s str) -> IResult<&str, SystemLiteral<'s>> {
alt((
map(
@ -362,9 +318,7 @@ impl<'s> Parser<'s> for SystemLiteral<'s> {
}
/// [12] PubidLiteral ::= '"' PubidChar* '"' | "'" (PubidChar - "'")* "'"
impl<'s> Parser<'s> for PubidLiteral<'s> {
type Output = PubidLiteral<'s>;
impl<'s> Parser<'s, PubidLiteral<'s>> for PubidLiteral<'s> {
fn parse(input: &'s str) -> IResult<&str, PubidLiteral<'s>> {
alt((
map(
@ -384,9 +338,7 @@ impl<'s> Parser<'s> for PubidLiteral<'s> {
}
/// [13] PubidChar ::= #x20 | #xD | #xA | [a-zA-Z0-9] | [-'()+,./:=?;!*#@$_%]
impl Parser<'_> for PubidChar {
type Output = PubidChar;
impl Parser<'_, PubidChar> for PubidChar {
fn parse(input: &'_ str) -> IResult<&str, PubidChar> {
map(
satisfy(
@ -398,9 +350,7 @@ impl Parser<'_> for PubidChar {
}
/// [14] CharData ::= [^<&]* - ([^<&]* ']]>' [^<&]*)
impl<'s> Parser<'s> for CharData<'s> {
type Output = CharData<'s>;
impl<'s> Parser<'s, CharData<'s>> for CharData<'s> {
fn parse(input: &'s str) -> IResult<&str, CharData<'s>> {
map(
recognize(many_till(
@ -413,9 +363,7 @@ impl<'s> Parser<'s> for CharData<'s> {
}
/// Comment ::= '<!--' ((Char - '-') | ('-' (Char - '-')))* '-->'
impl<'s> Parser<'s> for Comment<'s> {
type Output = Comment<'s>;
impl<'s> Parser<'s, Comment<'s>> for Comment<'s> {
fn parse(input: &'s str) -> IResult<&str, Comment<'s>> {
map(
delimited(
@ -429,9 +377,7 @@ impl<'s> Parser<'s> for Comment<'s> {
}
/// [16] PI ::= '<?' PITarget (S (Char* - (Char* '?>' Char*)))? '?>'
impl<'s> Parser<'s> for PI<'s> {
type Output = PI<'s>;
impl<'s> Parser<'s, PI<'s>> for PI<'s> {
fn parse(input: &'s str) -> IResult<&str, PI<'s>> {
map(
delimited(
@ -454,9 +400,7 @@ impl<'s> Parser<'s> for PI<'s> {
}
/// [17] PITarget ::= Name - (('X' | 'x') ('M' | 'm') ('L' | 'l'))
impl<'s> Parser<'s> for PITarget<'s> {
type Output = PITarget<'s>;
impl<'s> Parser<'s, PITarget<'s>> for PITarget<'s> {
fn parse(input: &'s str) -> IResult<&str, PITarget<'s>> {
let (rest, name) = Name::parse(input)?;
if name.0.to_lowercase() == "xml" {
@ -472,9 +416,7 @@ impl<'s> Parser<'s> for PITarget<'s> {
}
/// [18] CDSect ::= CDStart CData CDEnd
impl<'s> Parser<'s> for CDSect<'s> {
type Output = CDSect<'s>;
impl<'s> Parser<'s, CDSect<'s>> for CDSect<'s> {
fn parse(input: &'s str) -> IResult<&str, CDSect<'s>> {
map(
delimited(CDStart::parse, CData::parse, CDEnd::parse),
@ -484,18 +426,14 @@ impl<'s> Parser<'s> for CDSect<'s> {
}
/// [19] CDStart ::= '<![CDATA['
impl Parser<'_> for CDStart {
type Output = CDStart;
impl Parser<'_, CDStart> for CDStart {
fn parse(input: &'_ str) -> IResult<&str, CDStart> {
value(CDStart, tag("<![CDATA["))(input)
}
}
/// [20] CData ::= (Char* - (Char* ']]>' Char*))
impl<'s> Parser<'s> for CData<'s> {
type Output = CData<'s>;
impl<'s> Parser<'s, CData<'s>> for CData<'s> {
fn parse(input: &'s str) -> IResult<&str, CData<'s>> {
map(
recognize(many_till(Char::parse, peek(tag("]]>")))),
@ -505,18 +443,14 @@ impl<'s> Parser<'s> for CData<'s> {
}
/// [21] CDEnd ::= ']]>'
impl Parser<'_> for CDEnd {
type Output = CDEnd;
impl Parser<'_, CDEnd> for CDEnd {
fn parse(input: &'_ str) -> IResult<&str, CDEnd> {
value(CDEnd, tag("]]>"))(input)
}
}
/// [22] prolog ::= XMLDecl? Misc* (doctypedecl Misc*)?
impl<'s> Parser<'s> for Prolog<'s> {
type Output = Prolog<'s>;
impl<'s> Parser<'s, Prolog<'s>> for Prolog<'s> {
fn parse(input: &'s str) -> IResult<&str, Prolog<'s>> {
tuple((
opt(XMLDecl::parse),
@ -527,9 +461,7 @@ impl<'s> Parser<'s> for Prolog<'s> {
}
/// [23] XMLDecl ::= '<?xml' VersionInfo EncodingDecl? SDDecl? S? '?>'
impl<'s> Parser<'s> for XMLDecl<'s> {
type Output = XMLDecl<'s>;
impl<'s> Parser<'s, XMLDecl<'s>> for XMLDecl<'s> {
fn parse(input: &'s str) -> IResult<&str, XMLDecl<'s>> {
map(
delimited(
@ -551,9 +483,7 @@ impl<'s> Parser<'s> for XMLDecl<'s> {
}
/// [24] VersionInfo ::= S 'version' Eq ("'" VersionNum "'" | '"' VersionNum '"')
impl Parser<'_> for VersionInfo {
type Output = VersionInfo;
impl Parser<'_, VersionInfo> for VersionInfo {
fn parse(input: &'_ str) -> IResult<&str, VersionInfo> {
preceded(
tuple((S::parse, tag("version"), Eq::parse)),
@ -572,9 +502,7 @@ impl Parser<'_> for VersionInfo {
}
/// [25] Eq ::= S? '=' S?
impl Parser<'_> for Eq {
type Output = Eq;
impl Parser<'_, Eq> for Eq {
fn parse(input: &'_ str) -> IResult<&str, Eq> {
value(
Eq,
@ -584,9 +512,7 @@ impl Parser<'_> for Eq {
}
/// [26] VersionNum ::= '1.' [0-9]+
impl Parser<'_> for VersionNum {
type Output = VersionNum;
impl Parser<'_, VersionNum> for VersionNum {
fn parse(input: &'_ str) -> IResult<&str, VersionNum> {
preceded(
tag("1."),
@ -599,9 +525,7 @@ impl Parser<'_> for VersionNum {
}
/// [27] Misc ::= Comment | PI | S
impl<'s> Parser<'s> for Misc<'s> {
type Output = Misc<'s>;
impl<'s> Parser<'s, Misc<'s>> for Misc<'s> {
fn parse(input: &'s str) -> IResult<&str, Misc<'s>> {
alt((
map(Comment::parse, |comment| Misc::Comment(comment)),
@ -613,9 +537,7 @@ impl<'s> Parser<'s> for Misc<'s> {
/// [16] doctypedecl ::= '<!DOCTYPE' S QName (S ExternalID)? S? ('[' (markupdecl | PEReference | S)* ']' S?)? '>'
/// [28] doctypedecl ::= '<!DOCTYPE' S Name (S ExternalID)? S? ('[' intSubset ']' S?)? '>'
impl<'s> Parser<'s> for DoctypeDecl<'s> {
type Output = DoctypeDecl<'s>;
impl<'s> Parser<'s, DoctypeDecl<'s>> for DoctypeDecl<'s> {
fn parse(input: &'s str) -> IResult<&str, DoctypeDecl<'s>> {
map(
delimited(
@ -643,9 +565,7 @@ impl<'s> Parser<'s> for DoctypeDecl<'s> {
}
/// [28a] DeclSep ::= PEReference | S
impl<'s> Parser<'s> for DeclSep<'s> {
type Output = DeclSep<'s>;
impl<'s> Parser<'s, DeclSep<'s>> for DeclSep<'s> {
fn parse(input: &'s str) -> IResult<&str, DeclSep<'s>> {
alt((
map(PEReference::parse, |pe_reference| {
@ -657,9 +577,7 @@ impl<'s> Parser<'s> for DeclSep<'s> {
}
/// [28b] intSubset ::= (markupdecl | DeclSep)*
impl<'s> Parser<'s> for IntSubset<'s> {
type Output = IntSubset<'s>;
impl<'s> Parser<'s, IntSubset<'s>> for IntSubset<'s> {
fn parse(input: &'s str) -> IResult<&str, IntSubset<'s>> {
many0(alt((
map(MarkupDecl::parse, |markup_decl| {
@ -673,9 +591,7 @@ impl<'s> Parser<'s> for IntSubset<'s> {
}
/// [29] markupdecl ::= elementdecl | AttlistDecl | EntityDecl | NotationDecl | PI | Comment
impl<'s> Parser<'s> for MarkupDecl<'s> {
type Output = MarkupDecl<'s>;
impl<'s> Parser<'s, MarkupDecl<'s>> for MarkupDecl<'s> {
fn parse(input: &'s str) -> IResult<&str, MarkupDecl<'s>> {
alt((
map(Elementdecl::parse, |elementdecl| {
@ -697,9 +613,7 @@ impl<'s> Parser<'s> for MarkupDecl<'s> {
}
/// [30] extSubset ::= TextDecl? extSubsetDecl
impl<'s> Parser<'s> for ExtSubset<'s> {
type Output = ExtSubset<'s>;
impl<'s> Parser<'s, ExtSubset<'s>> for ExtSubset<'s> {
fn parse(input: &'s str) -> IResult<&str, ExtSubset<'s>> {
map(
pair(opt(TextDecl::parse), ExtSubsetDecl::parse),
@ -712,9 +626,7 @@ impl<'s> Parser<'s> for ExtSubset<'s> {
}
/// [31] extSubsetDecl ::= ( markupdecl | conditionalSect | DeclSep)*
impl<'s> Parser<'s> for ExtSubsetDecl<'s> {
type Output = ExtSubsetDecl<'s>;
impl<'s> Parser<'s, ExtSubsetDecl<'s>> for ExtSubsetDecl<'s> {
fn parse(input: &'s str) -> IResult<&str, ExtSubsetDecl<'s>> {
many0(alt((
map(MarkupDecl::parse, |markup_decl| {
@ -731,9 +643,7 @@ impl<'s> Parser<'s> for ExtSubsetDecl<'s> {
}
/// [32] SDDecl ::= S 'standalone' Eq (("'" ('yes' | 'no') "'") | ('"' ('yes' | 'no') '"'))
impl Parser<'_> for SDDecl {
type Output = SDDecl;
impl Parser<'_, SDDecl> for SDDecl {
fn parse(input: &'_ str) -> IResult<&str, SDDecl> {
preceded(
tuple((S::parse, tag("standalone"), Eq::parse)),
@ -762,9 +672,7 @@ impl Parser<'_> for SDDecl {
// (Productions 33 through 38 have been removed.)
/// [39] element ::= EmptyElemTag | STag content ETag
impl<'s> Parser<'s> for Element<'s> {
type Output = Element<'s>;
impl<'s> Parser<'s, Element<'s>> for Element<'s> {
fn parse(input: &'s str) -> IResult<&str, Element<'s>> {
alt((
map(EmptyElemTag::parse, |empty_elem_tag| {
@ -780,9 +688,7 @@ impl<'s> Parser<'s> for Element<'s> {
/// [12] STag ::= '<' QName (S Attribute)* S? '>'
/// [40] STag ::= '<' Name (S Attribute)* S? '>'
impl<'s> Parser<'s> for STag<'s> {
type Output = STag<'s>;
impl<'s> Parser<'s, STag<'s>> for STag<'s> {
fn parse(input: &'s str) -> IResult<&str, STag<'s>> {
map(
delimited(
@ -796,9 +702,7 @@ impl<'s> Parser<'s> for STag<'s> {
}
/// [15] Attribute ::= NSAttName Eq AttValue | QName Eq AttValue
impl<'s> Parser<'s> for Attribute<'s> {
type Output = Attribute<'s>;
impl<'s> Parser<'s, Attribute<'s>> for Attribute<'s> {
fn parse(input: &'s str) -> IResult<&str, Attribute<'s>> {
alt((
map(
@ -820,9 +724,7 @@ impl<'s> Parser<'s> for Attribute<'s> {
/// [13] ETag ::= '</' QName S? '>'
/// [42] ETag ::= '</' Name S? '>'
impl<'s> Parser<'s> for ETag<'s> {
type Output = ETag<'s>;
impl<'s> Parser<'s, ETag<'s>> for ETag<'s> {
fn parse(input: &'s str) -> IResult<&str, ETag<'s>> {
map(
delimited(tag("</"), QName::parse, pair(opt(S::parse), tag(">"))),
@ -831,9 +733,7 @@ impl<'s> Parser<'s> for ETag<'s> {
}
}
impl<'s> Parser<'s> for ContentItem<'s> {
type Output = ContentItem<'s>;
impl<'s> Parser<'s, ContentItem<'s>> for ContentItem<'s> {
fn parse(input: &'s str) -> IResult<&str, ContentItem<'s>> {
alt((
map(Element::parse, |element| ContentItem::Element(element)),
@ -848,9 +748,7 @@ impl<'s> Parser<'s> for ContentItem<'s> {
}
/// [43] content ::= CharData? ((element | Reference | CDSect | PI | Comment) CharData?)*
impl<'s> Parser<'s> for Content<'s> {
type Output = Content<'s>;
impl<'s> Parser<'s, Content<'s>> for Content<'s> {
fn parse(input: &'s str) -> IResult<&str, Content<'s>> {
map(
pair(
@ -875,9 +773,7 @@ impl<'s> Parser<'s> for Content<'s> {
/// [14] EmptyElemTag ::= '<' QName (S Attribute)* S? '/>'
/// [44] EmptyElemTag ::= '<' Name (S Attribute)* S? '/>' [WFC: Unique Att Spec]
impl<'s> Parser<'s> for EmptyElemTag<'s> {
type Output = EmptyElemTag<'s>;
impl<'s> Parser<'s, EmptyElemTag<'s>> for EmptyElemTag<'s> {
fn parse(input: &'s str) -> IResult<&str, EmptyElemTag<'s>> {
map(
delimited(
@ -892,9 +788,7 @@ impl<'s> Parser<'s> for EmptyElemTag<'s> {
/// [17] elementdecl ::= '<!ELEMENT' S QName S contentspec S? '>'
/// [45] elementdecl ::= '<!ELEMENT' S Name S contentspec S? '>'
impl<'s> Parser<'s> for Elementdecl<'s> {
type Output = Elementdecl<'s>;
impl<'s> Parser<'s, Elementdecl<'s>> for Elementdecl<'s> {
fn parse(input: &'s str) -> IResult<&str, Elementdecl> {
map(
delimited(
@ -908,9 +802,7 @@ impl<'s> Parser<'s> for Elementdecl<'s> {
}
/// [46] contentspec ::= 'EMPTY' | 'ANY' | Mixed | children
impl<'s> Parser<'s> for Contentspec<'s> {
type Output = Contentspec<'s>;
impl<'s> Parser<'s, Contentspec<'s>> for Contentspec<'s> {
fn parse(input: &'s str) -> IResult<&str, Contentspec<'s>> {
alt((
value(Contentspec::Empty, tag("EMPTY")),
@ -922,9 +814,7 @@ impl<'s> Parser<'s> for Contentspec<'s> {
}
/// Occurence ::= ('?' | '*' | '+')?
impl Parser<'_> for Occurence {
type Output = Occurence;
impl Parser<'_, Occurence> for Occurence {
fn parse(input: &'_ str) -> IResult<&str, Occurence> {
map(
opt(alt((tag("?"), tag("*"), tag("+")))),
@ -939,9 +829,7 @@ impl Parser<'_> for Occurence {
}
/// [47] children ::= (choice | seq) ('?' | '*' | '+')?
impl<'s> Parser<'s> for Children<'s> {
type Output = Children<'s>;
impl<'s> Parser<'s, Children<'s>> for Children<'s> {
fn parse(input: &'s str) -> IResult<&str, Children<'s>> {
map(
pair(
@ -958,9 +846,7 @@ impl<'s> Parser<'s> for Children<'s> {
/// [18] cp ::= (QName | choice | seq) ('?' | '*' | '+')?
/// [48] cp ::= (Name | choice | seq) ('?' | '*' | '+')?
impl<'s> Parser<'s> for Cp<'s> {
type Output = Cp<'s>;
impl<'s> Parser<'s, Cp<'s>> for Cp<'s> {
fn parse(input: &'s str) -> IResult<&str, Cp<'s>> {
map(
pair(
@ -977,9 +863,7 @@ impl<'s> Parser<'s> for Cp<'s> {
}
/// [49] choice ::= '(' S? cp ( S? '|' S? cp )+ S? ')'
impl<'s> Parser<'s> for Choice<'s> {
type Output = Choice<'s>;
impl<'s> Parser<'s, Choice<'s>> for Choice<'s> {
fn parse(input: &'s str) -> IResult<&str, Choice<'s>> {
map(
delimited(
@ -1002,9 +886,7 @@ impl<'s> Parser<'s> for Choice<'s> {
}
/// [50] seq ::= '(' S? cp ( S? ',' S? cp )* S? ')'
impl<'s> Parser<'s> for Seq<'s> {
type Output = Seq<'s>;
impl<'s> Parser<'s, Seq<'s>> for Seq<'s> {
fn parse(input: &'s str) -> IResult<&str, Seq<'s>> {
map(
delimited(
@ -1028,9 +910,7 @@ impl<'s> Parser<'s> for Seq<'s> {
/// [19] Mixed ::= '(' S? '#PCDATA' (S? '|' S? QName)* S? ')*' | '(' S? '#PCDATA' S? ')'
/// [51] Mixed ::= '(' S? '#PCDATA' (S? '|' S? Name)* S? ')*' | '(' S? '#PCDATA' S? ')'
impl<'s> Parser<'s> for Mixed<'s> {
type Output = Mixed<'s>;
impl<'s> Parser<'s, Mixed<'s>> for Mixed<'s> {
fn parse(input: &'s str) -> IResult<&str, Mixed<'s>> {
alt((
map(
@ -1060,9 +940,7 @@ impl<'s> Parser<'s> for Mixed<'s> {
/// [20] AttlistDecl ::= '<!ATTLIST' S QName AttDef* S? '>'
/// [52] AttlistDecl ::= '<!ATTLIST' S Name AttDef* S? '>'
impl<'s> Parser<'s> for AttlistDecl<'s> {
type Output = AttlistDecl<'s>;
impl<'s> Parser<'s, AttlistDecl<'s>> for AttlistDecl<'s> {
fn parse(input: &'s str) -> IResult<&str, AttlistDecl<'s>> {
map(
delimited(
@ -1080,9 +958,7 @@ impl<'s> Parser<'s> for AttlistDecl<'s> {
/// [21] AttDef ::= S (QName | NSAttName) S AttType S DefaultDecl
/// [53] AttDef ::= S Name S AttType S DefaultDecl
impl<'s> Parser<'s> for AttDef<'s> {
type Output = AttDef<'s>;
impl<'s> Parser<'s, AttDef<'s>> for AttDef<'s> {
fn parse(input: &'s str) -> IResult<&str, AttDef<'s>> {
map(
tuple((
@ -1108,9 +984,7 @@ impl<'s> Parser<'s> for AttDef<'s> {
}
/// [54] AttType ::= StringType | TokenizedType | EnumeratedType
impl<'s> Parser<'s> for AttType<'s> {
type Output = AttType<'s>;
impl<'s> Parser<'s, AttType<'s>> for AttType<'s> {
fn parse(input: &'s str) -> IResult<&str, AttType<'s>> {
alt((
value(AttType::StringType, StringType::parse),
@ -1125,18 +999,14 @@ impl<'s> Parser<'s> for AttType<'s> {
}
/// [55] StringType ::= 'CDATA'
impl Parser<'_> for StringType {
type Output = StringType;
impl Parser<'_, StringType> for StringType {
fn parse(input: &'_ str) -> IResult<&str, StringType> {
value(StringType, tag("CDATA"))(input)
}
}
/// [56] TokenizedType ::= 'ID' | 'IDREF' | 'IDREFS' | 'ENTITY' | 'ENTITIES' | 'NMTOKEN' | 'NMTOKENS'
impl Parser<'_> for TokenizedType {
type Output = TokenizedType;
impl Parser<'_, TokenizedType> for TokenizedType {
fn parse(input: &'_ str) -> IResult<&str, TokenizedType> {
alt((
value(TokenizedType::ID, tag("ID")),
@ -1154,9 +1024,7 @@ impl Parser<'_> for TokenizedType {
}
/// [57] EnumeratedType ::= NotationType | Enumeration
impl<'s> Parser<'s> for EnumeratedType<'s> {
type Output = EnumeratedType<'s>;
impl<'s> Parser<'s, EnumeratedType<'s>> for EnumeratedType<'s> {
fn parse(input: &'s str) -> IResult<&str, EnumeratedType<'s>> {
alt((
map(NotationType::parse, |notation_type| {
@ -1170,9 +1038,7 @@ impl<'s> Parser<'s> for EnumeratedType<'s> {
}
/// [58] NotationType ::= 'NOTATION' S '(' S? Name (S? '|' S? Name)* S? ')'
impl<'s> Parser<'s> for NotationType<'s> {
type Output = NotationType<'s>;
impl<'s> Parser<'s, NotationType<'s>> for NotationType<'s> {
fn parse(input: &'s str) -> IResult<&str, NotationType<'s>> {
map(
delimited(
@ -1195,9 +1061,7 @@ impl<'s> Parser<'s> for NotationType<'s> {
}
/// [59] Enumeration ::= '(' S? Nmtoken (S? '|' S? Nmtoken)* S? ')'
impl<'s> Parser<'s> for Enumeration<'s> {
type Output = Enumeration<'s>;
impl<'s> Parser<'s, Enumeration<'s>> for Enumeration<'s> {
fn parse(input: &'s str) -> IResult<&str, Enumeration<'s>> {
map(
delimited(
@ -1220,9 +1084,7 @@ impl<'s> Parser<'s> for Enumeration<'s> {
}
/// [60] DefaultDecl ::= '#REQUIRED' | '#IMPLIED' | (('#FIXED' S)? AttValue)
impl<'s> Parser<'s> for DefaultDecl<'s> {
type Output = DefaultDecl<'s>;
impl<'s> Parser<'s, DefaultDecl<'s>> for DefaultDecl<'s> {
fn parse(input: &'s str) -> IResult<&str, DefaultDecl<'s>> {
alt((
value(DefaultDecl::Required, tag("#REQUIRED")),
@ -1236,9 +1098,7 @@ impl<'s> Parser<'s> for DefaultDecl<'s> {
}
/// [61] conditionalSect ::= includeSect | ignoreSect
impl<'s> Parser<'s> for ConditionalSect<'s> {
type Output = ConditionalSect<'s>;
impl<'s> Parser<'s, ConditionalSect<'s>> for ConditionalSect<'s> {
fn parse(input: &'s str) -> IResult<&str, ConditionalSect<'s>> {
alt((
map(IncludeSect::parse, |include_sect| {
@ -1252,9 +1112,7 @@ impl<'s> Parser<'s> for ConditionalSect<'s> {
}
/// [62] includeSect ::= '<![' S? 'INCLUDE' S? '[' extSubsetDecl ']]>'
impl<'s> Parser<'s> for IncludeSect<'s> {
type Output = IncludeSect<'s>;
impl<'s> Parser<'s, IncludeSect<'s>> for IncludeSect<'s> {
fn parse(input: &'s str) -> IResult<&str, IncludeSect<'s>> {
map(
delimited(
@ -1274,9 +1132,7 @@ impl<'s> Parser<'s> for IncludeSect<'s> {
}
/// [63] ignoreSect ::= '<![' S? 'IGNORE' S? '[' ignoreSectContents* ']]>'
impl<'s> Parser<'s> for IgnoreSect<'s> {
type Output = IgnoreSect<'s>;
impl<'s> Parser<'s, IgnoreSect<'s>> for IgnoreSect<'s> {
fn parse(input: &'s str) -> IResult<&str, IgnoreSect<'s>> {
map(
delimited(
@ -1296,9 +1152,7 @@ impl<'s> Parser<'s> for IgnoreSect<'s> {
}
/// [64] ignoreSectContents ::= Ignore ('<![' ignoreSectContents ']]>' Ignore)*
impl<'s> Parser<'s> for IgnoreSectContents<'s> {
type Output = IgnoreSectContents<'s>;
impl<'s> Parser<'s, IgnoreSectContents<'s>> for IgnoreSectContents<'s> {
fn parse(input: &'s str) -> IResult<&str, IgnoreSectContents<'s>> {
map(
pair(
@ -1317,9 +1171,7 @@ impl<'s> Parser<'s> for IgnoreSectContents<'s> {
}
/// [65] Ignore ::= Char* - (Char* ('<![' | ']]>') Char*)
impl<'s> Parser<'s> for Ignore<'s> {
type Output = Ignore<'s>;
impl<'s> Parser<'s, Ignore<'s>> for Ignore<'s> {
fn parse(input: &'s str) -> IResult<&str, Ignore<'s>> {
map(
recognize(many_till(Char::parse, peek(alt((tag("<!["), tag("]]>")))))),
@ -1329,9 +1181,7 @@ impl<'s> Parser<'s> for Ignore<'s> {
}
/// [66] CharRef ::= '&#' [0-9]+ ';' | '&#x' [0-9a-fA-F]+ ';'
impl<'s> Parser<'s> for CharRef<'s> {
type Output = CharRef<'s>;
impl<'s> Parser<'s, CharRef<'s>> for CharRef<'s> {
fn parse(input: &'s str) -> IResult<&str, CharRef<'s>> {
alt((
delimited(
@ -1354,9 +1204,7 @@ impl<'s> Parser<'s> for CharRef<'s> {
}
/// [67] Reference ::= EntityRef | CharRef
impl<'s> Parser<'s> for Reference<'s> {
type Output = Reference<'s>;
impl<'s> Parser<'s, Reference<'s>> for Reference<'s> {
fn parse(input: &'s str) -> IResult<&str, Reference<'s>> {
alt((
map(EntityRef::parse, |entity_ref| {
@ -1368,9 +1216,7 @@ impl<'s> Parser<'s> for Reference<'s> {
}
/// [68] EntityRef ::= '&' Name ';'
impl<'s> Parser<'s> for EntityRef<'s> {
type Output = EntityRef<'s>;
impl<'s> Parser<'s, EntityRef<'s>> for EntityRef<'s> {
fn parse(input: &'s str) -> IResult<&str, EntityRef<'s>> {
map(delimited(tag("&"), Name::parse, tag(";")), |entity_ref| {
EntityRef(entity_ref)
@ -1379,9 +1225,7 @@ impl<'s> Parser<'s> for EntityRef<'s> {
}
/// [69] PEReference ::= '%' Name ';'
impl<'s> Parser<'s> for PEReference<'s> {
type Output = PEReference<'s>;
impl<'s> Parser<'s, PEReference<'s>> for PEReference<'s> {
fn parse(input: &'s str) -> IResult<&str, PEReference<'s>> {
map(delimited(tag("%"), Name::parse, tag(";")), |pe_reference| {
PEReference(pe_reference)
@ -1390,9 +1234,7 @@ impl<'s> Parser<'s> for PEReference<'s> {
}
/// [70] EntityDecl ::= GEDecl | PEDecl
impl<'s> Parser<'s> for EntityDecl<'s> {
type Output = EntityDecl<'s>;
impl<'s> Parser<'s, EntityDecl<'s>> for EntityDecl<'s> {
fn parse(input: &'s str) -> IResult<&str, EntityDecl<'s>> {
alt((
map(GEDecl::parse, |ge_decl| EntityDecl::GEDecl(ge_decl)),
@ -1402,9 +1244,7 @@ impl<'s> Parser<'s> for EntityDecl<'s> {
}
/// [71] GEDecl ::= '<!ENTITY' S Name S EntityDef S? '>'
impl<'s> Parser<'s> for GEDecl<'s> {
type Output = GEDecl<'s>;
impl<'s> Parser<'s, GEDecl<'s>> for GEDecl<'s> {
fn parse(input: &'s str) -> IResult<&str, GEDecl<'s>> {
map(
delimited(
@ -1418,9 +1258,7 @@ impl<'s> Parser<'s> for GEDecl<'s> {
}
/// [72] PEDecl ::= '<!ENTITY' S '%' S Name S PEDef S? '>'
impl<'s> Parser<'s> for PEDecl<'s> {
type Output = PEDecl<'s>;
impl<'s> Parser<'s, PEDecl<'s>> for PEDecl<'s> {
fn parse(input: &'s str) -> IResult<&str, PEDecl<'s>> {
map(
delimited(
@ -1434,9 +1272,7 @@ impl<'s> Parser<'s> for PEDecl<'s> {
}
/// [73] EntityDef ::= EntityValue | (ExternalID NDataDecl?)
impl<'s> Parser<'s> for EntityDef<'s> {
type Output = EntityDef<'s>;
impl<'s> Parser<'s, EntityDef<'s>> for EntityDef<'s> {
fn parse(input: &'s str) -> IResult<&str, EntityDef<'s>> {
alt((
map(EntityValue::parse, |entity_value| {
@ -1454,9 +1290,7 @@ impl<'s> Parser<'s> for EntityDef<'s> {
}
/// [74] PEDef ::= EntityValue | ExternalID
impl<'s> Parser<'s> for PEDef<'s> {
type Output = PEDef<'s>;
impl<'s> Parser<'s, PEDef<'s>> for PEDef<'s> {
fn parse(input: &'s str) -> IResult<&str, PEDef<'s>> {
alt((
map(EntityValue::parse, |entity_value| {
@ -1471,9 +1305,7 @@ 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> {
impl<'s> Parser<'s> for ExternalID<'s> {
type Output = ExternalID<'s>;
impl<'s> Parser<'s, ExternalID<'s>> for ExternalID<'s> {
fn parse(input: &'s str) -> IResult<&str, ExternalID<'s>> {
alt((
map(
@ -1495,9 +1327,7 @@ impl<'s> Parser<'s> for ExternalID<'s> {
}
/// [76] NDataDecl ::= S 'NDATA' S Name
impl<'s> Parser<'s> for NDataDecl<'s> {
type Output = NDataDecl<'s>;
impl<'s> Parser<'s, NDataDecl<'s>> for NDataDecl<'s> {
fn parse(input: &'s str) -> IResult<&str, NDataDecl<'s>> {
map(
preceded(tuple((S::parse, tag("NDATA"), S::parse)), Name::parse),
@ -1507,9 +1337,7 @@ impl<'s> Parser<'s> for NDataDecl<'s> {
}
/// [77] TextDecl ::= '<?xml' VersionInfo? EncodingDecl S? '?>'
impl<'s> Parser<'s> for TextDecl<'s> {
type Output = TextDecl<'s>;
impl<'s> Parser<'s, TextDecl<'s>> for TextDecl<'s> {
fn parse(input: &'s str) -> IResult<&str, TextDecl<'s>> {
map(
delimited(
@ -1529,9 +1357,7 @@ impl<'s> Parser<'s> for TextDecl<'s> {
}
/// [78] extParsedEnt ::= TextDecl? content
impl<'s> Parser<'s> for ExtParsedEnt<'s> {
type Output = ExtParsedEnt<'s>;
impl<'s> Parser<'s, ExtParsedEnt<'s>> for ExtParsedEnt<'s> {
fn parse(input: &'s str) -> IResult<&str, ExtParsedEnt<'s>> {
map(
pair(opt(TextDecl::parse), Content::parse),
@ -1541,9 +1367,7 @@ impl<'s> Parser<'s> for ExtParsedEnt<'s> {
}
/// [80] EncodingDecl ::= S 'encoding' Eq ('"' EncName '"' | "'" EncName
impl<'s> Parser<'s> for EncodingDecl<'s> {
type Output = EncodingDecl<'s>;
impl<'s> Parser<'s, EncodingDecl<'s>> for EncodingDecl<'s> {
fn parse(input: &'s str) -> IResult<&str, EncodingDecl<'s>> {
map(
preceded(
@ -1559,9 +1383,7 @@ impl<'s> Parser<'s> for EncodingDecl<'s> {
}
/// [81] EncName ::= [A-Za-z] ([A-Za-z0-9._] | '-')*
impl<'s> Parser<'s> for EncName<'s> {
type Output = EncName<'s>;
impl<'s> Parser<'s, EncName<'s>> for EncName<'s> {
fn parse(input: &'s str) -> IResult<&str, EncName<'s>> {
map(
recognize(pair(
@ -1576,9 +1398,7 @@ impl<'s> Parser<'s> for EncName<'s> {
}
/// [82] NotationDecl ::= '<!NOTATION' S Name S (ExternalID | PublicID) S? '>'
impl<'s> Parser<'s> for NotationDecl<'s> {
type Output = NotationDecl<'s>;
impl<'s> Parser<'s, NotationDecl<'s>> for NotationDecl<'s> {
fn parse(input: &'s str) -> IResult<&str, NotationDecl<'s>> {
map(
delimited(
@ -1603,9 +1423,7 @@ impl<'s> Parser<'s> for NotationDecl<'s> {
}
/// [83] PublicID ::= 'PUBLIC' S PubidLiteral
impl<'s> Parser<'s> for PublicID<'s> {
type Output = PublicID<'s>;
impl<'s> Parser<'s, PublicID<'s>> for PublicID<'s> {
fn parse(input: &'s str) -> IResult<&str, PublicID<'s>> {
map(
preceded(pair(tag("PUBLIC"), S::parse), PubidLiteral::parse),

File diff suppressed because it is too large Load Diff