aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_syntax/src/ast.rs
diff options
context:
space:
mode:
authorMarcus Klaas de Vries <[email protected]>2019-01-05 20:28:30 +0000
committerMarcus Klaas de Vries <[email protected]>2019-01-05 20:28:30 +0000
commit4fc233a02e8dc07619a969400c445ec47c2b1a9d (patch)
treedae33907a38b7c4ed9d1a63ff38803e99f1ae6df /crates/ra_syntax/src/ast.rs
parent3e42a158787955ff9f2e81be43479dbe8f2b1bb6 (diff)
Implement type inference for boolean operators
Diffstat (limited to 'crates/ra_syntax/src/ast.rs')
-rw-r--r--crates/ra_syntax/src/ast.rs39
1 files changed, 39 insertions, 0 deletions
diff --git a/crates/ra_syntax/src/ast.rs b/crates/ra_syntax/src/ast.rs
index c10169d90..1bce6fa40 100644
--- a/crates/ra_syntax/src/ast.rs
+++ b/crates/ra_syntax/src/ast.rs
@@ -489,6 +489,45 @@ 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| {
515 match c.kind() {
516 PIPEPIPE => Some(BinOp::BooleanOr),
517 AMPAMP => Some(BinOp::BooleanAnd),
518 EQEQ => Some(BinOp::EqualityTest),
519 LTEQ => Some(BinOp::LesserEqualTest),
520 GTEQ => Some(BinOp::GreaterEqualTest),
521 L_ANGLE => Some(BinOp::LesserTest),
522 R_ANGLE => Some(BinOp::GreaterTest),
523 _ => None,
524 }
525 })
526 .next()
527 }
528}
529
530#[derive(Copy, Clone, Debug, PartialEq, Eq, Hash)]
492pub enum SelfParamFlavor { 531pub enum SelfParamFlavor {
493 /// self 532 /// self
494 Owned, 533 Owned,