aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_syntax
diff options
context:
space:
mode:
authorbors[bot] <bors[bot]@users.noreply.github.com>2019-01-06 21:28:36 +0000
committerbors[bot] <bors[bot]@users.noreply.github.com>2019-01-06 21:28:36 +0000
commit31c1999505ccb51584dee45fb9fa1ffe16b1608e (patch)
tree64404f418c59cbbf7dcb52a834da0d44d444a8c5 /crates/ra_syntax
parent0d59422b18de8dce416d792b9e7dbe9b8d5aa30a (diff)
parent82d9a77dade454ee8d09f198fa839e7755ff7bfb (diff)
Merge #440
440: Implement type inference for boolean operators r=flodiebold a=marcusklaas Tried implementing the easiest part of https://github.com/rust-analyzer/rust-analyzer/issues/390. Hope this is somewhat close to what the intent of the issue was. Found it surprisingly easy to find my way around the repository - it's well organized! Very grateful for any pointers. Co-authored-by: Marcus Klaas de Vries <[email protected]>
Diffstat (limited to 'crates/ra_syntax')
-rw-r--r--crates/ra_syntax/src/ast.rs52
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)]
492pub 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
510impl<'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)]
492pub enum SelfParamFlavor { 544pub enum SelfParamFlavor {
493 /// self 545 /// self
494 Owned, 546 Owned,