diff options
Diffstat (limited to 'crates/ra_syntax')
-rw-r--r-- | crates/ra_syntax/src/ast.rs | 52 |
1 files changed, 52 insertions, 0 deletions
diff --git a/crates/ra_syntax/src/ast.rs b/crates/ra_syntax/src/ast.rs index c10169d90..9df8ec663 100644 --- a/crates/ra_syntax/src/ast.rs +++ b/crates/ra_syntax/src/ast.rs | |||
@@ -489,6 +489,58 @@ impl<'a> PrefixExpr<'a> { | |||
489 | } | 489 | } |
490 | 490 | ||
491 | #[derive(Copy, Clone, Debug, PartialEq, Eq, Hash)] | 491 | #[derive(Copy, Clone, Debug, PartialEq, Eq, Hash)] |
492 | pub enum BinOp { | ||
493 | /// The `||` operator for boolean OR | ||
494 | BooleanOr, | ||
495 | /// The `&&` operator for boolean AND | ||
496 | BooleanAnd, | ||
497 | /// The `==` operator for equality testing | ||
498 | EqualityTest, | ||
499 | /// The `<=` operator for lesser-equal testing | ||
500 | LesserEqualTest, | ||
501 | /// The `>=` operator for greater-equal testing | ||
502 | GreaterEqualTest, | ||
503 | /// The `<` operator for comparison | ||
504 | LesserTest, | ||
505 | /// The `>` operator for comparison | ||
506 | GreaterTest, | ||
507 | // TODO: lots of others | ||
508 | } | ||
509 | |||
510 | impl<'a> BinExpr<'a> { | ||
511 | pub fn op(&self) -> Option<BinOp> { | ||
512 | self.syntax() | ||
513 | .children() | ||
514 | .filter_map(|c| match c.kind() { | ||
515 | PIPEPIPE => Some(BinOp::BooleanOr), | ||
516 | AMPAMP => Some(BinOp::BooleanAnd), | ||
517 | EQEQ => Some(BinOp::EqualityTest), | ||
518 | LTEQ => Some(BinOp::LesserEqualTest), | ||
519 | GTEQ => Some(BinOp::GreaterEqualTest), | ||
520 | L_ANGLE => Some(BinOp::LesserTest), | ||
521 | R_ANGLE => Some(BinOp::GreaterTest), | ||
522 | _ => None, | ||
523 | }) | ||
524 | .next() | ||
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 | } | ||
541 | } | ||
542 | |||
543 | #[derive(Copy, Clone, Debug, PartialEq, Eq, Hash)] | ||
492 | pub enum SelfParamFlavor { | 544 | pub enum SelfParamFlavor { |
493 | /// self | 545 | /// self |
494 | Owned, | 546 | Owned, |