2023-03-20 16:25:14 +00:00
|
|
|
use super::*;
|
|
|
|
use derive_more::From;
|
|
|
|
|
|
|
|
#[derive(Default, Debug, PartialEq, Eq)]
|
|
|
|
pub struct Ignore;
|
|
|
|
|
|
|
|
#[derive(From)]
|
|
|
|
pub struct IgnoreParser(IgnoreParserInner);
|
|
|
|
|
|
|
|
enum IgnoreParserInner {
|
|
|
|
Initial,
|
|
|
|
InTag { name: Vec<u8>, depth: u8 },
|
|
|
|
}
|
|
|
|
|
|
|
|
impl Parser for IgnoreParser {
|
|
|
|
type Output = Result<Ignore>;
|
|
|
|
|
|
|
|
fn consume<'a>(
|
|
|
|
self: Self,
|
2023-10-04 13:55:34 +00:00
|
|
|
_: ResolveResult,
|
2023-03-20 16:25:14 +00:00
|
|
|
event: &Event<'a>,
|
|
|
|
) -> Continuation<Self, Self::Output> {
|
|
|
|
match self.0 {
|
|
|
|
IgnoreParserInner::Initial => match event {
|
|
|
|
Event::Start(bytes) => {
|
|
|
|
let name = bytes.name().0.to_owned();
|
|
|
|
Continuation::Continue(IgnoreParserInner::InTag { name, depth: 0 }.into())
|
|
|
|
}
|
|
|
|
Event::Empty(_) => Continuation::Final(Ok(Ignore)),
|
|
|
|
_ => Continuation::Final(Ok(Ignore)),
|
|
|
|
},
|
|
|
|
IgnoreParserInner::InTag { name, depth } => match event {
|
|
|
|
Event::End(bytes) if name == bytes.name().0 => {
|
|
|
|
if depth == 0 {
|
|
|
|
Continuation::Final(Ok(Ignore))
|
|
|
|
} else {
|
|
|
|
Continuation::Continue(
|
|
|
|
IgnoreParserInner::InTag {
|
|
|
|
name,
|
|
|
|
depth: depth - 1,
|
|
|
|
}
|
|
|
|
.into(),
|
|
|
|
)
|
|
|
|
}
|
|
|
|
}
|
2023-03-21 00:16:02 +00:00
|
|
|
_ => Continuation::Continue(IgnoreParserInner::InTag { name, depth }.into()),
|
2023-03-20 16:25:14 +00:00
|
|
|
},
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl FromXml for Ignore {
|
|
|
|
type P = IgnoreParser;
|
|
|
|
|
|
|
|
fn parse() -> Self::P {
|
|
|
|
IgnoreParserInner::Initial.into()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl ToXml for () {
|
2023-10-04 13:55:34 +00:00
|
|
|
fn serialize(&self, _: &mut Vec<Event<'static>>) {}
|
2023-03-20 16:25:14 +00:00
|
|
|
}
|