mirror of
https://github.com/servo/servo.git
synced 2025-08-05 13:40:08 +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 script_bindings::str::DOMString;
|
||||||
|
|
||||||
use super::Node;
|
use super::Node;
|
||||||
use crate::dom::bindings::root::DomRoot;
|
|
||||||
use crate::dom::bindings::codegen::Bindings::NodeBinding::NodeMethods;
|
use crate::dom::bindings::codegen::Bindings::NodeBinding::NodeMethods;
|
||||||
|
use crate::dom::bindings::root::DomRoot;
|
||||||
|
|
||||||
/// The context during evaluation of an XPath expression.
|
/// The context during evaluation of an XPath expression.
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
|
@ -75,7 +75,8 @@ impl EvaluationCtx {
|
||||||
|
|
||||||
/// Resolve a namespace prefix using the context node's document
|
/// Resolve a namespace prefix using the context node's document
|
||||||
pub(crate) fn resolve_namespace(&self, prefix: Option<&str>) -> Option<DOMString> {
|
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> {
|
fn try_from(converter: QualNameConverter<'a>) -> Result<Self, Self::Error> {
|
||||||
let qname_as_str = converter.qname.to_string();
|
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) {
|
if let Ok((ns, prefix, local)) = validate_and_extract(namespace, &qname_as_str) {
|
||||||
Ok(QualName { prefix, ns, local })
|
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()?;
|
let wanted_name: QualName = QualNameConverter { qname, context }.try_into()?;
|
||||||
match node.type_id() {
|
match node.type_id() {
|
||||||
NodeTypeId::Element(_) => {
|
NodeTypeId::Element(_) => {
|
||||||
let element = node.downcast::<Element>().unwrap();
|
let element = node.downcast::<Element>().unwrap();
|
||||||
let comparison_mode = if node.owner_doc().is_html_document() {
|
let comparison_mode = if node.owner_doc().is_html_document() {
|
||||||
NameTestComparisonMode::Html
|
NameTestComparisonMode::Html
|
||||||
} else {
|
} else {
|
||||||
NameTestComparisonMode::XHtml
|
NameTestComparisonMode::XHtml
|
||||||
};
|
};
|
||||||
let element_qualname = QualName::new(
|
let element_qualname = QualName::new(
|
||||||
element.prefix().as_ref().cloned(),
|
element.prefix().as_ref().cloned(),
|
||||||
element.namespace().clone(),
|
element.namespace().clone(),
|
||||||
element.local_name().clone(),
|
element.local_name().clone(),
|
||||||
);
|
);
|
||||||
element_name_test(wanted_name, element_qualname, comparison_mode)
|
element_name_test(wanted_name, element_qualname, comparison_mode)
|
||||||
},
|
},
|
||||||
NodeTypeId::Attr => {
|
NodeTypeId::Attr => {
|
||||||
let attr = node.downcast::<Attr>().unwrap();
|
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> {
|
fn path_expr(input: &str) -> IResult<&str, Expr> {
|
||||||
alt((
|
alt((
|
||||||
// "//" RelativePathExpr
|
// "//" RelativePathExpr
|
||||||
map(pair(tag("//"), move |i| relative_path_expr(true, i)), |(_, rel_path)| {
|
map(
|
||||||
Expr::Path(PathExpr {
|
pair(tag("//"), move |i| relative_path_expr(true, i)),
|
||||||
is_absolute: true,
|
|(_, rel_path)| {
|
||||||
is_descendant: true,
|
Expr::Path(PathExpr {
|
||||||
steps: match rel_path {
|
is_absolute: true,
|
||||||
Expr::Path(p) => p.steps,
|
is_descendant: true,
|
||||||
_ => unreachable!(),
|
steps: match rel_path {
|
||||||
},
|
|
||||||
})
|
|
||||||
}),
|
|
||||||
// "/" 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,
|
Expr::Path(p) => p.steps,
|
||||||
_ => unreachable!(),
|
_ => 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
|
// RelativePathExpr
|
||||||
move |i| relative_path_expr(false, i),
|
move |i| relative_path_expr(false, i),
|
||||||
))(input)
|
))(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> {
|
fn axis_step(is_descendant: bool, input: &str) -> IResult<&str, AxisStep> {
|
||||||
let (input, (step, predicates)) =
|
let (input, (step, predicates)) = pair(
|
||||||
pair(alt((move |i| forward_step(is_descendant, i), reverse_step)), predicate_list)(input)?;
|
alt((move |i| forward_step(is_descendant, i), reverse_step)),
|
||||||
|
predicate_list,
|
||||||
|
)(input)?;
|
||||||
|
|
||||||
let (axis, node_test) = step;
|
let (axis, node_test) = step;
|
||||||
Ok((
|
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)> {
|
fn forward_step(is_descendant: bool, input: &str) -> IResult<&str, (Axis, NodeTest)> {
|
||||||
alt((
|
alt((pair(forward_axis, node_test), move |i| {
|
||||||
pair(forward_axis, node_test),
|
abbrev_forward_step(is_descendant, i)
|
||||||
move |i| abbrev_forward_step(is_descendant, i),
|
}))(input)
|
||||||
))(input)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn forward_axis(input: &str) -> IResult<&str, Axis> {
|
fn forward_axis(input: &str) -> IResult<&str, Axis> {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue