use std::borrow::Cow;
use crate::tendril::StrTendril;
use crate::tokenizer::ProcessResult;
use crate::{Attribute, QualName};
pub use self::TagKind::{EmptyTag, EndTag, ShortTag, StartTag};
#[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, Default)]
pub struct Doctype {
pub name: Option<StrTendril>,
pub public_id: Option<StrTendril>,
pub system_id: Option<StrTendril>,
}
#[derive(PartialEq, Eq, Clone, Debug)]
pub struct Pi {
pub target: StrTendril,
pub data: StrTendril,
}
#[derive(PartialEq, Eq, Debug)]
pub enum Token {
Doctype(Doctype),
Tag(Tag),
ProcessingInstruction(Pi),
Comment(StrTendril),
Characters(StrTendril),
EndOfFile,
NullCharacter,
ParseError(Cow<'static, str>),
}
pub trait TokenSink {
type Handle;
fn process_token(&self, token: Token) -> ProcessResult<Self::Handle>;
fn end(&self) {}
}