Format and tidy

Signed-off-by: Ville Lindholm <ville@lindholm.dev>
This commit is contained in:
Ville Lindholm 2025-06-05 22:51:54 +03:00
parent a2d8bf73d8
commit 26c0806f63
No known key found for this signature in database
3 changed files with 49 additions and 39 deletions

View file

@ -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))
} }
} }

View file

@ -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 })

View file

@ -510,7 +510,9 @@ 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(
pair(tag("//"), move |i| relative_path_expr(true, i)),
|(_, rel_path)| {
Expr::Path(PathExpr { Expr::Path(PathExpr {
is_absolute: true, is_absolute: true,
is_descendant: true, is_descendant: true,
@ -519,9 +521,12 @@ fn path_expr(input: &str) -> IResult<&str, Expr> {
_ => unreachable!(), _ => unreachable!(),
}, },
}) })
}), },
),
// "/" RelativePathExpr? // "/" RelativePathExpr?
map(pair(char('/'), opt(move |i| relative_path_expr(false, i))), |(_, rel_path)| { map(
pair(char('/'), opt(move |i| relative_path_expr(false, i))),
|(_, rel_path)| {
Expr::Path(PathExpr { Expr::Path(PathExpr {
is_absolute: true, is_absolute: true,
is_descendant: false, is_descendant: false,
@ -532,7 +537,8 @@ fn path_expr(input: &str) -> IResult<&str, Expr> {
}) })
.unwrap_or_default(), .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> {