mirror of
https://github.com/servo/servo.git
synced 2025-10-01 17:19:16 +01:00
script: Remove unreachable assertions in xpath parser (#39588)
`relative_path_expr` can only ever return `Expr::Path`. If we make it return a `PathExpr` then callers can rely on this invariant. Testing: There's only limited testing for this change due to https://github.com/servo/servo/issues/39551. But I think that's okay, since the change is fairly trivial. Part of https://github.com/servo/servo/issues/34527 Signed-off-by: Simon Wülker <simon.wuelker@arcor.de>
This commit is contained in:
parent
6ffc0cd482
commit
0a1633c52a
1 changed files with 8 additions and 16 deletions
|
@ -394,40 +394,32 @@ fn path_expr(input: &str) -> IResult<&str, Expr> {
|
||||||
// "//" RelativePathExpr
|
// "//" RelativePathExpr
|
||||||
map(
|
map(
|
||||||
pair(tag("//"), move |i| relative_path_expr(true, i)),
|
pair(tag("//"), move |i| relative_path_expr(true, i)),
|
||||||
|(_, rel_path)| {
|
|(_, relative_path)| {
|
||||||
Expr::Path(PathExpr {
|
Expr::Path(PathExpr {
|
||||||
is_absolute: true,
|
is_absolute: true,
|
||||||
is_descendant: true,
|
is_descendant: true,
|
||||||
steps: match rel_path {
|
steps: relative_path.steps,
|
||||||
Expr::Path(p) => p.steps,
|
|
||||||
_ => unreachable!(),
|
|
||||||
},
|
|
||||||
})
|
})
|
||||||
},
|
},
|
||||||
),
|
),
|
||||||
// "/" RelativePathExpr?
|
// "/" RelativePathExpr?
|
||||||
map(
|
map(
|
||||||
pair(char('/'), opt(move |i| relative_path_expr(false, i))),
|
pair(char('/'), opt(move |i| relative_path_expr(false, i))),
|
||||||
|(_, rel_path)| {
|
|(_, relative_path)| {
|
||||||
Expr::Path(PathExpr {
|
Expr::Path(PathExpr {
|
||||||
is_absolute: true,
|
is_absolute: true,
|
||||||
is_descendant: false,
|
is_descendant: false,
|
||||||
steps: rel_path
|
steps: relative_path.map(|path| path.steps).unwrap_or_default(),
|
||||||
.map(|p| match p {
|
|
||||||
Expr::Path(p) => p.steps,
|
|
||||||
_ => unreachable!(),
|
|
||||||
})
|
|
||||||
.unwrap_or_default(),
|
|
||||||
})
|
})
|
||||||
},
|
},
|
||||||
),
|
),
|
||||||
// RelativePathExpr
|
// RelativePathExpr
|
||||||
move |i| relative_path_expr(false, i),
|
map(move |i| relative_path_expr(false, i), Expr::Path),
|
||||||
)))
|
)))
|
||||||
.parse(input)
|
.parse(input)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn relative_path_expr(is_descendant: bool, input: &str) -> IResult<&str, Expr> {
|
fn relative_path_expr(is_descendant: bool, input: &str) -> IResult<&str, PathExpr> {
|
||||||
let (input, first) = step_expr(is_descendant, input)?;
|
let (input, first) = step_expr(is_descendant, input)?;
|
||||||
let (input, steps) = many0(pair(
|
let (input, steps) = many0(pair(
|
||||||
ws(alt((value(true, tag("//")), value(false, char('/'))))),
|
ws(alt((value(true, tag("//")), value(false, char('/'))))),
|
||||||
|
@ -450,11 +442,11 @@ fn relative_path_expr(is_descendant: bool, input: &str) -> IResult<&str, Expr> {
|
||||||
|
|
||||||
Ok((
|
Ok((
|
||||||
input,
|
input,
|
||||||
Expr::Path(PathExpr {
|
PathExpr {
|
||||||
is_absolute: false,
|
is_absolute: false,
|
||||||
is_descendant: false,
|
is_descendant: false,
|
||||||
steps: all_steps,
|
steps: all_steps,
|
||||||
}),
|
},
|
||||||
))
|
))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue