@@ -771,15 +771,15 @@ impl BinOp {
|
||||
pub fn precedence(&self) -> u8 {
|
||||
// Ensure that this matches the other precedence function for guards
|
||||
match self {
|
||||
Self::Or => 1,
|
||||
// Pipe is 0
|
||||
// Unary operators are 1
|
||||
Self::Or => 2,
|
||||
|
||||
Self::And => 2,
|
||||
Self::And => 3,
|
||||
|
||||
Self::Eq | Self::NotEq => 3,
|
||||
Self::Eq | Self::NotEq | Self::LtInt | Self::LtEqInt | Self::GtEqInt | Self::GtInt => 4,
|
||||
|
||||
Self::LtInt | Self::LtEqInt | Self::GtEqInt | Self::GtInt => 4,
|
||||
|
||||
// Pipe is 5
|
||||
// Concatenation operators are typically 5, so we skip it.
|
||||
Self::AddInt | Self::SubInt => 6,
|
||||
|
||||
Self::MultInt | Self::DivInt | Self::ModInt => 7,
|
||||
|
||||
@@ -651,7 +651,7 @@ impl UntypedExpr {
|
||||
pub fn binop_precedence(&self) -> u8 {
|
||||
match self {
|
||||
Self::BinOp { name, .. } => name.precedence(),
|
||||
Self::PipeLine { .. } => 5,
|
||||
Self::PipeLine { .. } => 0,
|
||||
_ => std::u8::MAX,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -799,3 +799,20 @@ fn test_fail() {
|
||||
|
||||
assert_fmt(src, src);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn pipes_and_expressions() {
|
||||
let src = indoc! {r#"
|
||||
test fmt() {
|
||||
(x == y) && ((z |> length()) == x)
|
||||
}
|
||||
"#};
|
||||
|
||||
let expected = indoc! {r#"
|
||||
test fmt() {
|
||||
x == y && ( z |> length() ) == x
|
||||
}
|
||||
"#};
|
||||
|
||||
assert_fmt(src, expected);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user