mirror of
https://github.com/servo/servo.git
synced 2025-08-03 12:40:06 +01:00
Format and tidy
Signed-off-by: Ville Lindholm <ville@lindholm.dev>
This commit is contained in:
parent
a2d8bf73d8
commit
26c0806f63
3 changed files with 49 additions and 39 deletions
|
@ -8,8 +8,8 @@ use std::vec::IntoIter;
|
|||
use script_bindings::str::DOMString;
|
||||
|
||||
use super::Node;
|
||||
use crate::dom::bindings::root::DomRoot;
|
||||
use crate::dom::bindings::codegen::Bindings::NodeBinding::NodeMethods;
|
||||
use crate::dom::bindings::root::DomRoot;
|
||||
|
||||
/// The context during evaluation of an XPath expression.
|
||||
#[derive(Debug)]
|
||||
|
@ -75,7 +75,8 @@ impl EvaluationCtx {
|
|||
|
||||
/// Resolve a namespace prefix using the context node's document
|
||||
pub(crate) fn resolve_namespace(&self, prefix: Option<&str>) -> Option<DOMString> {
|
||||
self.context_node.LookupNamespaceURI(prefix.map(DOMString::from))
|
||||
self.context_node
|
||||
.LookupNamespaceURI(prefix.map(DOMString::from))
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -257,7 +257,9 @@ impl<'a> TryFrom<QualNameConverter<'a>> for QualName {
|
|||
|
||||
fn try_from(converter: QualNameConverter<'a>) -> Result<Self, Self::Error> {
|
||||
let qname_as_str = converter.qname.to_string();
|
||||
let namespace = converter.context.resolve_namespace(converter.qname.prefix.as_deref());
|
||||
let namespace = converter
|
||||
.context
|
||||
.resolve_namespace(converter.qname.prefix.as_deref());
|
||||
|
||||
if let Ok((ns, prefix, local)) = validate_and_extract(namespace, &qname_as_str) {
|
||||
Ok(QualName { prefix, ns, local })
|
||||
|
@ -326,18 +328,18 @@ fn apply_node_test(context: &EvaluationCtx, test: &NodeTest, node: &Node) -> Res
|
|||
let wanted_name: QualName = QualNameConverter { qname, context }.try_into()?;
|
||||
match node.type_id() {
|
||||
NodeTypeId::Element(_) => {
|
||||
let element = node.downcast::<Element>().unwrap();
|
||||
let element = node.downcast::<Element>().unwrap();
|
||||
let comparison_mode = if node.owner_doc().is_html_document() {
|
||||
NameTestComparisonMode::Html
|
||||
} else {
|
||||
NameTestComparisonMode::XHtml
|
||||
};
|
||||
let element_qualname = QualName::new(
|
||||
element.prefix().as_ref().cloned(),
|
||||
element.namespace().clone(),
|
||||
element.local_name().clone(),
|
||||
);
|
||||
element_name_test(wanted_name, element_qualname, comparison_mode)
|
||||
NameTestComparisonMode::XHtml
|
||||
};
|
||||
let element_qualname = QualName::new(
|
||||
element.prefix().as_ref().cloned(),
|
||||
element.namespace().clone(),
|
||||
element.local_name().clone(),
|
||||
);
|
||||
element_name_test(wanted_name, element_qualname, comparison_mode)
|
||||
},
|
||||
NodeTypeId::Attr => {
|
||||
let attr = node.downcast::<Attr>().unwrap();
|
||||
|
|
|
@ -510,29 +510,35 @@ fn union_expr(input: &str) -> IResult<&str, Expr> {
|
|||
fn path_expr(input: &str) -> IResult<&str, Expr> {
|
||||
alt((
|
||||
// "//" RelativePathExpr
|
||||
map(pair(tag("//"), move |i| relative_path_expr(true, i)), |(_, rel_path)| {
|
||||
Expr::Path(PathExpr {
|
||||
is_absolute: true,
|
||||
is_descendant: true,
|
||||
steps: match rel_path {
|
||||
Expr::Path(p) => p.steps,
|
||||
_ => unreachable!(),
|
||||
},
|
||||
})
|
||||
}),
|
||||
// "/" RelativePathExpr?
|
||||
map(pair(char('/'), opt(move |i| relative_path_expr(false, i))), |(_, rel_path)| {
|
||||
Expr::Path(PathExpr {
|
||||
is_absolute: true,
|
||||
is_descendant: false,
|
||||
steps: rel_path
|
||||
.map(|p| match p {
|
||||
map(
|
||||
pair(tag("//"), move |i| relative_path_expr(true, i)),
|
||||
|(_, rel_path)| {
|
||||
Expr::Path(PathExpr {
|
||||
is_absolute: true,
|
||||
is_descendant: true,
|
||||
steps: match rel_path {
|
||||
Expr::Path(p) => p.steps,
|
||||
_ => unreachable!(),
|
||||
})
|
||||
.unwrap_or_default(),
|
||||
})
|
||||
}),
|
||||
},
|
||||
})
|
||||
},
|
||||
),
|
||||
// "/" RelativePathExpr?
|
||||
map(
|
||||
pair(char('/'), opt(move |i| relative_path_expr(false, i))),
|
||||
|(_, rel_path)| {
|
||||
Expr::Path(PathExpr {
|
||||
is_absolute: true,
|
||||
is_descendant: false,
|
||||
steps: rel_path
|
||||
.map(|p| match p {
|
||||
Expr::Path(p) => p.steps,
|
||||
_ => unreachable!(),
|
||||
})
|
||||
.unwrap_or_default(),
|
||||
})
|
||||
},
|
||||
),
|
||||
// RelativePathExpr
|
||||
move |i| relative_path_expr(false, i),
|
||||
))(input)
|
||||
|
@ -576,8 +582,10 @@ fn step_expr(is_descendant: bool, input: &str) -> IResult<&str, StepExpr> {
|
|||
}
|
||||
|
||||
fn axis_step(is_descendant: bool, input: &str) -> IResult<&str, AxisStep> {
|
||||
let (input, (step, predicates)) =
|
||||
pair(alt((move |i| forward_step(is_descendant, i), reverse_step)), predicate_list)(input)?;
|
||||
let (input, (step, predicates)) = pair(
|
||||
alt((move |i| forward_step(is_descendant, i), reverse_step)),
|
||||
predicate_list,
|
||||
)(input)?;
|
||||
|
||||
let (axis, node_test) = step;
|
||||
Ok((
|
||||
|
@ -591,10 +599,9 @@ fn axis_step(is_descendant: bool, input: &str) -> IResult<&str, AxisStep> {
|
|||
}
|
||||
|
||||
fn forward_step(is_descendant: bool, input: &str) -> IResult<&str, (Axis, NodeTest)> {
|
||||
alt((
|
||||
pair(forward_axis, node_test),
|
||||
move |i| abbrev_forward_step(is_descendant, i),
|
||||
))(input)
|
||||
alt((pair(forward_axis, node_test), move |i| {
|
||||
abbrev_forward_step(is_descendant, i)
|
||||
}))(input)
|
||||
}
|
||||
|
||||
fn forward_axis(input: &str) -> IResult<&str, Axis> {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue