mirror of
https://github.com/servo/servo.git
synced 2025-08-06 06:00:15 +01:00
script: Limit public exports. (#34915)
* script: Restrict reexport visibility of DOM types. Signed-off-by: Josh Matthews <josh@joshmatthews.net> * script: Mass pub->pub(crate) conversion. Signed-off-by: Josh Matthews <josh@joshmatthews.net> * script: Hide existing dead code warnings. Signed-off-by: Josh Matthews <josh@joshmatthews.net> * Formatting. Signed-off-by: Josh Matthews <josh@joshmatthews.net> * Fix clippy warnings. Signed-off-by: Josh Matthews <josh@joshmatthews.net> * Formatting. Signed-off-by: Josh Matthews <josh@joshmatthews.net> * Fix unit tests. Signed-off-by: Josh Matthews <josh@joshmatthews.net> * Fix clippy. Signed-off-by: Josh Matthews <josh@joshmatthews.net> * More formatting. Signed-off-by: Josh Matthews <josh@joshmatthews.net> --------- Signed-off-by: Josh Matthews <josh@joshmatthews.net>
This commit is contained in:
parent
f220d6d3a5
commit
c94d909a86
585 changed files with 5411 additions and 5013 deletions
|
@ -9,26 +9,26 @@ use super::Node;
|
|||
use crate::dom::bindings::root::DomRoot;
|
||||
|
||||
/// The context during evaluation of an XPath expression.
|
||||
pub struct EvaluationCtx {
|
||||
pub(crate) struct EvaluationCtx {
|
||||
/// Where we started at
|
||||
pub starting_node: DomRoot<Node>,
|
||||
pub(crate) starting_node: DomRoot<Node>,
|
||||
/// The "current" node in the evaluation
|
||||
pub context_node: DomRoot<Node>,
|
||||
pub(crate) context_node: DomRoot<Node>,
|
||||
/// Details needed for evaluating a predicate list
|
||||
pub predicate_ctx: Option<PredicateCtx>,
|
||||
pub(crate) predicate_ctx: Option<PredicateCtx>,
|
||||
/// The nodes we're currently matching against
|
||||
pub predicate_nodes: Option<Vec<DomRoot<Node>>>,
|
||||
pub(crate) predicate_nodes: Option<Vec<DomRoot<Node>>>,
|
||||
}
|
||||
|
||||
#[derive(Clone, Copy)]
|
||||
pub struct PredicateCtx {
|
||||
pub index: usize,
|
||||
pub size: usize,
|
||||
pub(crate) struct PredicateCtx {
|
||||
pub(crate) index: usize,
|
||||
pub(crate) size: usize,
|
||||
}
|
||||
|
||||
impl EvaluationCtx {
|
||||
/// Prepares the context used while evaluating the XPath expression
|
||||
pub fn new(context_node: &Node) -> EvaluationCtx {
|
||||
pub(crate) fn new(context_node: &Node) -> EvaluationCtx {
|
||||
EvaluationCtx {
|
||||
starting_node: DomRoot::from_ref(context_node),
|
||||
context_node: DomRoot::from_ref(context_node),
|
||||
|
@ -38,7 +38,7 @@ impl EvaluationCtx {
|
|||
}
|
||||
|
||||
/// Creates a new context using the provided node as the context node
|
||||
pub fn subcontext_for_node(&self, node: &Node) -> EvaluationCtx {
|
||||
pub(crate) fn subcontext_for_node(&self, node: &Node) -> EvaluationCtx {
|
||||
EvaluationCtx {
|
||||
starting_node: self.starting_node.clone(),
|
||||
context_node: DomRoot::from_ref(node),
|
||||
|
@ -47,7 +47,7 @@ impl EvaluationCtx {
|
|||
}
|
||||
}
|
||||
|
||||
pub fn update_predicate_nodes(&self, nodes: Vec<&Node>) -> EvaluationCtx {
|
||||
pub(crate) fn update_predicate_nodes(&self, nodes: Vec<&Node>) -> EvaluationCtx {
|
||||
EvaluationCtx {
|
||||
starting_node: self.starting_node.clone(),
|
||||
context_node: self.context_node.clone(),
|
||||
|
@ -56,7 +56,7 @@ impl EvaluationCtx {
|
|||
}
|
||||
}
|
||||
|
||||
pub fn subcontext_iter_for_nodes(&self) -> EvalNodesetIter {
|
||||
pub(crate) fn subcontext_iter_for_nodes(&self) -> EvalNodesetIter {
|
||||
let size = self.predicate_nodes.as_ref().map_or(0, |v| v.len());
|
||||
EvalNodesetIter {
|
||||
ctx: self,
|
||||
|
@ -72,7 +72,7 @@ impl EvaluationCtx {
|
|||
|
||||
/// When evaluating predicates, we need to keep track of the current node being evaluated and
|
||||
/// the index of that node in the nodeset we're operating on.
|
||||
pub struct EvalNodesetIter<'a> {
|
||||
pub(crate) struct EvalNodesetIter<'a> {
|
||||
ctx: &'a EvaluationCtx,
|
||||
nodes_iter: Enumerate<IntoIter<DomRoot<Node>>>,
|
||||
size: usize,
|
||||
|
|
|
@ -21,7 +21,7 @@ use crate::dom::node::{Node, ShadowIncluding};
|
|||
use crate::dom::processinginstruction::ProcessingInstruction;
|
||||
|
||||
#[derive(Clone, Debug, PartialEq)]
|
||||
pub enum Error {
|
||||
pub(crate) enum Error {
|
||||
NotANodeset,
|
||||
InvalidPath,
|
||||
UnknownFunction { name: QualName },
|
||||
|
@ -57,14 +57,14 @@ impl std::fmt::Display for Error {
|
|||
|
||||
impl std::error::Error for Error {}
|
||||
|
||||
pub fn try_extract_nodeset(v: Value) -> Result<Vec<DomRoot<Node>>, Error> {
|
||||
pub(crate) fn try_extract_nodeset(v: Value) -> Result<Vec<DomRoot<Node>>, Error> {
|
||||
match v {
|
||||
Value::Nodeset(ns) => Ok(ns),
|
||||
_ => Err(Error::NotANodeset),
|
||||
}
|
||||
}
|
||||
|
||||
pub trait Evaluatable: fmt::Debug {
|
||||
pub(crate) trait Evaluatable: fmt::Debug {
|
||||
fn evaluate(&self, context: &EvaluationCtx) -> Result<Value, Error>;
|
||||
/// Returns true if this expression evaluates to a primitive value, without needing to touch the DOM
|
||||
fn is_primitive(&self) -> bool;
|
||||
|
@ -245,14 +245,14 @@ impl TryFrom<&ParserQualName> for QualName {
|
|||
}
|
||||
}
|
||||
|
||||
pub enum NameTestComparisonMode {
|
||||
pub(crate) enum NameTestComparisonMode {
|
||||
/// Namespaces must match exactly
|
||||
XHtml,
|
||||
/// Missing namespace information is treated as the HTML namespace
|
||||
Html,
|
||||
}
|
||||
|
||||
pub fn element_name_test(
|
||||
pub(crate) fn element_name_test(
|
||||
expected_name: QualName,
|
||||
element_qualname: QualName,
|
||||
comparison_mode: NameTestComparisonMode,
|
||||
|
|
|
@ -75,7 +75,7 @@ fn substring(s: &str, start_idx: isize, len: Option<isize>) -> String {
|
|||
}
|
||||
|
||||
/// <https://www.w3.org/TR/1999/REC-xpath-19991116/#function-normalize-space>
|
||||
pub fn normalize_space(s: &str) -> String {
|
||||
pub(crate) fn normalize_space(s: &str) -> String {
|
||||
let mut result = String::with_capacity(s.len());
|
||||
let mut last_was_whitespace = true; // Handles leading whitespace
|
||||
|
||||
|
|
|
@ -12,7 +12,7 @@ use crate::dom::bindings::utils::AsVoidPtr;
|
|||
use crate::dom::node::Node;
|
||||
|
||||
/// The primary types of values that an XPath expression returns as a result.
|
||||
pub enum Value {
|
||||
pub(crate) enum Value {
|
||||
Boolean(bool),
|
||||
/// A IEEE-754 double-precision floating point number
|
||||
Number(f64),
|
||||
|
@ -32,7 +32,7 @@ impl fmt::Debug for Value {
|
|||
}
|
||||
}
|
||||
|
||||
pub fn str_to_num(s: &str) -> f64 {
|
||||
pub(crate) fn str_to_num(s: &str) -> f64 {
|
||||
s.trim().parse().unwrap_or(f64::NAN)
|
||||
}
|
||||
|
||||
|
@ -78,7 +78,7 @@ impl PartialEq<Value> for Value {
|
|||
}
|
||||
|
||||
impl Value {
|
||||
pub fn boolean(&self) -> bool {
|
||||
pub(crate) fn boolean(&self) -> bool {
|
||||
match *self {
|
||||
Value::Boolean(val) => val,
|
||||
Value::Number(n) => n != 0.0 && !n.is_nan(),
|
||||
|
@ -87,11 +87,11 @@ impl Value {
|
|||
}
|
||||
}
|
||||
|
||||
pub fn into_boolean(self) -> bool {
|
||||
pub(crate) fn into_boolean(self) -> bool {
|
||||
self.boolean()
|
||||
}
|
||||
|
||||
pub fn number(&self) -> f64 {
|
||||
pub(crate) fn number(&self) -> f64 {
|
||||
match *self {
|
||||
Value::Boolean(val) => {
|
||||
if val {
|
||||
|
@ -106,11 +106,11 @@ impl Value {
|
|||
}
|
||||
}
|
||||
|
||||
pub fn into_number(self) -> f64 {
|
||||
pub(crate) fn into_number(self) -> f64 {
|
||||
self.number()
|
||||
}
|
||||
|
||||
pub fn string(&self) -> string::String {
|
||||
pub(crate) fn string(&self) -> string::String {
|
||||
match *self {
|
||||
Value::Boolean(v) => v.to_string(),
|
||||
Value::Number(n) => {
|
||||
|
@ -135,7 +135,7 @@ impl Value {
|
|||
}
|
||||
}
|
||||
|
||||
pub fn into_string(self) -> string::String {
|
||||
pub(crate) fn into_string(self) -> string::String {
|
||||
match self {
|
||||
Value::String(val) => val,
|
||||
other => other.string(),
|
||||
|
@ -191,7 +191,7 @@ partial_eq_impl!(String, Value::String(ref v) => v);
|
|||
partial_eq_impl!(&str, Value::String(ref v) => v);
|
||||
partial_eq_impl!(Vec<DomRoot<Node>>, Value::Nodeset(ref v) => v);
|
||||
|
||||
pub trait NodesetHelpers {
|
||||
pub(crate) trait NodesetHelpers {
|
||||
/// Returns the node that occurs first in [document order]
|
||||
///
|
||||
/// [document order]: https://www.w3.org/TR/xpath/#dt-document-order
|
||||
|
|
|
@ -4,21 +4,24 @@
|
|||
|
||||
use context::EvaluationCtx;
|
||||
use eval::Evaluatable;
|
||||
pub use eval_value::{NodesetHelpers, Value};
|
||||
pub(crate) use eval_value::{NodesetHelpers, Value};
|
||||
use parser::OwnedParserError;
|
||||
pub use parser::{parse as parse_impl, Expr};
|
||||
pub(crate) use parser::{parse as parse_impl, Expr};
|
||||
|
||||
use super::dom::node::Node;
|
||||
|
||||
mod context;
|
||||
#[allow(dead_code)]
|
||||
mod eval;
|
||||
mod eval_function;
|
||||
#[allow(dead_code)]
|
||||
mod eval_value;
|
||||
#[allow(dead_code)]
|
||||
mod parser;
|
||||
|
||||
/// The failure modes of executing an XPath.
|
||||
#[derive(Debug, PartialEq)]
|
||||
pub enum Error {
|
||||
pub(crate) enum Error {
|
||||
/// The XPath was syntactically invalid
|
||||
Parsing { source: OwnedParserError },
|
||||
/// The XPath could not be executed
|
||||
|
@ -44,7 +47,7 @@ impl std::error::Error for Error {
|
|||
}
|
||||
|
||||
/// Parse an XPath expression from a string
|
||||
pub fn parse(xpath: &str) -> Result<Expr, Error> {
|
||||
pub(crate) fn parse(xpath: &str) -> Result<Expr, Error> {
|
||||
match parse_impl(xpath) {
|
||||
Ok(expr) => {
|
||||
debug!("Parsed XPath: {:?}", expr);
|
||||
|
@ -58,7 +61,7 @@ pub fn parse(xpath: &str) -> Result<Expr, Error> {
|
|||
}
|
||||
|
||||
/// Evaluate an already-parsed XPath expression
|
||||
pub fn evaluate_parsed_xpath(expr: &Expr, context_node: &Node) -> Result<Value, Error> {
|
||||
pub(crate) fn evaluate_parsed_xpath(expr: &Expr, context_node: &Node) -> Result<Value, Error> {
|
||||
let context = EvaluationCtx::new(context_node);
|
||||
match expr.evaluate(&context) {
|
||||
Ok(v) => {
|
||||
|
|
|
@ -11,13 +11,13 @@ use nom::multi::{many0, separated_list0};
|
|||
use nom::sequence::{delimited, pair, preceded, tuple};
|
||||
use nom::{Finish, IResult};
|
||||
|
||||
pub fn parse(input: &str) -> Result<Expr, OwnedParserError> {
|
||||
pub(crate) fn parse(input: &str) -> Result<Expr, OwnedParserError> {
|
||||
let (_, ast) = expr(input).finish().map_err(OwnedParserError::from)?;
|
||||
Ok(ast)
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, MallocSizeOf, PartialEq)]
|
||||
pub enum Expr {
|
||||
pub(crate) enum Expr {
|
||||
Or(Box<Expr>, Box<Expr>),
|
||||
And(Box<Expr>, Box<Expr>),
|
||||
Equality(Box<Expr>, EqualityOp, Box<Expr>),
|
||||
|
@ -30,13 +30,13 @@ pub enum Expr {
|
|||
}
|
||||
|
||||
#[derive(Clone, Debug, MallocSizeOf, PartialEq)]
|
||||
pub enum EqualityOp {
|
||||
pub(crate) enum EqualityOp {
|
||||
Eq,
|
||||
NotEq,
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, MallocSizeOf, PartialEq)]
|
||||
pub enum RelationalOp {
|
||||
pub(crate) enum RelationalOp {
|
||||
Lt,
|
||||
Gt,
|
||||
LtEq,
|
||||
|
@ -44,61 +44,61 @@ pub enum RelationalOp {
|
|||
}
|
||||
|
||||
#[derive(Clone, Debug, MallocSizeOf, PartialEq)]
|
||||
pub enum AdditiveOp {
|
||||
pub(crate) enum AdditiveOp {
|
||||
Add,
|
||||
Sub,
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, MallocSizeOf, PartialEq)]
|
||||
pub enum MultiplicativeOp {
|
||||
pub(crate) enum MultiplicativeOp {
|
||||
Mul,
|
||||
Div,
|
||||
Mod,
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, MallocSizeOf, PartialEq)]
|
||||
pub enum UnaryOp {
|
||||
pub(crate) enum UnaryOp {
|
||||
Minus,
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, MallocSizeOf, PartialEq)]
|
||||
pub struct PathExpr {
|
||||
pub is_absolute: bool,
|
||||
pub is_descendant: bool,
|
||||
pub steps: Vec<StepExpr>,
|
||||
pub(crate) struct PathExpr {
|
||||
pub(crate) is_absolute: bool,
|
||||
pub(crate) is_descendant: bool,
|
||||
pub(crate) steps: Vec<StepExpr>,
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, MallocSizeOf, PartialEq)]
|
||||
pub struct PredicateListExpr {
|
||||
pub predicates: Vec<PredicateExpr>,
|
||||
pub(crate) struct PredicateListExpr {
|
||||
pub(crate) predicates: Vec<PredicateExpr>,
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, MallocSizeOf, PartialEq)]
|
||||
pub struct PredicateExpr {
|
||||
pub expr: Expr,
|
||||
pub(crate) struct PredicateExpr {
|
||||
pub(crate) expr: Expr,
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, MallocSizeOf, PartialEq)]
|
||||
pub struct FilterExpr {
|
||||
pub primary: PrimaryExpr,
|
||||
pub predicates: PredicateListExpr,
|
||||
pub(crate) struct FilterExpr {
|
||||
pub(crate) primary: PrimaryExpr,
|
||||
pub(crate) predicates: PredicateListExpr,
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, MallocSizeOf, PartialEq)]
|
||||
pub enum StepExpr {
|
||||
pub(crate) enum StepExpr {
|
||||
Filter(FilterExpr),
|
||||
Axis(AxisStep),
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, MallocSizeOf, PartialEq)]
|
||||
pub struct AxisStep {
|
||||
pub axis: Axis,
|
||||
pub node_test: NodeTest,
|
||||
pub predicates: PredicateListExpr,
|
||||
pub(crate) struct AxisStep {
|
||||
pub(crate) axis: Axis,
|
||||
pub(crate) node_test: NodeTest,
|
||||
pub(crate) predicates: PredicateListExpr,
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, MallocSizeOf, PartialEq)]
|
||||
pub enum Axis {
|
||||
pub(crate) enum Axis {
|
||||
Child,
|
||||
Descendant,
|
||||
Attribute,
|
||||
|
@ -115,16 +115,16 @@ pub enum Axis {
|
|||
}
|
||||
|
||||
#[derive(Clone, Debug, MallocSizeOf, PartialEq)]
|
||||
pub enum NodeTest {
|
||||
pub(crate) enum NodeTest {
|
||||
Name(QName),
|
||||
Wildcard,
|
||||
Kind(KindTest),
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, MallocSizeOf, PartialEq)]
|
||||
pub struct QName {
|
||||
pub prefix: Option<String>,
|
||||
pub local_part: String,
|
||||
pub(crate) struct QName {
|
||||
pub(crate) prefix: Option<String>,
|
||||
pub(crate) local_part: String,
|
||||
}
|
||||
|
||||
impl std::fmt::Display for QName {
|
||||
|
@ -137,7 +137,7 @@ impl std::fmt::Display for QName {
|
|||
}
|
||||
|
||||
#[derive(Clone, Debug, MallocSizeOf, PartialEq)]
|
||||
pub enum KindTest {
|
||||
pub(crate) enum KindTest {
|
||||
PI(Option<String>),
|
||||
Comment,
|
||||
Text,
|
||||
|
@ -145,7 +145,7 @@ pub enum KindTest {
|
|||
}
|
||||
|
||||
#[derive(Clone, Debug, MallocSizeOf, PartialEq)]
|
||||
pub enum PrimaryExpr {
|
||||
pub(crate) enum PrimaryExpr {
|
||||
Literal(Literal),
|
||||
Variable(QName),
|
||||
Parenthesized(Box<Expr>),
|
||||
|
@ -155,20 +155,20 @@ pub enum PrimaryExpr {
|
|||
}
|
||||
|
||||
#[derive(Clone, Debug, MallocSizeOf, PartialEq)]
|
||||
pub enum Literal {
|
||||
pub(crate) enum Literal {
|
||||
Numeric(NumericLiteral),
|
||||
String(String),
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, MallocSizeOf, PartialEq)]
|
||||
pub enum NumericLiteral {
|
||||
pub(crate) enum NumericLiteral {
|
||||
Integer(u64),
|
||||
Decimal(f64),
|
||||
}
|
||||
|
||||
/// In the DOM we do not support custom functions, so we can enumerate the usable ones
|
||||
#[derive(Clone, Debug, MallocSizeOf, PartialEq)]
|
||||
pub enum CoreFunction {
|
||||
pub(crate) enum CoreFunction {
|
||||
// Node Set Functions
|
||||
/// last()
|
||||
Last,
|
||||
|
@ -233,7 +233,7 @@ pub enum CoreFunction {
|
|||
}
|
||||
|
||||
impl CoreFunction {
|
||||
pub fn name(&self) -> &'static str {
|
||||
pub(crate) fn name(&self) -> &'static str {
|
||||
match self {
|
||||
CoreFunction::Last => "last",
|
||||
CoreFunction::Position => "position",
|
||||
|
@ -265,7 +265,7 @@ impl CoreFunction {
|
|||
}
|
||||
}
|
||||
|
||||
pub fn min_args(&self) -> usize {
|
||||
pub(crate) fn min_args(&self) -> usize {
|
||||
match self {
|
||||
// No args
|
||||
CoreFunction::Last |
|
||||
|
@ -306,7 +306,7 @@ impl CoreFunction {
|
|||
}
|
||||
}
|
||||
|
||||
pub fn max_args(&self) -> Option<usize> {
|
||||
pub(crate) fn max_args(&self) -> Option<usize> {
|
||||
match self {
|
||||
// No args
|
||||
CoreFunction::Last |
|
||||
|
@ -348,7 +348,7 @@ impl CoreFunction {
|
|||
}
|
||||
|
||||
/// Returns true if the number of arguments is valid for this function
|
||||
pub fn is_valid_arity(&self, num_args: usize) -> bool {
|
||||
pub(crate) fn is_valid_arity(&self, num_args: usize) -> bool {
|
||||
let min = self.min_args();
|
||||
let max = self.max_args();
|
||||
|
||||
|
@ -357,7 +357,7 @@ impl CoreFunction {
|
|||
}
|
||||
|
||||
#[derive(Clone, Debug, PartialEq)]
|
||||
pub struct OwnedParserError {
|
||||
pub(crate) struct OwnedParserError {
|
||||
input: String,
|
||||
kind: NomErrorKind,
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue