diff options
Diffstat (limited to 'crates/ra_syntax/src/ast.rs')
-rw-r--r-- | crates/ra_syntax/src/ast.rs | 35 |
1 files changed, 24 insertions, 11 deletions
diff --git a/crates/ra_syntax/src/ast.rs b/crates/ra_syntax/src/ast.rs index 1bce6fa40..9df8ec663 100644 --- a/crates/ra_syntax/src/ast.rs +++ b/crates/ra_syntax/src/ast.rs | |||
@@ -511,20 +511,33 @@ impl<'a> BinExpr<'a> { | |||
511 | pub fn op(&self) -> Option<BinOp> { | 511 | pub fn op(&self) -> Option<BinOp> { |
512 | self.syntax() | 512 | self.syntax() |
513 | .children() | 513 | .children() |
514 | .filter_map(|c| { | 514 | .filter_map(|c| match c.kind() { |
515 | match c.kind() { | 515 | PIPEPIPE => Some(BinOp::BooleanOr), |
516 | PIPEPIPE => Some(BinOp::BooleanOr), | 516 | AMPAMP => Some(BinOp::BooleanAnd), |
517 | AMPAMP => Some(BinOp::BooleanAnd), | 517 | EQEQ => Some(BinOp::EqualityTest), |
518 | EQEQ => Some(BinOp::EqualityTest), | 518 | LTEQ => Some(BinOp::LesserEqualTest), |
519 | LTEQ => Some(BinOp::LesserEqualTest), | 519 | GTEQ => Some(BinOp::GreaterEqualTest), |
520 | GTEQ => Some(BinOp::GreaterEqualTest), | 520 | L_ANGLE => Some(BinOp::LesserTest), |
521 | L_ANGLE => Some(BinOp::LesserTest), | 521 | R_ANGLE => Some(BinOp::GreaterTest), |
522 | R_ANGLE => Some(BinOp::GreaterTest), | 522 | _ => None, |
523 | _ => None, | ||
524 | } | ||
525 | }) | 523 | }) |
526 | .next() | 524 | .next() |
527 | } | 525 | } |
526 | |||
527 | pub fn lhs(self) -> Option<Expr<'a>> { | ||
528 | children(self).nth(0) | ||
529 | } | ||
530 | |||
531 | pub fn rhs(self) -> Option<Expr<'a>> { | ||
532 | children(self).nth(1) | ||
533 | } | ||
534 | |||
535 | pub fn sub_exprs(self) -> (Option<Expr<'a>>, Option<Expr<'a>>) { | ||
536 | let mut children = children(self); | ||
537 | let first = children.next(); | ||
538 | let second = children.next(); | ||
539 | (first, second) | ||
540 | } | ||
528 | } | 541 | } |
529 | 542 | ||
530 | #[derive(Copy, Clone, Debug, PartialEq, Eq, Hash)] | 543 | #[derive(Copy, Clone, Debug, PartialEq, Eq, Hash)] |