diff options
Diffstat (limited to 'src/xml/composers.rs')
-rw-r--r-- | src/xml/composers.rs | 1216 |
1 files changed, 1207 insertions, 9 deletions
diff --git a/src/xml/composers.rs b/src/xml/composers.rs index 8299708..a47f007 100644 --- a/src/xml/composers.rs +++ b/src/xml/composers.rs @@ -1,4 +1,7 @@ -use std::io; +use std::{ + fmt::{self, Display, Formatter, Write}, + io, +}; use tokio::io::{AsyncWrite, AsyncWriteExt}; @@ -144,9 +147,9 @@ impl<'s> Composer<'s> for Document<'s> { where W: Unpin + AsyncWrite, { - self.0.write(writer).await?; - self.1.write(writer).await?; - for misc in &self.2 { + self.prolog.write(writer).await?; + self.element.write(writer).await?; + for misc in &self.miscs { misc.write(writer).await? } Ok(()) @@ -490,13 +493,13 @@ impl<'s> Composer<'s> for Prolog<'s> { where W: Unpin + AsyncWrite, { - if let Some(xml_decl) = &self.0 { + if let Some(xml_decl) = &self.xml_decl { xml_decl.write(writer).await?; } - for misc in &self.1 { + for misc in &self.miscs { misc.write(writer).await?; } - if let Some((doctype_decl, miscs)) = &self.2 { + if let Some((doctype_decl, miscs)) = &self.doctype_decl { doctype_decl.write(writer).await?; for misc in miscs { misc.write(writer).await?; @@ -634,7 +637,7 @@ impl<'s> Composer<'s> for IntSubset<'s> { where W: Unpin + AsyncWrite, { - for declaration in self { + for declaration in &self.0 { match declaration { super::IntSubsetDeclaration::MarkupDecl(markup_decl) => { markup_decl.write(writer).await? @@ -684,7 +687,7 @@ impl<'s> Composer<'s> for ExtSubsetDecl<'s> { where W: Unpin + AsyncWrite, { - for declaration in self { + for declaration in &self.0 { match declaration { ExtSubsetDeclaration::MarkupDecl(markup_decl) => markup_decl.write(writer).await?, ExtSubsetDeclaration::ConditionalSect(conditional_sect) => { @@ -1495,3 +1498,1198 @@ impl<'s> Composer<'s> for PublicID<'s> { Ok(()) } } + +/// [1] NSAttName ::= PrefixedAttName | DefaultAttName +impl<'s> Display for NSAttName<'s> { + fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result { + match self { + NSAttName::PrefixedAttName(prefixed_att_name) => prefixed_att_name.fmt(f)?, + NSAttName::DefaultAttName => DefaultAttName.fmt(f)?, + } + Ok(()) + } +} + +/// [2] PrefixedAttName ::= 'xmlns:' NCName +impl<'s> Display for PrefixedAttName<'s> { + fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result { + f.write_str("xmlns:")?; + self.0.fmt(f)?; + Ok(()) + } +} + +/// [3] DefaultAttName ::= 'xmlns'; +impl Display for DefaultAttName { + fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result { + f.write_str("xmlns")?; + Ok(()) + } +} + +/// [4] NCName ::= Name - (Char* ':' Char*) +impl<'s> Display for NCName<'s> { + fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result { + f.write_str(self.0)?; + Ok(()) + } +} + +/// [7] QName ::= PrefixedName | UnprefixedName +impl<'s> Display for QName<'s> { + fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result { + match self { + QName::PrefixedName(prefixed_name) => prefixed_name.fmt(f)?, + QName::UnprefixedName(unprefixed_name) => unprefixed_name.fmt(f)?, + } + Ok(()) + } +} + +/// [8] PrefixedName ::= Prefix ':' LocalPart +impl<'s> Display for PrefixedName<'s> { + fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result { + self.prefix.fmt(f)?; + f.write_str(":")?; + self.local_part.fmt(f)?; + Ok(()) + } +} + +/// [9] UnprefixedName ::= LocalPart +impl<'s> Display for UnprefixedName<'s> { + fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result { + self.0.fmt(f)?; + Ok(()) + } +} + +/// [10] Prefix ::= NCName +impl<'s> Display for Prefix<'s> { + fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result { + self.0.fmt(f)?; + Ok(()) + } +} + +/// [11] LocalPart ::= NCName +impl<'s> Display for LocalPart<'s> { + fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result { + self.0.fmt(f)?; + Ok(()) + } +} + +// xml spec + +/// [1] document ::= prolog element Misc* +impl<'s> Display for Document<'s> { + fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result { + self.prolog.fmt(f)?; + self.element.fmt(f)?; + for misc in &self.miscs { + misc.fmt(f)? + } + Ok(()) + } +} + +/// [2] Char ::= #x9 | #xA | #xD | [#x20-#xD7FF] | [#xE000-#xFFFD] | [#x10000-#x10FFFF] /* any Unicode character, excluding the surrogate blocks, FFFE, and FFFF. */ +impl Display for Char { + fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result { + f.write_char(self.0)?; + Ok(()) + } +} + +/// [3] S ::= (#x20 | #x9 | #xD | #xA)+ +impl<'s> Display for S { + fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result { + f.write_str("\u{20}")?; + Ok(()) + } +} + +/// [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 Display for NameStartChar { + fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result { + f.write_char(self.0)?; + Ok(()) + } +} + +/// [4a] NameChar ::= NameStartChar | "-" | "." | [0-9] | #xB7 | [#x0300-#x036F] | [#x203F-#x2040] +impl Display for NameChar { + fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result { + f.write_char(self.0)?; + Ok(()) + } +} + +/// [5] Name ::= NameStartChar (NameChar)* +impl<'s> Display for Name<'s> { + fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result { + f.write_str(self.0)?; + Ok(()) + } +} + +/// [6] Names ::= Name (#x20 Name)* +impl<'s> Display for Names<'s> { + fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result { + let mut first = true; + for name in &self.0 { + if !first { + f.write_str("\u{20}")?; + } + name.fmt(f)?; + if first { + first = false + } + } + Ok(()) + } +} + +/// [7] Nmtoken ::= (NameChar)+ +impl<'s> Display for Nmtoken<'s> { + fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result { + f.write_str(self.0)?; + Ok(()) + } +} + +/// [8] Nmtokens ::= Nmtoken (#x20 Nmtoken)* +impl<'s> Display for Nmtokens<'s> { + fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result { + let mut first = true; + for nmtoken in &self.0 { + if !first { + f.write_str("\u{20}")?; + } + nmtoken.fmt(f)?; + if first { + first = false + } + } + Ok(()) + } +} + +/// [9] EntityValue ::= '"' ([^%&"] | PEReference | Reference)* '"' +/// | "'" ([^%&'] | PEReference | Reference)* "'" +impl<'s> Display for EntityValue<'s> { + fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result { + match self { + EntityValue::DoubleQuoted(entity_value_data) => { + f.write_str("\"")?; + for entity_value_data in entity_value_data { + match entity_value_data { + EntityValueData::String(s) => f.write_str(s)?, + EntityValueData::PEReference(pe_reference) => pe_reference.fmt(f)?, + EntityValueData::Reference(reference) => reference.fmt(f)?, + } + } + f.write_str("\"")?; + } + EntityValue::SingleQuoted(entity_value_data) => { + f.write_str("'")?; + for entity_value_data in entity_value_data { + match entity_value_data { + EntityValueData::String(s) => f.write_str(s)?, + EntityValueData::PEReference(pe_reference) => pe_reference.fmt(f)?, + EntityValueData::Reference(reference) => reference.fmt(f)?, + } + } + f.write_str("'")?; + } + } + Ok(()) + } +} + +/// [10] AttValue ::= '"' ([^<&"] | Reference)* '"' +/// | "'" ([^<&'] | Reference)* "'" +impl<'s> Display for AttValue<'s> { + fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result { + match self { + AttValue::DoubleQuoted(att_value_data) => { + f.write_str("\"")?; + for att_value_data in att_value_data { + match att_value_data { + AttValueData::String(s) => f.write_str(s)?, + AttValueData::Reference(reference) => reference.fmt(f)?, + } + } + f.write_str("\"")?; + } + AttValue::SingleQuoted(att_value_data) => { + f.write_str("'")?; + for att_value_data in att_value_data { + match att_value_data { + AttValueData::String(s) => f.write_str(s)?, + AttValueData::Reference(reference) => reference.fmt(f)?, + } + } + f.write_str("'")?; + } + } + Ok(()) + } +} + +/// [11] SystemLiteral ::= ('"' [^"]* '"') | ("'" [^']* "'") +impl<'s> Display for SystemLiteral<'s> { + fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result { + match self { + SystemLiteral::DoubleQuoted(s) => { + f.write_str("\"")?; + f.write_str(s)?; + f.write_str("\"")?; + } + SystemLiteral::SingleQuoted(s) => { + f.write_str("'")?; + f.write_str(s)?; + f.write_str("'")?; + } + } + Ok(()) + } +} + +/// [12] PubidLiteral ::= '"' PubidChar* '"' | "'" (PubidChar - "'")* "'" +impl<'s> Display for PubidLiteral<'s> { + fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result { + match self { + PubidLiteral::DoubleQuoted(s) => { + f.write_str("\"")?; + f.write_str(s)?; + f.write_str("\"")?; + } + PubidLiteral::SingleQuoted(s) => { + f.write_str("'")?; + f.write_str(s)?; + f.write_str("'")?; + } + } + Ok(()) + } +} + +/// [13] PubidChar ::= #x20 | #xD | #xA | [a-zA-Z0-9] | [-'()+,./:=?;!*#@$_%] +impl Display for PubidChar { + fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result { + f.write_char(self.0)?; + Ok(()) + } +} + +/// [14] CharData ::= [^<&]* - ([^<&]* ']]>' [^<&]*) +impl<'s> Display for CharData<'s> { + fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result { + f.write_str(self.0)?; + Ok(()) + } +} + +/// [15] Comment ::= '<!--' ((Char - '-') | ('-' (Char - '-')))* '-->' +impl<'s> Display for Comment<'s> { + fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result { + f.write_str("<!--")?; + f.write_str(self.0)?; + f.write_str("-->")?; + Ok(()) + } +} + +/// [16] PI ::= '<?' PITarget (S (Char* - (Char* '?>' Char*)))? '?>' +impl<'s> Display for PI<'s> { + fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result { + f.write_str("<?")?; + self.target.fmt(f)?; + if let Some(instruction) = self.instruction { + S.fmt(f)?; + f.write_str(instruction)?; + } + f.write_str("?>")?; + Ok(()) + } +} + +/// [17] PITarget ::= Name - (('X' | 'x') ('M' | 'm') ('L' | 'l')) +impl<'s> Display for PITarget<'s> { + fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result { + self.0.fmt(f)?; + Ok(()) + } +} + +/// [18] CDSect ::= CDStart CData CDEnd +impl<'s> Display for CDSect<'s> { + fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result { + CDStart.fmt(f)?; + self.0.fmt(f)?; + CDEnd.fmt(f)?; + Ok(()) + } +} + +/// [19] CDStart ::= '<![CDATA[' +impl Display for CDStart { + fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result { + f.write_str("<![CDATA[")?; + Ok(()) + } +} + +/// [20] CData ::= (Char* - (Char* ']]>' Char*)) +impl<'s> Display for CData<'s> { + fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result { + f.write_str(self.0)?; + Ok(()) + } +} + +/// [21] CDEnd ::= ']]>' +impl Display for CDEnd { + fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result { + f.write_str("]]>")?; + Ok(()) + } +} + +/// [22] prolog ::= XMLDecl? Misc* (doctypedecl Misc*)? +impl<'s> Display for Prolog<'s> { + fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result { + if let Some(xml_decl) = &self.xml_decl { + xml_decl.fmt(f)?; + } + for misc in &self.miscs { + misc.fmt(f)?; + } + if let Some((doctype_decl, miscs)) = &self.doctype_decl { + doctype_decl.fmt(f)?; + for misc in miscs { + misc.fmt(f)?; + } + } + Ok(()) + } +} + +/// [23] XMLDecl ::= '<?xml' VersionInfo EncodingDecl? SDDecl? S? '?>' +impl<'s> Display for XMLDecl<'s> { + fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result { + f.write_str("<?xml")?; + self.version_info.fmt(f)?; + if let Some(encoding_decl) = &self.encoding_decl { + encoding_decl.fmt(f)? + } + if let Some(sd_decl) = &self.sd_decl { + sd_decl.fmt(f)? + } + f.write_str("?>")?; + Ok(()) + } +} + +/// [24] VersionInfo ::= S 'version' Eq ("'" VersionNum "'" | '"' VersionNum '"') +impl Display for VersionInfo { + fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result { + S.fmt(f)?; + f.write_str("version")?; + Eq.fmt(f)?; + match self { + VersionInfo::SingleQuoted(version_num) => { + f.write_str("'")?; + version_num.fmt(f)?; + f.write_str("'")?; + } + VersionInfo::DoubleQuoted(version_num) => { + f.write_str("\"")?; + version_num.fmt(f)?; + f.write_str("\"")?; + } + } + Ok(()) + } +} + +/// [25] Eq ::= S? '=' S? +impl Display for Eq { + fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result { + f.write_str("=")?; + Ok(()) + } +} + +/// [26] VersionNum ::= '1.' [0-9]+ +impl Display for VersionNum { + fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result { + match self { + VersionNum::One => f.write_str("1.0")?, + VersionNum::OneDotOne => f.write_str("1.1")?, + } + Ok(()) + } +} + +/// [27] Misc ::= Comment | PI | S +impl<'s> Display for Misc<'s> { + fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result { + match self { + Misc::Comment(comment) => comment.fmt(f)?, + Misc::PI(pi) => pi.fmt(f)?, + Misc::S => {} + } + Ok(()) + } +} + +/// [16] doctypedecl ::= '<!DOCTYPE' S QName (S ExternalID)? S? ('[' (markupdecl | PEReference | S)* ']' S?)? '>' +/// [28] doctypedecl ::= '<!DOCTYPE' S Name (S ExternalID)? S? ('[' intSubset ']' S?)? '>' +impl<'s> Display for DoctypeDecl<'s> { + fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result { + f.write_str("<!DOCTYPE")?; + S.fmt(f)?; + self.name.fmt(f)?; + if let Some(external_id) = &self.external_id { + S.fmt(f)?; + external_id.fmt(f)?; + } + if let Some(int_subset) = &self.int_subset { + f.write_str("[")?; + int_subset.fmt(f)?; + f.write_str("]")?; + } + f.write_str(">")?; + Ok(()) + } +} + +/// [28a] DeclSep ::= PEReference | S +impl<'s> Display for DeclSep<'s> { + fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result { + match self { + DeclSep::PEReference(pe_reference) => pe_reference.fmt(f)?, + DeclSep::S => S.fmt(f)?, + } + Ok(()) + } +} + +/// [28b] intSubset ::= (markupdecl | DeclSep)* +impl<'s> Display for IntSubset<'s> { + fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result { + for declaration in &self.0 { + match declaration { + super::IntSubsetDeclaration::MarkupDecl(markup_decl) => markup_decl.fmt(f)?, + super::IntSubsetDeclaration::DeclSep(decl_sep) => decl_sep.fmt(f)?, + } + } + Ok(()) + } +} + +/// [29] markupdecl ::= elementdecl | AttlistDecl | EntityDecl | NotationDecl | PI | Comment +impl<'s> Display for MarkupDecl<'s> { + fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result { + match self { + MarkupDecl::Elementdecl(elementdecl) => elementdecl.fmt(f)?, + MarkupDecl::AttlistDecl(attlist_decl) => attlist_decl.fmt(f)?, + MarkupDecl::EntityDecl(entity_decl) => entity_decl.fmt(f)?, + MarkupDecl::NotationDecl(notation_decl) => notation_decl.fmt(f)?, + MarkupDecl::PI(pi) => pi.fmt(f)?, + MarkupDecl::Comment(comment) => comment.fmt(f)?, + } + Ok(()) + } +} + +/// [30] extSubset ::= TextDecl? extSubsetDecl +impl<'s> Display for ExtSubset<'s> { + fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result { + if let Some(text_decl) = &self.text_decl { + text_decl.fmt(f)? + } + self.ext_subset_decl.fmt(f)?; + Ok(()) + } +} + +/// [31] extSubsetDecl ::= ( markupdecl | conditionalSect | DeclSep)* +impl<'s> Display for ExtSubsetDecl<'s> { + fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result { + for declaration in &self.0 { + match declaration { + ExtSubsetDeclaration::MarkupDecl(markup_decl) => markup_decl.fmt(f)?, + ExtSubsetDeclaration::ConditionalSect(conditional_sect) => { + conditional_sect.fmt(f)? + } + ExtSubsetDeclaration::DeclSep(decl_sep) => decl_sep.fmt(f)?, + } + } + Ok(()) + } +} + +/// [32] SDDecl ::= S 'standalone' Eq (("'" ('yes' | 'no') "'") | ('"' ('yes' | 'no') '"')) +impl Display for SDDecl { + fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result { + S.fmt(f)?; + f.write_str("standalone")?; + Eq.fmt(f)?; + match self { + SDDecl::SingleQuoted(sd_decl) => { + f.write_str("'")?; + match sd_decl { + true => f.write_str("yes")?, + false => f.write_str("no")?, + } + f.write_str("'")?; + } + SDDecl::DoubleQuoted(sd_decl) => { + f.write_str("\"")?; + match sd_decl { + true => f.write_str("yes")?, + false => f.write_str("no")?, + } + f.write_str("\"")?; + } + } + Ok(()) + } +} + +// (Productions 33 through 38 have been removed.) + +/// [39] element ::= EmptyElemTag | STag content ETag +impl<'s> Display for Element<'s> { + fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result { + match self { + Element::Empty(empty_elem_tag) => empty_elem_tag.fmt(f)?, + Element::NotEmpty(s_tag, content, e_tag) => { + s_tag.fmt(f)?; + content.fmt(f)?; + e_tag.fmt(f)?; + } + } + Ok(()) + } +} + +/// [12] STag ::= '<' QName (S Attribute)* S? '>' +/// [40] STag ::= '<' Name (S Attribute)* S? '>' +impl<'s> Display for STag<'s> { + fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result { + f.write_str("<")?; + self.name.fmt(f)?; + for attribute in &self.attributes { + S.fmt(f)?; + attribute.fmt(f)?; + } + f.write_str(">")?; + Ok(()) + } +} + +/// [15] Attribute ::= NSAttName Eq AttValue | QName Eq AttValue +impl<'s> Display for Attribute<'s> { + fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result { + match self { + Attribute::NamespaceDeclaration { ns_name, value } => { + ns_name.fmt(f)?; + Eq.fmt(f)?; + value.fmt(f)?; + } + Attribute::Attribute { name, value } => { + name.fmt(f)?; + Eq.fmt(f)?; + value.fmt(f)?; + } + } + Ok(()) + } +} + +/// [13] ETag ::= '</' QName S? '>' +impl<'s> Display for ETag<'s> { + fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result { + f.write_str("</")?; + self.name.fmt(f)?; + f.write_str(">")?; + Ok(()) + } +} + +/// [43] content ::= CharData? ((element | Reference | CDSect | PI | Comment) CharData?)* +impl<'s> Display for Content<'s> { + fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result { + if let Some(char_data) = &self.char_data { + char_data.fmt(f)?; + } + for (content, char_data) in &self.content { + match content { + ContentItem::Element(element) => element.fmt(f)?, + ContentItem::Reference(reference) => reference.fmt(f)?, + ContentItem::CDSect(cd_sect) => cd_sect.fmt(f)?, + ContentItem::PI(pi) => pi.fmt(f)?, + ContentItem::Comment(comment) => comment.fmt(f)?, + // TODO: verify no split chardata + // _ => todo!("verify no split chardata"), + } + if let Some(char_data) = char_data { + char_data.fmt(f)?; + } + } + Ok(()) + } +} + +/// [14] EmptyElemTag ::= '<' QName (S Attribute)* S? '/>' +impl<'s> Display for EmptyElemTag<'s> { + fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result { + f.write_str("<")?; + self.name.fmt(f)?; + for attribute in &self.attributes { + S.fmt(f)?; + attribute.fmt(f)?; + } + f.write_str("/>")?; + Ok(()) + } +} + +/// [17] elementdecl ::= '<!ELEMENT' S QName S contentspec S? '>' +impl<'s> Display for Elementdecl<'s> { + fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result { + f.write_str("<!ELEMENT")?; + S.fmt(f)?; + self.name.fmt(f)?; + S.fmt(f)?; + self.contentspec.fmt(f)?; + f.write_str(">")?; + Ok(()) + } +} + +/// [46] contentspec ::= 'EMPTY' | 'ANY' | Mixed | children +impl<'s> Display for Contentspec<'s> { + fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result { + match self { + Contentspec::Empty => f.write_str("EMPTY")?, + Contentspec::Any => f.write_str("ANY")?, + Contentspec::Mixed(mixed) => mixed.fmt(f)?, + Contentspec::Children(children) => children.fmt(f)?, + } + Ok(()) + } +} + +/// Occurence ::= ('?' | '*' | '+')? +impl Display for Occurence { + fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result { + match self { + Occurence::Once => {} + Occurence::Optional => f.write_str("?")?, + Occurence::Many0 => f.write_str("*")?, + Occurence::Many1 => f.write_str("+")?, + } + Ok(()) + } +} + +/// [47] children ::= (choice | seq) ('?' | '*' | '+')? +impl<'s> Display for Children<'s> { + fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result { + match &self.kind { + ChildrenKind::Choice(choice) => choice.fmt(f)?, + ChildrenKind::Seq(seq) => seq.fmt(f)?, + } + self.occurence.fmt(f)?; + Ok(()) + } +} + +/// [18] cp ::= (QName | choice | seq) ('?' | '*' | '+')? +impl<'s> Display for Cp<'s> { + fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result { + match &self.kind { + CpKind::Name(q_name) => q_name.fmt(f)?, + CpKind::Choice(choice) => choice.fmt(f)?, + CpKind::Seq(seq) => seq.fmt(f)?, + } + self.occurence.fmt(f)?; + Ok(()) + } +} + +/// [49] choice ::= '(' S? cp ( S? '|' S? cp )+ S? ')' +impl<'s> Display for Choice<'s> { + fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result { + f.write_str("(")?; + let mut first = true; + for cp in &self.0 { + if !first { + f.write_str("|")?; + } + cp.fmt(f)?; + if first { + first = false + } + } + f.write_str(")")?; + Ok(()) + } +} + +/// [50] seq ::= '(' S? cp ( S? ',' S? cp )* S? ')' +impl<'s> Display for Seq<'s> { + fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result { + f.write_str("(")?; + let mut first = true; + for cp in &self.0 { + if !first { + f.write_str(",")?; + } + cp.fmt(f)?; + if first { + first = false + } + } + f.write_str(")")?; + Ok(()) + } +} + +/// [19] Mixed ::= '(' S? '#PCDATA' (S? '|' S? QName)* S? ')*' | '(' S? '#PCDATA' S? ')' +impl<'s> Display for Mixed<'s> { + fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result { + f.write_str("(#PCDATA")?; + if !self.0.is_empty() { + for q_name in &self.0 { + f.write_str("|")?; + q_name.fmt(f)?; + } + f.write_str(")*")?; + } else { + f.write_str(")")?; + } + Ok(()) + } +} + +/// [20] AttlistDecl ::= '<!ATTLIST' S QName AttDef* S? '>' +impl<'s> Display for AttlistDecl<'s> { + fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result { + f.write_str("<!ATTLIST")?; + S.fmt(f)?; + self.element_type.fmt(f)?; + for att_def in &self.att_defs { + att_def.fmt(f)?; + } + f.write_str(">")?; + Ok(()) + } +} + +/// [21] AttDef ::= S (QName | NSAttName) S AttType S DefaultDecl +impl<'s> Display for AttDef<'s> { + fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result { + S.fmt(f)?; + match &self.name { + AttDefName::QName(q_name) => q_name.fmt(f)?, + AttDefName::NSAttName(ns_att_name) => ns_att_name.fmt(f)?, + } + S.fmt(f)?; + self.att_type.fmt(f)?; + S.fmt(f)?; + self.default_decl.fmt(f)?; + Ok(()) + } +} + +/// [54] AttType ::= StringType | TokenizedType | EnumeratedType +impl<'s> Display for AttType<'s> { + fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result { + match self { + AttType::StringType => StringType.fmt(f)?, + AttType::TokenizedType(tokenized_type) => tokenized_type.fmt(f)?, + AttType::EnumeratedType(enumerated_type) => enumerated_type.fmt(f)?, + } + Ok(()) + } +} + +/// [55] StringType ::= 'CDATA' +impl Display for StringType { + fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result { + f.write_str("CDATA")?; + Ok(()) + } +} + +/// [56] TokenizedType ::= 'ID' | 'IDREF' | 'IDREFS' | 'ENTITY' | 'ENTITIES' | 'NMTOKEN' | 'NMTOKENS' +impl Display for TokenizedType { + fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result { + match self { + TokenizedType::ID => f.write_str("ID")?, + TokenizedType::IDRef => f.write_str("IDREF")?, + TokenizedType::IDRefs => f.write_str("IDREFS")?, + TokenizedType::Entity => f.write_str("ENTITY")?, + TokenizedType::Entities => f.write_str("ENTITIES")?, + TokenizedType::NMToken => f.write_str("NMTOKEN")?, + TokenizedType::NMTokens => f.write_str("NMTOKENS")?, + } + Ok(()) + } +} + +/// [57] EnumeratedType ::= NotationType | Enumeration +impl<'s> Display for EnumeratedType<'s> { + fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result { + match self { + EnumeratedType::NotationType(notation_type) => notation_type.fmt(f)?, + EnumeratedType::Enumeration(enumeration) => enumeration.fmt(f)?, + } + Ok(()) + } +} + +/// [58] NotationType ::= 'NOTATION' S '(' S? Name (S? '|' S? Name)* S? ')' +impl<'s> Display for NotationType<'s> { + fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result { + f.write_str("NOTATION")?; + S.fmt(f)?; + f.write_str("(")?; + let mut first = true; + for name in &self.0 { + if !first { + f.write_str("|")?; + } + name.fmt(f)?; + if first { + first = false + } + } + f.write_str(")")?; + Ok(()) + } +} + +/// [59] Enumeration ::= '(' S? Nmtoken (S? '|' S? Nmtoken)* S? ')' +impl<'s> Display for Enumeration<'s> { + fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result { + f.write_str("(")?; + let mut first = true; + for nm_token in &self.0 { + if !first { + f.write_str("|")?; + } + nm_token.fmt(f)?; + if first { + first = false + } + } + f.write_str(")")?; + Ok(()) + } +} + +/// [60] DefaultDecl ::= '#REQUIRED' | '#IMPLIED' | (('#FIXED' S)? AttValue) +impl<'s> Display for DefaultDecl<'s> { + fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result { + match self { + DefaultDecl::Required => f.write_str("#REQUIRED")?, + DefaultDecl::Implied => f.write_str("#IMPLIED")?, + DefaultDecl::Fixed(fixed, att_value) => { + if *fixed { + f.write_str("#FIXED")?; + S.fmt(f)?; + } + att_value.fmt(f)? + } + } + Ok(()) + } +} + +/// [61] conditionalSect ::= includeSect | ignoreSect +impl<'s> Display for ConditionalSect<'s> { + fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result { + match self { + ConditionalSect::IncludeSect(include_sect) => include_sect.fmt(f)?, + ConditionalSect::IgnoreSect(ignore_sect) => ignore_sect.fmt(f)?, + } + Ok(()) + } +} + +/// [62] includeSect ::= '<![' S? 'INCLUDE' S? '[' extSubsetDecl ']]>' +impl<'s> Display for IncludeSect<'s> { + fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result { + f.write_str("<![INCLUDE[")?; + self.0.fmt(f)?; + f.write_str("]]>")?; + Ok(()) + } +} + +/// [63] ignoreSect ::= '<![' S? 'IGNORE' S? '[' ignoreSectContents* ']]>' +impl<'s> Display for IgnoreSect<'s> { + fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result { + f.write_str("<![IGNORE[")?; + for ignore_sect_contents in &self.0 { + ignore_sect_contents.fmt(f)?; + } + f.write_str("]]>")?; + Ok(()) + } +} + +/// [64] ignoreSectContents ::= Ignore ('<![' ignoreSectContents ']]>' Ignore)* +impl<'s> Display for IgnoreSectContents<'s> { + fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result { + self.ignore.fmt(f)?; + for (ignore_sect_contents, ignore) in &self.ignore_list { + f.write_str("<![")?; + ignore_sect_contents.fmt(f)?; + f.write_str("]]>")?; + ignore.fmt(f)?; + } + Ok(()) + } +} + +/// [65] Ignore ::= Char* - (Char* ('<![' | ']]>') Char*) +impl<'s> Display for Ignore<'s> { + fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result { + f.write_str(self.0)?; + Ok(()) + } +} + +/// [66] CharRef ::= '&#' [0-9]+ ';' | '&#x' [0-9a-fA-F]+ ';' +impl<'s> Display for CharRef<'s> { + fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result { + match self { + CharRef::Decimal(decimal) => { + f.write_str("&#")?; + f.write_str(decimal)?; + f.write_str(";")?; + } + CharRef::Hexadecimal(hexadecimal) => { + f.write_str("&#x")?; + f.write_str(hexadecimal)?; + f.write_str(";")?; + } + } + Ok(()) + } +} + +/// [67] Reference ::= EntityRef | CharRef +impl<'s> Display for Reference<'s> { + fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result { + match self { + Reference::EntityRef(entity_ref) => entity_ref.fmt(f)?, + Reference::CharRef(char_ref) => char_ref.fmt(f)?, + } + Ok(()) + } +} + +/// [68] EntityRef ::= '&' Name ';' +impl<'s> Display for EntityRef<'s> { + fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result { + f.write_str("&")?; + self.0.fmt(f)?; + f.write_str(";")?; + Ok(()) + } +} + +/// [69] PEReference ::= '%' Name ';' +impl<'s> Display for PEReference<'s> { + fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result { + f.write_str("%")?; + self.0.fmt(f)?; + f.write_str(";")?; + Ok(()) + } +} + +/// [70] EntityDecl ::= GEDecl | PEDecl +impl<'s> Display for EntityDecl<'s> { + fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result { + match self { + EntityDecl::GEDecl(ge_decl) => ge_decl.fmt(f)?, + EntityDecl::PEDecl(pe_decl) => pe_decl.fmt(f)?, + } + Ok(()) + } +} + +/// [71] GEDecl ::= '<!ENTITY' S Name S EntityDef S? '>' +impl<'s> Display for GEDecl<'s> { + fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result { + f.write_str("<!ENTITY")?; + S.fmt(f)?; + self.name.fmt(f)?; + S.fmt(f)?; + self.entity_def.fmt(f)?; + f.write_str(">")?; + Ok(()) + } +} + +/// [72] PEDecl ::= '<!ENTITY' S '%' S Name S PEDef S? '>' +impl<'s> Display for PEDecl<'s> { + fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result { + f.write_str("<!ENTITY")?; + S.fmt(f)?; + f.write_str("%")?; + S.fmt(f)?; + self.name.fmt(f)?; + S.fmt(f)?; + self.pe_def.fmt(f)?; + f.write_str(">")?; + Ok(()) + } +} + +/// [73] EntityDef ::= EntityValue | (ExternalID NDataDecl?) +impl<'s> Display for EntityDef<'s> { + fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result { + match self { + EntityDef::EntityValue(entity_value) => entity_value.fmt(f)?, + EntityDef::ExternalID { + external_id, + n_data_decl, + } => { + external_id.fmt(f)?; + if let Some(n_data_decl) = n_data_decl { + n_data_decl.fmt(f)?; + } + } + } + Ok(()) + } +} + +/// [74] PEDef ::= EntityValue | ExternalID +impl<'s> Display for PEDef<'s> { + fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result { + match self { + PEDef::EntityValue(entity_value) => entity_value.fmt(f)?, + PEDef::ExternalID(external_id) => external_id.fmt(f)?, + } + Ok(()) + } +} + +/// [75] ExternalID ::= 'SYSTEM' S SystemLiteral | 'PUBLIC' S PubidLiteral S SystemLiteral +impl<'s> Display for ExternalID<'s> { + fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result { + match self { + ExternalID::SYSTEM { system_identifier } => { + f.write_str("SYSTEM")?; + S.fmt(f)?; + system_identifier.fmt(f)?; + } + ExternalID::PUBLIC { + public_identifier, + system_identifier, + } => { + f.write_str("PUBLIC")?; + S.fmt(f)?; + public_identifier.fmt(f)?; + S.fmt(f)?; + system_identifier.fmt(f)?; + } + } + Ok(()) + } +} + +/// [76] NDataDecl ::= S 'NDATA' S Name +impl<'s> Display for NDataDecl<'s> { + fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result { + S.fmt(f)?; + f.write_str("NDATA")?; + S.fmt(f)?; + self.0.fmt(f)?; + Ok(()) + } +} + +/// [77] TextDecl ::= '<?xml' VersionInfo? EncodingDecl S? '?>' +impl<'s> Display for TextDecl<'s> { + fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result { + f.write_str("<?xml")?; + if let Some(version_info) = &self.version_info { + version_info.fmt(f)?; + } + self.encoding_decl.fmt(f)?; + f.write_str("?>")?; + Ok(()) + } +} + +/// [78] extParsedEnt ::= TextDecl? content +impl<'s> Display for ExtParsedEnt<'s> { + fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result { + if let Some(text_decl) = &self.text_decl { + text_decl.fmt(f)?; + } + self.content.fmt(f)?; + Ok(()) + } +} + +/// [80] EncodingDecl ::= S 'encoding' Eq ('"' EncName '"' | "'" EncName +impl<'s> Display for EncodingDecl<'s> { + fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result { + S.fmt(f)?; + f.write_str("encoding")?; + Eq.fmt(f)?; + f.write_str("\"")?; + self.0.fmt(f)?; + f.write_str("\"")?; + Ok(()) + } +} + +/// [81] EncName ::= [A-Za-z] ([A-Za-z0-9._] | '-')* +impl<'s> Display for EncName<'s> { + fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result { + f.write_str(self.0)?; + Ok(()) + } +} + +/// [82] NotationDecl ::= '<!NOTATION' S Name S (ExternalID | PublicID) S? '>' +impl<'s> Display for NotationDecl<'s> { + fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result { + f.write_str("<!NOTATION")?; + S.fmt(f)?; + self.name.fmt(f)?; + S.fmt(f)?; + match &self.id { + NotationDeclID::External(external_id) => external_id.fmt(f)?, + NotationDeclID::Public(public_id) => public_id.fmt(f)?, + } + f.write_str(">")?; + Ok(()) + } +} + +/// [83] PublicID ::= 'PUBLIC' S PubidLiteral +impl<'s> Display for PublicID<'s> { + fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result { + f.write_str("PUBLIC")?; + S.fmt(f)?; + self.0.fmt(f)?; + Ok(()) + } +} |