pub(crate) mod ast;
mod builder;
mod display;
mod dom;
mod matcher;
mod parser;
#[cfg(test)]
mod tests;
pub use self::ast::{Compound, Selector};
pub use self::dom::{Dom, Element, NodeId};
pub use self::matcher::SelectorSubject;
use std::fmt;
#[derive(Debug, Clone, PartialEq, Eq)]
#[non_exhaustive]
pub enum SelectorError {
EmptySelector,
UnexpectedToken,
UnexpectedEnd,
DanglingCombinator,
MissingAttributeName,
UnexpectedTokenInAttribute,
UnsupportedCombinator(char),
UnsupportedPseudoClass,
NamespacedSelector,
EmptyNegation,
InvalidNth,
}
impl fmt::Display for SelectorError {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self {
Self::EmptySelector => f.write_str("empty selector"),
Self::UnexpectedToken => f.write_str("unexpected token in selector"),
Self::UnexpectedEnd => f.write_str("unexpected end of selector"),
Self::DanglingCombinator => f.write_str("dangling combinator in selector"),
Self::MissingAttributeName => {
f.write_str("missing attribute name in attribute selector")
}
Self::UnexpectedTokenInAttribute => {
f.write_str("unexpected token in attribute selector")
}
Self::UnsupportedCombinator(c) => {
write!(f, "unsupported combinator `{c}` in selector")
}
Self::UnsupportedPseudoClass => {
f.write_str("unsupported pseudo-class or pseudo-element in selector")
}
Self::NamespacedSelector => {
f.write_str("selectors with explicit namespaces are not supported")
}
Self::EmptyNegation => f.write_str("empty `:not()` in selector"),
Self::InvalidNth => f.write_str("invalid `An+B` value in selector"),
}
}
}
impl std::error::Error for SelectorError {}