parser/expr: Don't next() the precedences in bind; it makes everything less readable.
This commit is contained in:
@@ -499,26 +499,23 @@ fn parse_for(p: &mut Parser<'_>, _level: ()) -> PResult<Expr> {
|
|||||||
|
|
||||||
/// Returns the [BindOp], [pattern precedence](PPrec), [arrow TKind](TKind), [body precedence](Prec),
|
/// Returns the [BindOp], [pattern precedence](PPrec), [arrow TKind](TKind), [body precedence](Prec),
|
||||||
/// and [else precedence](Prec), (if applicable,) which controls the parsing of Bind expressions.
|
/// and [else precedence](Prec), (if applicable,) which controls the parsing of Bind expressions.
|
||||||
///
|
|
||||||
/// The returned expression [Prec]edences are expected to be [`Prec::next`]ed, so they may
|
|
||||||
/// be one level of precedence lower than would be intuitive (i.e. [Prec::Assign] instead of [Prec::Tuple])
|
|
||||||
#[rustfmt::skip]
|
#[rustfmt::skip]
|
||||||
#[allow(clippy::type_complexity)]
|
#[allow(clippy::type_complexity)]
|
||||||
fn from_bind(p: &mut Parser<'_>) -> PResult<(BindOp, PPrec, Option<TKind>, Option<Prec>, Option<Prec>)> {
|
fn from_bind(p: &mut Parser<'_>) -> PResult<(BindOp, PPrec, Option<TKind>, Option<Prec>, Option<Prec>)> {
|
||||||
let bk = match p.peek()?.kind {
|
let bk = match p.peek()?.kind {
|
||||||
// Token Operator Pat prec Body Token Body prec Else prec
|
// Token Operator Pat prec Body Token Body prec Else prec
|
||||||
TKind::Let => (BindOp::Let, PPrec::Tuple, Some(TKind::Eq), Some(Prec::Assign), Some(Prec::Body)),
|
TKind::Let => (BindOp::Let, PPrec::Tuple, Some(TKind::Eq), Some(Prec::Tuple), Some(Prec::Body)),
|
||||||
TKind::Const => (BindOp::Const, PPrec::Tuple, Some(TKind::Eq), Some(Prec::Assign), None),
|
TKind::Const => (BindOp::Const, PPrec::Tuple, Some(TKind::Eq), Some(Prec::Tuple), None),
|
||||||
TKind::Static => (BindOp::Static, PPrec::Tuple, Some(TKind::Eq), Some(Prec::Assign), None),
|
TKind::Static => (BindOp::Static, PPrec::Tuple, Some(TKind::Eq), Some(Prec::Tuple), None),
|
||||||
TKind::Type => (BindOp::Type, PPrec::Tuple, Some(TKind::Eq), Some(Prec::Project), None),
|
TKind::Type => (BindOp::Type, PPrec::Tuple, Some(TKind::Eq), Some(Prec::Extend), None),
|
||||||
TKind::Struct => (BindOp::Struct, PPrec::Tuple, None, None, None),
|
TKind::Struct => (BindOp::Struct, PPrec::Tuple, None, None, None),
|
||||||
TKind::Enum => (BindOp::Enum, PPrec::Tuple, None, None, None),
|
TKind::Enum => (BindOp::Enum, PPrec::Tuple, None, None, None),
|
||||||
TKind::Fn => (BindOp::Fn, PPrec::Fn, None, Some(Prec::Body), None),
|
TKind::Fn => (BindOp::Fn, PPrec::Fn, None, Some(Prec::Body), None),
|
||||||
TKind::Mod => (BindOp::Mod, PPrec::Max, None, Some(Prec::Body), None),
|
TKind::Mod => (BindOp::Mod, PPrec::Max, None, Some(Prec::Body), None),
|
||||||
TKind::Impl => (BindOp::Impl, PPrec::Max, None, Some(Prec::Body), None),
|
TKind::Impl => (BindOp::Impl, PPrec::Max, None, Some(Prec::Body), None),
|
||||||
TKind::Bar => (BindOp::Match, PPrec::Alt, Some(TKind::FatArrow), Some(Prec::Body), None),
|
TKind::Bar => (BindOp::Match, PPrec::Alt, Some(TKind::FatArrow), Some(Prec::Body), None),
|
||||||
// no consume!
|
// no consume!
|
||||||
_ => return Ok((BindOp::Match, PPrec::Alt, Some(TKind::FatArrow), Some(Prec::Body), None)),
|
_ => return Ok((BindOp::Match, PPrec::Alt, Some(TKind::FatArrow), Some(Prec::Body), None)),
|
||||||
};
|
};
|
||||||
|
|
||||||
p.consume();
|
p.consume();
|
||||||
@@ -559,7 +556,7 @@ impl<'t> Parse<'t> for Bind {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// `=` Expr
|
// `=` Expr
|
||||||
let body = p.parse(bodyp.next())?;
|
let body = p.parse(bodyp.value())?;
|
||||||
|
|
||||||
let Some(failp) = failp else {
|
let Some(failp) = failp else {
|
||||||
return Ok(Self(level, generics, pat, vec![body]));
|
return Ok(Self(level, generics, pat, vec![body]));
|
||||||
@@ -573,7 +570,7 @@ impl<'t> Parse<'t> for Bind {
|
|||||||
return Ok(Self(level, generics, pat, vec![body]));
|
return Ok(Self(level, generics, pat, vec![body]));
|
||||||
}
|
}
|
||||||
|
|
||||||
let fail = p.parse(failp.next())?;
|
let fail = p.parse(failp.value())?;
|
||||||
|
|
||||||
Ok(Self(level, generics, pat, vec![body, fail]))
|
Ok(Self(level, generics, pat, vec![body, fail]))
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user