change privacy
This commit is contained in:
parent
b9d88e5c6f
commit
1fb575b5ca
|
@ -1,5 +1,5 @@
|
||||||
mod element;
|
mod element;
|
||||||
mod error;
|
mod error;
|
||||||
mod parser;
|
pub mod parser;
|
||||||
mod reader;
|
mod reader;
|
||||||
mod writer;
|
mod writer;
|
||||||
|
|
|
@ -0,0 +1,14 @@
|
||||||
|
use peanuts::parser::document;
|
||||||
|
|
||||||
|
fn main() {
|
||||||
|
let document = document(
|
||||||
|
"<?xml version=\"1.0\"?>
|
||||||
|
<TEST>
|
||||||
|
<block1>Background Mark 1</block1>
|
||||||
|
<block2>Background Mark 2</block2>
|
||||||
|
<block3>Background Mark 3</block3>
|
||||||
|
</TEST>
|
||||||
|
",
|
||||||
|
);
|
||||||
|
println!("{:?}", document);
|
||||||
|
}
|
233
src/parser.rs
233
src/parser.rs
|
@ -19,13 +19,13 @@ use nom::{
|
||||||
// output is a rust representation of the input xml
|
// output is a rust representation of the input xml
|
||||||
// types could be used for xml production too?
|
// types could be used for xml production too?
|
||||||
|
|
||||||
type Document<'s> = (Prolog<'s>, Element<'s>, Vec<Misc<'s>>);
|
pub type Document<'s> = (Prolog<'s>, Element<'s>, Vec<Misc<'s>>);
|
||||||
/// [1] document ::= prolog element Misc*
|
/// [1] document ::= prolog element Misc*
|
||||||
pub fn document(input: &str) -> IResult<&str, Document> {
|
pub fn document(input: &str) -> IResult<&str, Document> {
|
||||||
tuple((prolog, element, many0(misc)))(input)
|
tuple((prolog, element, many0(misc)))(input)
|
||||||
}
|
}
|
||||||
|
|
||||||
type Char = char;
|
pub type Char = char;
|
||||||
/// [2] Char ::= #x9 | #xA | #xD | [#x20-#xD7FF] | [#xE000-#xFFFD] | [#x10000-#x10FFFF] /* any Unicode character, excluding the surrogate blocks, FFFE, and FFFF. */
|
/// [2] Char ::= #x9 | #xA | #xD | [#x20-#xD7FF] | [#xE000-#xFFFD] | [#x10000-#x10FFFF] /* any Unicode character, excluding the surrogate blocks, FFFE, and FFFF. */
|
||||||
pub fn xmlchar(input: &str) -> IResult<&str, Char> {
|
pub fn xmlchar(input: &str) -> IResult<&str, Char> {
|
||||||
satisfy(
|
satisfy(
|
||||||
|
@ -33,13 +33,13 @@ pub fn xmlchar(input: &str) -> IResult<&str, Char> {
|
||||||
)(input)
|
)(input)
|
||||||
}
|
}
|
||||||
|
|
||||||
type S<'s> = &'s str;
|
pub type S<'s> = &'s str;
|
||||||
/// [3] S ::= (#x20 | #x9 | #xD | #xA)+
|
/// [3] S ::= (#x20 | #x9 | #xD | #xA)+
|
||||||
pub fn s(input: &str) -> IResult<&str, S> {
|
pub fn s(input: &str) -> IResult<&str, S> {
|
||||||
is_a("\u{20}\u{9}\u{D}\u{A}")(input)
|
is_a("\u{20}\u{9}\u{D}\u{A}")(input)
|
||||||
}
|
}
|
||||||
|
|
||||||
type NameStartChar = char;
|
pub type NameStartChar = char;
|
||||||
/// [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]
|
/// [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]
|
||||||
pub fn name_start_char(input: &str) -> IResult<&str, NameStartChar> {
|
pub fn name_start_char(input: &str) -> IResult<&str, NameStartChar> {
|
||||||
satisfy(
|
satisfy(
|
||||||
|
@ -47,7 +47,7 @@ pub fn name_start_char(input: &str) -> IResult<&str, NameStartChar> {
|
||||||
)(input)
|
)(input)
|
||||||
}
|
}
|
||||||
|
|
||||||
type NameChar = char;
|
pub type NameChar = char;
|
||||||
/// [4a] NameChar ::= NameStartChar | "-" | "." | [0-9] | #xB7 | [#x0300-#x036F] | [#x203F-#x2040]
|
/// [4a] NameChar ::= NameStartChar | "-" | "." | [0-9] | #xB7 | [#x0300-#x036F] | [#x203F-#x2040]
|
||||||
pub fn name_char(input: &str) -> IResult<&str, NameChar> {
|
pub fn name_char(input: &str) -> IResult<&str, NameChar> {
|
||||||
alt((
|
alt((
|
||||||
|
@ -58,38 +58,38 @@ pub fn name_char(input: &str) -> IResult<&str, NameChar> {
|
||||||
))(input)
|
))(input)
|
||||||
}
|
}
|
||||||
|
|
||||||
type Name<'s> = &'s str;
|
pub type Name<'s> = &'s str;
|
||||||
/// [5] Name ::= NameStartChar (NameChar)*
|
/// [5] Name ::= NameStartChar (NameChar)*
|
||||||
pub fn name(input: &str) -> IResult<&str, Name> {
|
pub fn name(input: &str) -> IResult<&str, Name> {
|
||||||
recognize(pair(name_start_char, many0(name_char)))(input)
|
recognize(pair(name_start_char, many0(name_char)))(input)
|
||||||
}
|
}
|
||||||
|
|
||||||
type Names<'s> = &'s str;
|
pub type Names<'s> = &'s str;
|
||||||
/// [6] Names ::= Name (#x20 Name)*
|
/// [6] Names ::= Name (#x20 Name)*
|
||||||
pub fn names(input: &str) -> IResult<&str, Names> {
|
pub fn names(input: &str) -> IResult<&str, Names> {
|
||||||
recognize(pair(name, many0(pair(char('\u{20}'), name))))(input)
|
recognize(pair(name, many0(pair(char('\u{20}'), name))))(input)
|
||||||
}
|
}
|
||||||
|
|
||||||
type Nmtoken<'s> = &'s str;
|
pub type Nmtoken<'s> = &'s str;
|
||||||
/// [7] Nmtoken ::= (NameChar)+
|
/// [7] Nmtoken ::= (NameChar)+
|
||||||
pub fn nmtoken(input: &str) -> IResult<&str, Nmtoken> {
|
pub fn nmtoken(input: &str) -> IResult<&str, Nmtoken> {
|
||||||
recognize(many1(name_char))(input)
|
recognize(many1(name_char))(input)
|
||||||
}
|
}
|
||||||
|
|
||||||
type Nmtokens<'s> = &'s str;
|
pub type Nmtokens<'s> = &'s str;
|
||||||
/// [8] Nmtokens ::= Nmtoken (#x20 Nmtoken)*
|
/// [8] Nmtokens ::= Nmtoken (#x20 Nmtoken)*
|
||||||
pub fn nmtokens(input: &str) -> IResult<&str, Nmtokens> {
|
pub fn nmtokens(input: &str) -> IResult<&str, Nmtokens> {
|
||||||
recognize(pair(nmtoken, many0(pair(char('\u{20}'), nmtoken))))(input)
|
recognize(pair(nmtoken, many0(pair(char('\u{20}'), nmtoken))))(input)
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Clone)]
|
#[derive(Clone, Debug)]
|
||||||
enum LiteralData<'s> {
|
pub enum LiteralData<'s> {
|
||||||
String(&'s str),
|
String(&'s str),
|
||||||
PEReference(PEReference<'s>),
|
PEReference(PEReference<'s>),
|
||||||
Reference(Reference<'s>),
|
Reference(Reference<'s>),
|
||||||
}
|
}
|
||||||
|
|
||||||
type EntityValue<'s> = Vec<LiteralData<'s>>;
|
pub type EntityValue<'s> = Vec<LiteralData<'s>>;
|
||||||
/// [9] EntityValue ::= '"' ([^%&"] | PEReference | Reference)* '"'
|
/// [9] EntityValue ::= '"' ([^%&"] | PEReference | Reference)* '"'
|
||||||
/// | "'" ([^%&'] | PEReference | Reference)* "'"
|
/// | "'" ([^%&'] | PEReference | Reference)* "'"
|
||||||
pub fn entity_value(input: &str) -> IResult<&str, EntityValue> {
|
pub fn entity_value(input: &str) -> IResult<&str, EntityValue> {
|
||||||
|
@ -125,7 +125,7 @@ pub fn entity_value(input: &str) -> IResult<&str, EntityValue> {
|
||||||
))(input)
|
))(input)
|
||||||
}
|
}
|
||||||
|
|
||||||
type AttValue<'s> = Vec<LiteralData<'s>>;
|
pub type AttValue<'s> = Vec<LiteralData<'s>>;
|
||||||
/// [10] AttValue ::= '"' ([^<&"] | Reference)* '"'
|
/// [10] AttValue ::= '"' ([^<&"] | Reference)* '"'
|
||||||
/// | "'" ([^<&'] | Reference)* "'"
|
/// | "'" ([^<&'] | Reference)* "'"
|
||||||
pub fn att_value(input: &str) -> IResult<&str, AttValue> {
|
pub fn att_value(input: &str) -> IResult<&str, AttValue> {
|
||||||
|
@ -155,7 +155,7 @@ pub fn att_value(input: &str) -> IResult<&str, AttValue> {
|
||||||
))(input)
|
))(input)
|
||||||
}
|
}
|
||||||
|
|
||||||
type SystemLiteral<'s> = &'s str;
|
pub type SystemLiteral<'s> = &'s str;
|
||||||
/// [11] SystemLiteral ::= ('"' [^"]* '"') | ("'" [^']* "'")
|
/// [11] SystemLiteral ::= ('"' [^"]* '"') | ("'" [^']* "'")
|
||||||
pub fn system_literal(input: &str) -> IResult<&str, SystemLiteral> {
|
pub fn system_literal(input: &str) -> IResult<&str, SystemLiteral> {
|
||||||
alt((
|
alt((
|
||||||
|
@ -164,7 +164,7 @@ pub fn system_literal(input: &str) -> IResult<&str, SystemLiteral> {
|
||||||
))(input)
|
))(input)
|
||||||
}
|
}
|
||||||
|
|
||||||
type PubidLiteral<'s> = &'s str;
|
pub type PubidLiteral<'s> = &'s str;
|
||||||
/// [12] PubidLiteral ::= '"' PubidChar* '"' | "'" (PubidChar - "'")* "'"
|
/// [12] PubidLiteral ::= '"' PubidChar* '"' | "'" (PubidChar - "'")* "'"
|
||||||
pub fn pubid_literal(input: &str) -> IResult<&str, PubidLiteral> {
|
pub fn pubid_literal(input: &str) -> IResult<&str, PubidLiteral> {
|
||||||
alt((
|
alt((
|
||||||
|
@ -177,7 +177,7 @@ pub fn pubid_literal(input: &str) -> IResult<&str, PubidLiteral> {
|
||||||
))(input)
|
))(input)
|
||||||
}
|
}
|
||||||
|
|
||||||
type PubidChar<'s> = char;
|
pub type PubidChar<'s> = char;
|
||||||
/// [13] PubidChar ::= #x20 | #xD | #xA | [a-zA-Z0-9] | [-'()+,./:=?;!*#@$_%]
|
/// [13] PubidChar ::= #x20 | #xD | #xA | [a-zA-Z0-9] | [-'()+,./:=?;!*#@$_%]
|
||||||
pub fn pubid_char(input: &str) -> IResult<&str, PubidChar> {
|
pub fn pubid_char(input: &str) -> IResult<&str, PubidChar> {
|
||||||
satisfy(|c| matches!(c, '\u{20}' | '\u{D}' | '\u{A}' | 'a'..='z' | 'A'..='Z' | '0'..='9'))(
|
satisfy(|c| matches!(c, '\u{20}' | '\u{D}' | '\u{A}' | 'a'..='z' | 'A'..='Z' | '0'..='9'))(
|
||||||
|
@ -185,7 +185,7 @@ pub fn pubid_char(input: &str) -> IResult<&str, PubidChar> {
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
type CharData<'s> = &'s str;
|
pub type CharData<'s> = &'s str;
|
||||||
/// [14] CharData ::= [^<&]* - ([^<&]* ']]>' [^<&]*)
|
/// [14] CharData ::= [^<&]* - ([^<&]* ']]>' [^<&]*)
|
||||||
pub fn char_data(input: &str) -> IResult<&str, CharData> {
|
pub fn char_data(input: &str) -> IResult<&str, CharData> {
|
||||||
recognize(many_till(
|
recognize(many_till(
|
||||||
|
@ -216,7 +216,7 @@ pub fn char_data(input: &str) -> IResult<&str, CharData> {
|
||||||
// take_till(|c| c == '<' || c == '&').and_then(take_until("]]>"))(input)
|
// take_till(|c| c == '<' || c == '&').and_then(take_until("]]>"))(input)
|
||||||
}
|
}
|
||||||
|
|
||||||
type Comment<'s> = &'s str;
|
pub type Comment<'s> = &'s str;
|
||||||
/// Comment ::= '<!--' ((Char - '-') | ('-' (Char - '-')))* '-->'
|
/// Comment ::= '<!--' ((Char - '-') | ('-' (Char - '-')))* '-->'
|
||||||
pub fn comment(input: &str) -> IResult<&str, Comment> {
|
pub fn comment(input: &str) -> IResult<&str, Comment> {
|
||||||
delimited(
|
delimited(
|
||||||
|
@ -226,8 +226,8 @@ pub fn comment(input: &str) -> IResult<&str, Comment> {
|
||||||
)(input)
|
)(input)
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Clone)]
|
#[derive(Clone, Debug)]
|
||||||
struct PI<'s> {
|
pub struct PI<'s> {
|
||||||
target: &'s str,
|
target: &'s str,
|
||||||
instruction: Option<&'s str>,
|
instruction: Option<&'s str>,
|
||||||
}
|
}
|
||||||
|
@ -249,7 +249,7 @@ pub fn pi(input: &str) -> IResult<&str, PI> {
|
||||||
)(input)
|
)(input)
|
||||||
}
|
}
|
||||||
|
|
||||||
type PITarget<'s> = &'s str;
|
pub type PITarget<'s> = &'s str;
|
||||||
/// [17] PITarget ::= Name - (('X' | 'x') ('M' | 'm') ('L' | 'l'))
|
/// [17] PITarget ::= Name - (('X' | 'x') ('M' | 'm') ('L' | 'l'))
|
||||||
pub fn pi_target(input: &str) -> IResult<&str, PITarget> {
|
pub fn pi_target(input: &str) -> IResult<&str, PITarget> {
|
||||||
let (rest, name) = name(input)?;
|
let (rest, name) = name(input)?;
|
||||||
|
@ -264,31 +264,31 @@ pub fn pi_target(input: &str) -> IResult<&str, PITarget> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
type CDSect<'s> = (CDStart<'s>, CData<'s>, CDEnd<'s>);
|
pub type CDSect<'s> = (CDStart<'s>, CData<'s>, CDEnd<'s>);
|
||||||
/// [18] CDSect ::= CDStart CData CDEnd
|
/// [18] CDSect ::= CDStart CData CDEnd
|
||||||
pub fn cd_sect(input: &str) -> IResult<&str, CDSect> {
|
pub fn cd_sect(input: &str) -> IResult<&str, CDSect> {
|
||||||
tuple((cd_start, cdata, cd_end))(input)
|
tuple((cd_start, cdata, cd_end))(input)
|
||||||
}
|
}
|
||||||
|
|
||||||
type CDStart<'s> = &'s str;
|
pub type CDStart<'s> = &'s str;
|
||||||
/// [19] CDStart ::= '<![CDATA['
|
/// [19] CDStart ::= '<![CDATA['
|
||||||
pub fn cd_start(input: &str) -> IResult<&str, CDStart> {
|
pub fn cd_start(input: &str) -> IResult<&str, CDStart> {
|
||||||
tag("<![CDATA[")(input)
|
tag("<![CDATA[")(input)
|
||||||
}
|
}
|
||||||
|
|
||||||
type CData<'s> = &'s str;
|
pub type CData<'s> = &'s str;
|
||||||
/// [20] CData ::= (Char* - (Char* ']]>' Char*))
|
/// [20] CData ::= (Char* - (Char* ']]>' Char*))
|
||||||
pub fn cdata(input: &str) -> IResult<&str, CData> {
|
pub fn cdata(input: &str) -> IResult<&str, CData> {
|
||||||
recognize(many_till(xmlchar, peek(tag("]]>"))))(input)
|
recognize(many_till(xmlchar, peek(tag("]]>"))))(input)
|
||||||
}
|
}
|
||||||
|
|
||||||
type CDEnd<'s> = &'s str;
|
pub type CDEnd<'s> = &'s str;
|
||||||
/// [21] CDEnd ::= ']]>'
|
/// [21] CDEnd ::= ']]>'
|
||||||
pub fn cd_end(input: &str) -> IResult<&str, CDEnd> {
|
pub fn cd_end(input: &str) -> IResult<&str, CDEnd> {
|
||||||
tag("]]>")(input)
|
tag("]]>")(input)
|
||||||
}
|
}
|
||||||
|
|
||||||
type Prolog<'s> = (
|
pub type Prolog<'s> = (
|
||||||
Option<XMLDecl<'s>>,
|
Option<XMLDecl<'s>>,
|
||||||
Vec<Misc<'s>>,
|
Vec<Misc<'s>>,
|
||||||
Option<(DoctypeDecl<'s>, Vec<Misc<'s>>)>,
|
Option<(DoctypeDecl<'s>, Vec<Misc<'s>>)>,
|
||||||
|
@ -302,7 +302,8 @@ pub fn prolog(input: &str) -> IResult<&str, Prolog> {
|
||||||
))(input)
|
))(input)
|
||||||
}
|
}
|
||||||
|
|
||||||
struct XMLDecl<'s> {
|
#[derive(Debug)]
|
||||||
|
pub struct XMLDecl<'s> {
|
||||||
version_info: VersionInfo,
|
version_info: VersionInfo,
|
||||||
encoding_decl: Option<EncodingDecl<'s>>,
|
encoding_decl: Option<EncodingDecl<'s>>,
|
||||||
sd_decl: Option<SDDecl>,
|
sd_decl: Option<SDDecl>,
|
||||||
|
@ -323,7 +324,7 @@ pub fn xml_decl(input: &str) -> IResult<&str, XMLDecl> {
|
||||||
)(input)
|
)(input)
|
||||||
}
|
}
|
||||||
|
|
||||||
type VersionInfo = VersionNum;
|
pub type VersionInfo = VersionNum;
|
||||||
/// [24] VersionInfo ::= S 'version' Eq ("'" VersionNum "'" | '"' VersionNum '"')
|
/// [24] VersionInfo ::= S 'version' Eq ("'" VersionNum "'" | '"' VersionNum '"')
|
||||||
pub fn version_info(input: &str) -> IResult<&str, VersionInfo> {
|
pub fn version_info(input: &str) -> IResult<&str, VersionInfo> {
|
||||||
preceded(
|
preceded(
|
||||||
|
@ -340,8 +341,8 @@ pub fn eq(input: &str) -> IResult<&str, &str> {
|
||||||
recognize(tuple((opt(s), char('='), opt(s))))(input)
|
recognize(tuple((opt(s), char('='), opt(s))))(input)
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Clone)]
|
#[derive(Clone, Debug)]
|
||||||
enum VersionNum {
|
pub enum VersionNum {
|
||||||
One,
|
One,
|
||||||
OneDotOne,
|
OneDotOne,
|
||||||
}
|
}
|
||||||
|
@ -356,8 +357,8 @@ pub fn version_num(input: &str) -> IResult<&str, VersionNum> {
|
||||||
)(input)
|
)(input)
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Clone)]
|
#[derive(Clone, Debug)]
|
||||||
enum Misc<'s> {
|
pub enum Misc<'s> {
|
||||||
Comment(Comment<'s>),
|
Comment(Comment<'s>),
|
||||||
PI(PI<'s>),
|
PI(PI<'s>),
|
||||||
// TODO: how to deal with whitespace
|
// TODO: how to deal with whitespace
|
||||||
|
@ -372,7 +373,8 @@ pub fn misc(input: &str) -> IResult<&str, Misc> {
|
||||||
))(input)
|
))(input)
|
||||||
}
|
}
|
||||||
|
|
||||||
struct DoctypeDecl<'s> {
|
#[derive(Debug)]
|
||||||
|
pub struct DoctypeDecl<'s> {
|
||||||
name: &'s str,
|
name: &'s str,
|
||||||
external_id: Option<ExternalID<'s>>,
|
external_id: Option<ExternalID<'s>>,
|
||||||
int_subset: Option<IntSubset<'s>>,
|
int_subset: Option<IntSubset<'s>>,
|
||||||
|
@ -403,8 +405,8 @@ pub fn doctypedecl(input: &str) -> IResult<&str, DoctypeDecl> {
|
||||||
)(input)
|
)(input)
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Clone)]
|
#[derive(Clone, Debug)]
|
||||||
enum DeclSep<'s> {
|
pub enum DeclSep<'s> {
|
||||||
PEReference(PEReference<'s>),
|
PEReference(PEReference<'s>),
|
||||||
// TODO: tackle whitespace
|
// TODO: tackle whitespace
|
||||||
S,
|
S,
|
||||||
|
@ -419,7 +421,8 @@ pub fn decl_sep(input: &str) -> IResult<&str, DeclSep> {
|
||||||
))(input)
|
))(input)
|
||||||
}
|
}
|
||||||
|
|
||||||
enum IntSubsetDeclaration<'s> {
|
#[derive(Debug)]
|
||||||
|
pub enum IntSubsetDeclaration<'s> {
|
||||||
MarkupDecl(MarkupDecl<'s>),
|
MarkupDecl(MarkupDecl<'s>),
|
||||||
DeclSep(DeclSep<'s>),
|
DeclSep(DeclSep<'s>),
|
||||||
}
|
}
|
||||||
|
@ -434,7 +437,8 @@ pub fn int_subset(input: &str) -> IResult<&str, IntSubset> {
|
||||||
)))(input)
|
)))(input)
|
||||||
}
|
}
|
||||||
|
|
||||||
enum MarkupDecl<'s> {
|
#[derive(Debug)]
|
||||||
|
pub enum MarkupDecl<'s> {
|
||||||
Elementdecl(Elementdecl<'s>),
|
Elementdecl(Elementdecl<'s>),
|
||||||
AttlistDecl(AttlistDecl<'s>),
|
AttlistDecl(AttlistDecl<'s>),
|
||||||
EntityDecl(EntityDecl<'s>),
|
EntityDecl(EntityDecl<'s>),
|
||||||
|
@ -462,7 +466,7 @@ pub fn markup_decl(input: &str) -> IResult<&str, MarkupDecl> {
|
||||||
))(input)
|
))(input)
|
||||||
}
|
}
|
||||||
|
|
||||||
struct ExtSubset<'s> {
|
pub struct ExtSubset<'s> {
|
||||||
text_decl: Option<TextDecl<'s>>,
|
text_decl: Option<TextDecl<'s>>,
|
||||||
ext_subset_decl: ExtSubsetDecl<'s>,
|
ext_subset_decl: ExtSubsetDecl<'s>,
|
||||||
}
|
}
|
||||||
|
@ -477,7 +481,7 @@ pub fn ext_subset(input: &str) -> IResult<&str, ExtSubset> {
|
||||||
)(input)
|
)(input)
|
||||||
}
|
}
|
||||||
|
|
||||||
enum ExtSubsetDeclaration<'s> {
|
pub enum ExtSubsetDeclaration<'s> {
|
||||||
MarkupDecl(MarkupDecl<'s>),
|
MarkupDecl(MarkupDecl<'s>),
|
||||||
ConditionalSect(ConditionalSect<'s>),
|
ConditionalSect(ConditionalSect<'s>),
|
||||||
DeclSep(DeclSep<'s>),
|
DeclSep(DeclSep<'s>),
|
||||||
|
@ -496,7 +500,7 @@ pub fn ext_subset_decl(input: &str) -> IResult<&str, ExtSubsetDecl> {
|
||||||
)))(input)
|
)))(input)
|
||||||
}
|
}
|
||||||
|
|
||||||
type SDDecl = bool;
|
pub type SDDecl = bool;
|
||||||
/// [32] SDDecl ::= S 'standalone' Eq (("'" ('yes' | 'no') "'") | ('"' ('yes' | 'no') '"'))
|
/// [32] SDDecl ::= S 'standalone' Eq (("'" ('yes' | 'no') "'") | ('"' ('yes' | 'no') '"'))
|
||||||
pub fn sd_decl(input: &str) -> IResult<&str, SDDecl> {
|
pub fn sd_decl(input: &str) -> IResult<&str, SDDecl> {
|
||||||
preceded(
|
preceded(
|
||||||
|
@ -518,7 +522,8 @@ pub fn sd_decl(input: &str) -> IResult<&str, SDDecl> {
|
||||||
|
|
||||||
// (Productions 33 through 38 have been removed.)
|
// (Productions 33 through 38 have been removed.)
|
||||||
|
|
||||||
enum Element<'s> {
|
#[derive(Debug)]
|
||||||
|
pub enum Element<'s> {
|
||||||
Empty(EmptyElemTag<'s>),
|
Empty(EmptyElemTag<'s>),
|
||||||
NotEmpty(STag<'s>, Content<'s>, ETag<'s>),
|
NotEmpty(STag<'s>, Content<'s>, ETag<'s>),
|
||||||
}
|
}
|
||||||
|
@ -534,7 +539,8 @@ pub fn element(input: &str) -> IResult<&str, Element> {
|
||||||
))(input)
|
))(input)
|
||||||
}
|
}
|
||||||
|
|
||||||
struct STag<'s> {
|
#[derive(Debug)]
|
||||||
|
pub struct STag<'s> {
|
||||||
name: Name<'s>,
|
name: Name<'s>,
|
||||||
attributes: Vec<Attribute<'s>>,
|
attributes: Vec<Attribute<'s>>,
|
||||||
}
|
}
|
||||||
|
@ -550,13 +556,14 @@ pub fn s_tag(input: &str) -> IResult<&str, STag> {
|
||||||
)(input)
|
)(input)
|
||||||
}
|
}
|
||||||
|
|
||||||
type Attribute<'s> = (Name<'s>, AttValue<'s>);
|
pub type Attribute<'s> = (Name<'s>, AttValue<'s>);
|
||||||
/// [41] Attribute ::= Name Eq AttValue
|
/// [41] Attribute ::= Name Eq AttValue
|
||||||
pub fn attribute(input: &str) -> IResult<&str, Attribute> {
|
pub fn attribute(input: &str) -> IResult<&str, Attribute> {
|
||||||
separated_pair(name, eq, att_value)(input)
|
separated_pair(name, eq, att_value)(input)
|
||||||
}
|
}
|
||||||
|
|
||||||
struct ETag<'s> {
|
#[derive(Debug)]
|
||||||
|
pub struct ETag<'s> {
|
||||||
name: Name<'s>,
|
name: Name<'s>,
|
||||||
}
|
}
|
||||||
/// [42] ETag ::= '</' Name S? '>'
|
/// [42] ETag ::= '</' Name S? '>'
|
||||||
|
@ -566,7 +573,8 @@ pub fn e_tag(input: &str) -> IResult<&str, ETag> {
|
||||||
})(input)
|
})(input)
|
||||||
}
|
}
|
||||||
|
|
||||||
enum ContentItem<'s> {
|
#[derive(Debug)]
|
||||||
|
pub enum ContentItem<'s> {
|
||||||
// CharData(&'s str),
|
// CharData(&'s str),
|
||||||
Element(Element<'s>),
|
Element(Element<'s>),
|
||||||
Reference(Reference<'s>),
|
Reference(Reference<'s>),
|
||||||
|
@ -574,7 +582,8 @@ enum ContentItem<'s> {
|
||||||
PI(PI<'s>),
|
PI(PI<'s>),
|
||||||
Comment(Comment<'s>),
|
Comment(Comment<'s>),
|
||||||
}
|
}
|
||||||
struct Content<'s> {
|
#[derive(Debug)]
|
||||||
|
pub struct Content<'s> {
|
||||||
char_data: Option<CharData<'s>>,
|
char_data: Option<CharData<'s>>,
|
||||||
content: Vec<(ContentItem<'s>, Option<CharData<'s>>)>,
|
content: Vec<(ContentItem<'s>, Option<CharData<'s>>)>,
|
||||||
}
|
}
|
||||||
|
@ -598,7 +607,8 @@ pub fn content(input: &str) -> IResult<&str, Content> {
|
||||||
)(input)
|
)(input)
|
||||||
}
|
}
|
||||||
|
|
||||||
struct EmptyElemTag<'s> {
|
#[derive(Debug)]
|
||||||
|
pub struct EmptyElemTag<'s> {
|
||||||
name: Name<'s>,
|
name: Name<'s>,
|
||||||
attributes: Vec<Attribute<'s>>,
|
attributes: Vec<Attribute<'s>>,
|
||||||
}
|
}
|
||||||
|
@ -614,7 +624,8 @@ pub fn empty_elem_tag(input: &str) -> IResult<&str, EmptyElemTag> {
|
||||||
)(input)
|
)(input)
|
||||||
}
|
}
|
||||||
|
|
||||||
struct Elementdecl<'s> {
|
#[derive(Debug)]
|
||||||
|
pub struct Elementdecl<'s> {
|
||||||
name: Name<'s>,
|
name: Name<'s>,
|
||||||
contentspec: Contentspec<'s>,
|
contentspec: Contentspec<'s>,
|
||||||
}
|
}
|
||||||
|
@ -631,8 +642,8 @@ pub fn elementdecl(input: &str) -> IResult<&str, Elementdecl> {
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: casings???
|
// TODO: casings???
|
||||||
#[derive(Clone)]
|
#[derive(Clone, Debug)]
|
||||||
enum Contentspec<'s> {
|
pub enum Contentspec<'s> {
|
||||||
Empty,
|
Empty,
|
||||||
Any,
|
Any,
|
||||||
Mixed(Mixed<'s>),
|
Mixed(Mixed<'s>),
|
||||||
|
@ -648,8 +659,8 @@ pub fn contentspec(input: &str) -> IResult<&str, Contentspec> {
|
||||||
))(input)
|
))(input)
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Clone)]
|
#[derive(Clone, Debug)]
|
||||||
enum Occurence {
|
pub enum Occurence {
|
||||||
Once,
|
Once,
|
||||||
Optional,
|
Optional,
|
||||||
Many0,
|
Many0,
|
||||||
|
@ -668,13 +679,13 @@ pub fn occurence(input: &str) -> IResult<&str, Occurence> {
|
||||||
)(input)
|
)(input)
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Clone)]
|
#[derive(Clone, Debug)]
|
||||||
enum ChildrenKind<'s> {
|
pub enum ChildrenKind<'s> {
|
||||||
Choice(Choice<'s>),
|
Choice(Choice<'s>),
|
||||||
Seq(Seq<'s>),
|
Seq(Seq<'s>),
|
||||||
}
|
}
|
||||||
#[derive(Clone)]
|
#[derive(Clone, Debug)]
|
||||||
struct Children<'s> {
|
pub struct Children<'s> {
|
||||||
kind: ChildrenKind<'s>,
|
kind: ChildrenKind<'s>,
|
||||||
occurence: Occurence,
|
occurence: Occurence,
|
||||||
}
|
}
|
||||||
|
@ -696,14 +707,14 @@ pub fn children(input: &str) -> IResult<&str, Children> {
|
||||||
// ))(input)
|
// ))(input)
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Clone)]
|
#[derive(Clone, Debug)]
|
||||||
enum CpKind<'s> {
|
pub enum CpKind<'s> {
|
||||||
Name(Name<'s>),
|
Name(Name<'s>),
|
||||||
Choice(Choice<'s>),
|
Choice(Choice<'s>),
|
||||||
Seq(Seq<'s>),
|
Seq(Seq<'s>),
|
||||||
}
|
}
|
||||||
#[derive(Clone)]
|
#[derive(Clone, Debug)]
|
||||||
struct Cp<'s> {
|
pub struct Cp<'s> {
|
||||||
kind: CpKind<'s>,
|
kind: CpKind<'s>,
|
||||||
occurence: Occurence,
|
occurence: Occurence,
|
||||||
}
|
}
|
||||||
|
@ -722,8 +733,8 @@ pub fn cp(input: &str) -> IResult<&str, Cp> {
|
||||||
)(input)
|
)(input)
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Clone)]
|
#[derive(Clone, Debug)]
|
||||||
struct Choice<'s>(Vec<Cp<'s>>);
|
pub struct Choice<'s>(Vec<Cp<'s>>);
|
||||||
/// [49] choice ::= '(' S? cp ( S? '|' S? cp )+ S? ')'
|
/// [49] choice ::= '(' S? cp ( S? '|' S? cp )+ S? ')'
|
||||||
pub fn choice(input: &str) -> IResult<&str, Choice> {
|
pub fn choice(input: &str) -> IResult<&str, Choice> {
|
||||||
map(
|
map(
|
||||||
|
@ -739,8 +750,8 @@ pub fn choice(input: &str) -> IResult<&str, Choice> {
|
||||||
)(input)
|
)(input)
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Clone)]
|
#[derive(Clone, Debug)]
|
||||||
struct Seq<'s>(Vec<Cp<'s>>);
|
pub struct Seq<'s>(Vec<Cp<'s>>);
|
||||||
/// [50] seq ::= '(' S? cp ( S? ',' S? cp )* S? ')'
|
/// [50] seq ::= '(' S? cp ( S? ',' S? cp )* S? ')'
|
||||||
pub fn seq(input: &str) -> IResult<&str, Seq> {
|
pub fn seq(input: &str) -> IResult<&str, Seq> {
|
||||||
map(
|
map(
|
||||||
|
@ -757,8 +768,8 @@ pub fn seq(input: &str) -> IResult<&str, Seq> {
|
||||||
}
|
}
|
||||||
|
|
||||||
// always contains #PCDATA
|
// always contains #PCDATA
|
||||||
#[derive(Clone)]
|
#[derive(Clone, Debug)]
|
||||||
struct Mixed<'s>(Vec<Name<'s>>);
|
pub struct Mixed<'s>(Vec<Name<'s>>);
|
||||||
/// [51] Mixed ::= '(' S? '#PCDATA' (S? '|' S? Name)* S? ')*' | '(' S? '#PCDATA' S? ')'
|
/// [51] Mixed ::= '(' S? '#PCDATA' (S? '|' S? Name)* S? ')*' | '(' S? '#PCDATA' S? ')'
|
||||||
pub fn mixed(input: &str) -> IResult<&str, Mixed> {
|
pub fn mixed(input: &str) -> IResult<&str, Mixed> {
|
||||||
alt((
|
alt((
|
||||||
|
@ -777,7 +788,8 @@ pub fn mixed(input: &str) -> IResult<&str, Mixed> {
|
||||||
))(input)
|
))(input)
|
||||||
}
|
}
|
||||||
|
|
||||||
struct AttlistDecl<'s> {
|
#[derive(Debug)]
|
||||||
|
pub struct AttlistDecl<'s> {
|
||||||
element_type: Name<'s>,
|
element_type: Name<'s>,
|
||||||
att_defs: Vec<AttDef<'s>>,
|
att_defs: Vec<AttDef<'s>>,
|
||||||
}
|
}
|
||||||
|
@ -796,7 +808,8 @@ pub fn attlist_decl(input: &str) -> IResult<&str, AttlistDecl> {
|
||||||
)(input)
|
)(input)
|
||||||
}
|
}
|
||||||
|
|
||||||
struct AttDef<'s> {
|
#[derive(Debug)]
|
||||||
|
pub struct AttDef<'s> {
|
||||||
name: Name<'s>,
|
name: Name<'s>,
|
||||||
att_type: AttType<'s>,
|
att_type: AttType<'s>,
|
||||||
default_decl: DefaultDecl<'s>,
|
default_decl: DefaultDecl<'s>,
|
||||||
|
@ -817,8 +830,8 @@ pub fn att_def(input: &str) -> IResult<&str, AttDef> {
|
||||||
)(input)
|
)(input)
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Clone)]
|
#[derive(Clone, Debug)]
|
||||||
enum AttType<'s> {
|
pub enum AttType<'s> {
|
||||||
StringType,
|
StringType,
|
||||||
TokenizedType(TokenizedType),
|
TokenizedType(TokenizedType),
|
||||||
EnumeratedType(EnumeratedType<'s>),
|
EnumeratedType(EnumeratedType<'s>),
|
||||||
|
@ -836,14 +849,14 @@ pub fn att_type(input: &str) -> IResult<&str, AttType> {
|
||||||
))(input)
|
))(input)
|
||||||
}
|
}
|
||||||
|
|
||||||
type StringType<'s> = &'s str;
|
pub type StringType<'s> = &'s str;
|
||||||
/// [55] StringType ::= 'CDATA'
|
/// [55] StringType ::= 'CDATA'
|
||||||
pub fn string_type(input: &str) -> IResult<&str, StringType> {
|
pub fn string_type(input: &str) -> IResult<&str, StringType> {
|
||||||
tag("CDATA")(input)
|
tag("CDATA")(input)
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Clone)]
|
#[derive(Clone, Debug)]
|
||||||
enum TokenizedType {
|
pub enum TokenizedType {
|
||||||
ID,
|
ID,
|
||||||
IDRef,
|
IDRef,
|
||||||
IDRefs,
|
IDRefs,
|
||||||
|
@ -868,8 +881,8 @@ pub fn tokenized_type(input: &str) -> IResult<&str, TokenizedType> {
|
||||||
))(input)
|
))(input)
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Clone)]
|
#[derive(Debug, Clone)]
|
||||||
enum EnumeratedType<'s> {
|
pub enum EnumeratedType<'s> {
|
||||||
NotationType(NotationType<'s>),
|
NotationType(NotationType<'s>),
|
||||||
Enumeration(Enumeration<'s>),
|
Enumeration(Enumeration<'s>),
|
||||||
}
|
}
|
||||||
|
@ -885,8 +898,8 @@ pub fn enumerated_type(input: &str) -> IResult<&str, EnumeratedType> {
|
||||||
))(input)
|
))(input)
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Clone)]
|
#[derive(Debug, Clone)]
|
||||||
struct NotationType<'s>(Vec<Name<'s>>);
|
pub struct NotationType<'s>(Vec<Name<'s>>);
|
||||||
/// [58] NotationType ::= 'NOTATION' S '(' S? Name (S? '|' S? Name)* S? ')'
|
/// [58] NotationType ::= 'NOTATION' S '(' S? Name (S? '|' S? Name)* S? ')'
|
||||||
pub fn notation_type(input: &str) -> IResult<&str, NotationType> {
|
pub fn notation_type(input: &str) -> IResult<&str, NotationType> {
|
||||||
map(
|
map(
|
||||||
|
@ -905,8 +918,8 @@ pub fn notation_type(input: &str) -> IResult<&str, NotationType> {
|
||||||
)(input)
|
)(input)
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Clone)]
|
#[derive(Debug, Clone)]
|
||||||
struct Enumeration<'s>(Vec<Nmtoken<'s>>);
|
pub struct Enumeration<'s>(Vec<Nmtoken<'s>>);
|
||||||
/// [59] Enumeration ::= '(' S? Nmtoken (S? '|' S? Nmtoken)* S? ')'
|
/// [59] Enumeration ::= '(' S? Nmtoken (S? '|' S? Nmtoken)* S? ')'
|
||||||
pub fn enumeration(input: &str) -> IResult<&str, Enumeration> {
|
pub fn enumeration(input: &str) -> IResult<&str, Enumeration> {
|
||||||
map(
|
map(
|
||||||
|
@ -925,8 +938,8 @@ pub fn enumeration(input: &str) -> IResult<&str, Enumeration> {
|
||||||
)(input)
|
)(input)
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Clone)]
|
#[derive(Debug, Clone)]
|
||||||
enum DefaultDecl<'s> {
|
pub enum DefaultDecl<'s> {
|
||||||
Required,
|
Required,
|
||||||
Implied,
|
Implied,
|
||||||
Fixed(AttValue<'s>),
|
Fixed(AttValue<'s>),
|
||||||
|
@ -943,7 +956,7 @@ pub fn default_decl(input: &str) -> IResult<&str, DefaultDecl> {
|
||||||
))(input)
|
))(input)
|
||||||
}
|
}
|
||||||
|
|
||||||
enum ConditionalSect<'s> {
|
pub enum ConditionalSect<'s> {
|
||||||
IncludeSect(IncludeSect<'s>),
|
IncludeSect(IncludeSect<'s>),
|
||||||
IgnoreSect(IgnoreSect<'s>),
|
IgnoreSect(IgnoreSect<'s>),
|
||||||
}
|
}
|
||||||
|
@ -959,7 +972,7 @@ pub fn conditional_sect(input: &str) -> IResult<&str, ConditionalSect> {
|
||||||
))(input)
|
))(input)
|
||||||
}
|
}
|
||||||
|
|
||||||
struct IncludeSect<'s>(ExtSubsetDecl<'s>);
|
pub struct IncludeSect<'s>(ExtSubsetDecl<'s>);
|
||||||
/// [62] includeSect ::= '<![' S? 'INCLUDE' S? '[' extSubsetDecl ']]>'
|
/// [62] includeSect ::= '<![' S? 'INCLUDE' S? '[' extSubsetDecl ']]>'
|
||||||
pub fn include_sect(input: &str) -> IResult<&str, IncludeSect> {
|
pub fn include_sect(input: &str) -> IResult<&str, IncludeSect> {
|
||||||
map(
|
map(
|
||||||
|
@ -972,7 +985,7 @@ pub fn include_sect(input: &str) -> IResult<&str, IncludeSect> {
|
||||||
)(input)
|
)(input)
|
||||||
}
|
}
|
||||||
|
|
||||||
struct IgnoreSect<'s>(Vec<IgnoreSectContents<'s>>);
|
pub struct IgnoreSect<'s>(Vec<IgnoreSectContents<'s>>);
|
||||||
/// [63] ignoreSect ::= '<![' S? 'IGNORE' S? '[' ignoreSectContents* ']]>'
|
/// [63] ignoreSect ::= '<![' S? 'IGNORE' S? '[' ignoreSectContents* ']]>'
|
||||||
pub fn ignore_sect(input: &str) -> IResult<&str, IgnoreSect> {
|
pub fn ignore_sect(input: &str) -> IResult<&str, IgnoreSect> {
|
||||||
map(
|
map(
|
||||||
|
@ -985,7 +998,7 @@ pub fn ignore_sect(input: &str) -> IResult<&str, IgnoreSect> {
|
||||||
)(input)
|
)(input)
|
||||||
}
|
}
|
||||||
|
|
||||||
struct IgnoreSectContents<'s> {
|
pub struct IgnoreSectContents<'s> {
|
||||||
// TODO: what the fuck does this mean
|
// TODO: what the fuck does this mean
|
||||||
ignore: Ignore<'s>,
|
ignore: Ignore<'s>,
|
||||||
ignore_list: Vec<(IgnoreSectContents<'s>, Ignore<'s>)>,
|
ignore_list: Vec<(IgnoreSectContents<'s>, Ignore<'s>)>,
|
||||||
|
@ -1007,14 +1020,14 @@ pub fn ignore_sect_contents(input: &str) -> IResult<&str, IgnoreSectContents> {
|
||||||
)(input)
|
)(input)
|
||||||
}
|
}
|
||||||
|
|
||||||
type Ignore<'s> = &'s str;
|
pub type Ignore<'s> = &'s str;
|
||||||
/// [65] Ignore ::= Char* - (Char* ('<![' | ']]>') Char*)
|
/// [65] Ignore ::= Char* - (Char* ('<![' | ']]>') Char*)
|
||||||
pub fn ignore(input: &str) -> IResult<&str, Ignore> {
|
pub fn ignore(input: &str) -> IResult<&str, Ignore> {
|
||||||
recognize(many_till(xmlchar, peek(alt((tag("<!["), tag("]]>"))))))(input)
|
recognize(many_till(xmlchar, peek(alt((tag("<!["), tag("]]>"))))))(input)
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Clone)]
|
#[derive(Clone, Debug)]
|
||||||
enum CharRef<'s> {
|
pub enum CharRef<'s> {
|
||||||
Decimal(&'s str),
|
Decimal(&'s str),
|
||||||
Hexadecimal(&'s str),
|
Hexadecimal(&'s str),
|
||||||
}
|
}
|
||||||
|
@ -1039,8 +1052,8 @@ pub fn char_ref(input: &str) -> IResult<&str, CharRef> {
|
||||||
))(input)
|
))(input)
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Clone)]
|
#[derive(Clone, Debug)]
|
||||||
enum Reference<'s> {
|
pub enum Reference<'s> {
|
||||||
EntityRef(EntityRef<'s>),
|
EntityRef(EntityRef<'s>),
|
||||||
CharRef(CharRef<'s>),
|
CharRef(CharRef<'s>),
|
||||||
}
|
}
|
||||||
|
@ -1052,19 +1065,20 @@ pub fn reference(input: &str) -> IResult<&str, Reference> {
|
||||||
))(input)
|
))(input)
|
||||||
}
|
}
|
||||||
|
|
||||||
type EntityRef<'s> = &'s str;
|
pub type EntityRef<'s> = &'s str;
|
||||||
/// [68] EntityRef ::= '&' Name ';'
|
/// [68] EntityRef ::= '&' Name ';'
|
||||||
pub fn entity_ref(input: &str) -> IResult<&str, EntityRef> {
|
pub fn entity_ref(input: &str) -> IResult<&str, EntityRef> {
|
||||||
delimited(tag("&"), name, tag(";"))(input)
|
delimited(tag("&"), name, tag(";"))(input)
|
||||||
}
|
}
|
||||||
|
|
||||||
type PEReference<'s> = &'s str;
|
pub type PEReference<'s> = &'s str;
|
||||||
/// [69] PEReference ::= '%' Name ';'
|
/// [69] PEReference ::= '%' Name ';'
|
||||||
pub fn pe_reference(input: &str) -> IResult<&str, PEReference> {
|
pub fn pe_reference(input: &str) -> IResult<&str, PEReference> {
|
||||||
delimited(tag("%"), name, tag(";"))(input)
|
delimited(tag("%"), name, tag(";"))(input)
|
||||||
}
|
}
|
||||||
|
|
||||||
enum EntityDecl<'s> {
|
#[derive(Debug)]
|
||||||
|
pub enum EntityDecl<'s> {
|
||||||
GEDecl(GEDecl<'s>),
|
GEDecl(GEDecl<'s>),
|
||||||
PEDecl(PEDecl<'s>),
|
PEDecl(PEDecl<'s>),
|
||||||
}
|
}
|
||||||
|
@ -1076,7 +1090,8 @@ pub fn entity_decl(input: &str) -> IResult<&str, EntityDecl> {
|
||||||
))(input)
|
))(input)
|
||||||
}
|
}
|
||||||
|
|
||||||
struct GEDecl<'s> {
|
#[derive(Debug)]
|
||||||
|
pub struct GEDecl<'s> {
|
||||||
name: Name<'s>,
|
name: Name<'s>,
|
||||||
entity_def: EntityDef<'s>,
|
entity_def: EntityDef<'s>,
|
||||||
}
|
}
|
||||||
|
@ -1092,7 +1107,8 @@ pub fn ge_decl(input: &str) -> IResult<&str, GEDecl> {
|
||||||
)(input)
|
)(input)
|
||||||
}
|
}
|
||||||
|
|
||||||
struct PEDecl<'s> {
|
#[derive(Debug)]
|
||||||
|
pub struct PEDecl<'s> {
|
||||||
name: Name<'s>,
|
name: Name<'s>,
|
||||||
pe_def: PEDef<'s>,
|
pe_def: PEDef<'s>,
|
||||||
}
|
}
|
||||||
|
@ -1108,7 +1124,8 @@ pub fn pe_decl(input: &str) -> IResult<&str, PEDecl> {
|
||||||
)(input)
|
)(input)
|
||||||
}
|
}
|
||||||
|
|
||||||
enum EntityDef<'s> {
|
#[derive(Debug)]
|
||||||
|
pub enum EntityDef<'s> {
|
||||||
EntityValue(EntityValue<'s>),
|
EntityValue(EntityValue<'s>),
|
||||||
ExternalID {
|
ExternalID {
|
||||||
external_id: ExternalID<'s>,
|
external_id: ExternalID<'s>,
|
||||||
|
@ -1131,7 +1148,8 @@ pub fn entity_def(input: &str) -> IResult<&str, EntityDef> {
|
||||||
))(input)
|
))(input)
|
||||||
}
|
}
|
||||||
|
|
||||||
enum PEDef<'s> {
|
#[derive(Debug)]
|
||||||
|
pub enum PEDef<'s> {
|
||||||
EntityValue(EntityValue<'s>),
|
EntityValue(EntityValue<'s>),
|
||||||
ExternalID(ExternalID<'s>),
|
ExternalID(ExternalID<'s>),
|
||||||
}
|
}
|
||||||
|
@ -1145,7 +1163,8 @@ pub fn pe_def(input: &str) -> IResult<&str, PEDef> {
|
||||||
))(input)
|
))(input)
|
||||||
}
|
}
|
||||||
|
|
||||||
enum ExternalID<'s> {
|
#[derive(Debug)]
|
||||||
|
pub enum ExternalID<'s> {
|
||||||
SYSTEM {
|
SYSTEM {
|
||||||
system_identifier: &'s str,
|
system_identifier: &'s str,
|
||||||
},
|
},
|
||||||
|
@ -1175,13 +1194,13 @@ pub fn external_id(input: &str) -> IResult<&str, ExternalID> {
|
||||||
))(input)
|
))(input)
|
||||||
}
|
}
|
||||||
|
|
||||||
type NDataDecl<'s> = &'s str;
|
pub type NDataDecl<'s> = &'s str;
|
||||||
/// [76] NDataDecl ::= S 'NDATA' S Name
|
/// [76] NDataDecl ::= S 'NDATA' S Name
|
||||||
pub fn ndata_decl(input: &str) -> IResult<&str, NDataDecl> {
|
pub fn ndata_decl(input: &str) -> IResult<&str, NDataDecl> {
|
||||||
preceded(tuple((s, tag("NDATA"), s)), name)(input)
|
preceded(tuple((s, tag("NDATA"), s)), name)(input)
|
||||||
}
|
}
|
||||||
|
|
||||||
struct TextDecl<'s> {
|
pub struct TextDecl<'s> {
|
||||||
version_info: Option<VersionInfo>,
|
version_info: Option<VersionInfo>,
|
||||||
encoding_decl: EncodingDecl<'s>,
|
encoding_decl: EncodingDecl<'s>,
|
||||||
}
|
}
|
||||||
|
@ -1200,7 +1219,7 @@ pub fn text_decl(input: &str) -> IResult<&str, TextDecl> {
|
||||||
)(input)
|
)(input)
|
||||||
}
|
}
|
||||||
|
|
||||||
struct ExtParsedEnt<'s> {
|
pub struct ExtParsedEnt<'s> {
|
||||||
text_decl: Option<TextDecl<'s>>,
|
text_decl: Option<TextDecl<'s>>,
|
||||||
content: Content<'s>,
|
content: Content<'s>,
|
||||||
}
|
}
|
||||||
|
@ -1211,7 +1230,7 @@ pub fn ext_parsed_ent(input: &str) -> IResult<&str, ExtParsedEnt> {
|
||||||
})(input)
|
})(input)
|
||||||
}
|
}
|
||||||
|
|
||||||
type EncodingDecl<'s> = EncName<'s>;
|
pub type EncodingDecl<'s> = EncName<'s>;
|
||||||
/// [80] EncodingDecl ::= S 'encoding' Eq ('"' EncName '"' | "'" EncName
|
/// [80] EncodingDecl ::= S 'encoding' Eq ('"' EncName '"' | "'" EncName
|
||||||
pub fn encoding_decl(input: &str) -> IResult<&str, EncodingDecl> {
|
pub fn encoding_decl(input: &str) -> IResult<&str, EncodingDecl> {
|
||||||
preceded(
|
preceded(
|
||||||
|
@ -1223,7 +1242,7 @@ pub fn encoding_decl(input: &str) -> IResult<&str, EncodingDecl> {
|
||||||
)(input)
|
)(input)
|
||||||
}
|
}
|
||||||
|
|
||||||
type EncName<'s> = &'s str;
|
pub type EncName<'s> = &'s str;
|
||||||
/// [81] EncName ::= [A-Za-z] ([A-Za-z0-9._] | '-')*
|
/// [81] EncName ::= [A-Za-z] ([A-Za-z0-9._] | '-')*
|
||||||
pub fn enc_name(input: &str) -> IResult<&str, EncName> {
|
pub fn enc_name(input: &str) -> IResult<&str, EncName> {
|
||||||
recognize(pair(
|
recognize(pair(
|
||||||
|
@ -1234,11 +1253,13 @@ pub fn enc_name(input: &str) -> IResult<&str, EncName> {
|
||||||
))(input)
|
))(input)
|
||||||
}
|
}
|
||||||
|
|
||||||
struct NotationDecl<'s> {
|
#[derive(Debug)]
|
||||||
|
pub struct NotationDecl<'s> {
|
||||||
name: &'s str,
|
name: &'s str,
|
||||||
id: NotationDeclID<'s>,
|
id: NotationDeclID<'s>,
|
||||||
}
|
}
|
||||||
enum NotationDeclID<'s> {
|
#[derive(Debug)]
|
||||||
|
pub enum NotationDeclID<'s> {
|
||||||
External(ExternalID<'s>),
|
External(ExternalID<'s>),
|
||||||
Public(PublicID<'s>),
|
Public(PublicID<'s>),
|
||||||
}
|
}
|
||||||
|
@ -1263,7 +1284,7 @@ pub fn notation_decl(input: &str) -> IResult<&str, NotationDecl> {
|
||||||
)(input)
|
)(input)
|
||||||
}
|
}
|
||||||
|
|
||||||
type PublicID<'s> = &'s str;
|
pub type PublicID<'s> = &'s str;
|
||||||
/// [83] PublicID ::= 'PUBLIC' S PubidLiteral
|
/// [83] PublicID ::= 'PUBLIC' S PubidLiteral
|
||||||
pub fn public_id(input: &str) -> IResult<&str, PublicID> {
|
pub fn public_id(input: &str) -> IResult<&str, PublicID> {
|
||||||
preceded(pair(tag("PUBLIC"), s), pubid_literal)(input)
|
preceded(pair(tag("PUBLIC"), s), pubid_literal)(input)
|
||||||
|
|
Loading…
Reference in New Issue