aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_syntax
diff options
context:
space:
mode:
authorMarcus Klaas de Vries <[email protected]>2019-01-06 20:39:36 +0000
committerMarcus Klaas de Vries <[email protected]>2019-01-06 21:17:54 +0000
commit82d9a77dade454ee8d09f198fa839e7755ff7bfb (patch)
tree791b3c0ee6069a06896c815795ff7e86877887df /crates/ra_syntax
parent4fc233a02e8dc07619a969400c445ec47c2b1a9d (diff)
Touch up type inference for boolean operators
Also try to infer its subexpressions and set type expectations whenever possible.
Diffstat (limited to 'crates/ra_syntax')
-rw-r--r--crates/ra_syntax/src/ast.rs35
-rw-r--r--crates/ra_syntax/src/ast/generated.rs10
-rw-r--r--crates/ra_syntax/src/grammar.ron7
3 files changed, 26 insertions, 26 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)]
diff --git a/crates/ra_syntax/src/ast/generated.rs b/crates/ra_syntax/src/ast/generated.rs
index ac320606d..7df6a9c46 100644
--- a/crates/ra_syntax/src/ast/generated.rs
+++ b/crates/ra_syntax/src/ast/generated.rs
@@ -217,15 +217,7 @@ impl<R: TreeRoot<RaTypes>> BinExprNode<R> {
217} 217}
218 218
219 219
220impl<'a> BinExpr<'a> { 220impl<'a> BinExpr<'a> {}
221 pub fn lhs(self) -> Option<Expr<'a>> {
222 super::child_opt(self)
223 }
224
225 pub fn rhs(self) -> Option<Expr<'a>> {
226 super::child_opt(self)
227 }
228}
229 221
230// BindPat 222// BindPat
231#[derive(Debug, Clone, Copy,)] 223#[derive(Debug, Clone, Copy,)]
diff --git a/crates/ra_syntax/src/grammar.ron b/crates/ra_syntax/src/grammar.ron
index e59961da3..c55e9e07a 100644
--- a/crates/ra_syntax/src/grammar.ron
+++ b/crates/ra_syntax/src/grammar.ron
@@ -422,12 +422,7 @@ Grammar(
422 "RefExpr": (options: ["Expr"]), 422 "RefExpr": (options: ["Expr"]),
423 "PrefixExpr": (options: ["Expr"]), 423 "PrefixExpr": (options: ["Expr"]),
424 "RangeExpr": (), 424 "RangeExpr": (),
425 "BinExpr": ( 425 "BinExpr": (),
426 options: [
427 ["lhs", "Expr"],
428 ["rhs", "Expr"]
429 ]
430 ),
431 "String": (), 426 "String": (),
432 "Byte": (), 427 "Byte": (),
433 "ByteString": (), 428 "ByteString": (),