use std::borrow::Cow;
use crate::tendril::StrTendril;
use crate::{Attribute, QualName};
pub use self::TagKind::{EmptyTag, EndTag, ShortTag, StartTag};
pub use self::Token::{CharacterTokens, EOFToken, NullCharacterToken, ParseError};
pub use self::Token::{CommentToken, DoctypeToken, PIToken, TagToken};
use super::states;
#[derive(PartialEq, Eq, Hash, Copy, Clone, Debug)]
pub enum TagKind {
StartTag,
EndTag,
EmptyTag,
ShortTag,
}
#[derive(PartialEq, Eq, Debug, Clone)]
pub struct Tag {
pub kind: TagKind,
pub name: QualName,
pub attrs: Vec<Attribute>,
}
impl Tag {
pub fn equiv_modulo_attr_order(&self, other: &Tag) -> bool {
if (self.kind != other.kind) || (self.name != other.name) {
return false;
}
let mut self_attrs = self.attrs.clone();
let mut other_attrs = other.attrs.clone();
self_attrs.sort();
other_attrs.sort();
self_attrs == other_attrs
}
}
#[derive(PartialEq, Eq, Clone, Debug)]
pub struct Doctype {
pub name: Option<StrTendril>,
pub public_id: Option<StrTendril>,
pub system_id: Option<StrTendril>,
}
impl Doctype {
pub fn new() -> Doctype {
Doctype {
name: None,
public_id: None,
system_id: None,
}
}
}
#[derive(PartialEq, Eq, Clone, Debug)]
pub struct Pi {
pub target: StrTendril,
pub data: StrTendril,
}
#[derive(PartialEq, Eq, Debug)]
pub enum Token {
DoctypeToken(Doctype),
TagToken(Tag),
PIToken(Pi),
CommentToken(StrTendril),
CharacterTokens(StrTendril),
EOFToken,
NullCharacterToken,
ParseError(Cow<'static, str>),
}
pub trait TokenSink {
fn process_token(&mut self, token: Token);
fn end(&mut self) {}
fn query_state_change(&mut self) -> Option<states::XmlState> {
None
}
}