mod ast;
mod error;
mod eval;
mod glob;
mod lex;
mod node;
mod parse;
mod suggest;
mod token;
pub use ast::{
AttrDef, AttrPred, AttrType, Axis, AxisKind, CmpOp, Combinator, Literal, Path, Pred, Pseudo,
PseudoArity, PseudoDef, Selector, Step, AXIS_NAMES, COMMON_ATTRS, PSEUDO_DEFS,
};
pub use error::{SelectorError, SelectorErrorKind};
pub use eval::{count, select, select_with, EvalLimits};
pub use glob::Glob;
pub use node::{
control_axis, control_kind_name, paragraphs_of_control, runs_of, Node, NodeId, NodeRef,
NodeStep, PathStack, RunView,
};
pub use parse::{parse, MAX_NESTING, MAX_PATHS, MAX_PREDS, MAX_SOURCE_CHARS, MAX_STEPS};
pub use token::{Tok, Token};
pub fn tokenize(source: &str) -> Result<Vec<Token>, SelectorError> {
lex::lex(source).map(|l| l.tokens)
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn public_surface_parses_a_realistic_selector() {
let sel = parse("section:nth(2) > table:last cell[row=-1]").unwrap();
assert_eq!(sel.paths.len(), 1);
assert_eq!(sel.paths[0].steps.len(), 3);
assert_eq!(sel.result_axes(), vec![Axis::Kind(AxisKind::Cell)]);
}
#[test]
fn tokenize_survives_an_incomplete_selector() {
assert!(parse("para[te").is_err());
assert!(tokenize("para[te").is_ok());
}
#[test]
fn document_derived_text_is_never_reinterpreted_as_syntax() {
let sel = parse(r#"para[text="para:has(table)"]"#).unwrap();
match &sel.paths[0].steps[0].preds[0] {
Pred::Attr(a) => assert_eq!(
a.compare,
Some((CmpOp::Eq, Literal::Str("para:has(table)".into())))
),
other => panic!("{other:?}"),
}
assert_eq!(sel.paths[0].steps[0].preds.len(), 1);
}
}