diff options
Diffstat (limited to 'crates/ra_syntax')
-rw-r--r-- | crates/ra_syntax/src/ast.rs | 87 | ||||
-rw-r--r-- | crates/ra_syntax/src/ptr.rs | 6 |
2 files changed, 54 insertions, 39 deletions
diff --git a/crates/ra_syntax/src/ast.rs b/crates/ra_syntax/src/ast.rs index d8c2cb063..a6fac07c4 100644 --- a/crates/ra_syntax/src/ast.rs +++ b/crates/ra_syntax/src/ast.rs | |||
@@ -521,7 +521,7 @@ pub enum PrefixOp { | |||
521 | } | 521 | } |
522 | 522 | ||
523 | impl PrefixExpr { | 523 | impl PrefixExpr { |
524 | pub fn op(&self) -> Option<PrefixOp> { | 524 | pub fn op_kind(&self) -> Option<PrefixOp> { |
525 | match self.syntax().first_child()?.kind() { | 525 | match self.syntax().first_child()?.kind() { |
526 | STAR => Some(PrefixOp::Deref), | 526 | STAR => Some(PrefixOp::Deref), |
527 | EXCL => Some(PrefixOp::Not), | 527 | EXCL => Some(PrefixOp::Not), |
@@ -529,6 +529,10 @@ impl PrefixExpr { | |||
529 | _ => None, | 529 | _ => None, |
530 | } | 530 | } |
531 | } | 531 | } |
532 | |||
533 | pub fn op(&self) -> Option<&SyntaxNode> { | ||
534 | self.syntax().first_child() | ||
535 | } | ||
532 | } | 536 | } |
533 | 537 | ||
534 | #[derive(Copy, Clone, Debug, PartialEq, Eq, Hash)] | 538 | #[derive(Copy, Clone, Debug, PartialEq, Eq, Hash)] |
@@ -598,44 +602,49 @@ pub enum BinOp { | |||
598 | } | 602 | } |
599 | 603 | ||
600 | impl BinExpr { | 604 | impl BinExpr { |
601 | pub fn op(&self) -> Option<BinOp> { | 605 | fn op_details(&self) -> Option<(&SyntaxNode, BinOp)> { |
602 | self.syntax() | 606 | self.syntax().children().find_map(|c| match c.kind() { |
603 | .children() | 607 | PIPEPIPE => Some((c, BinOp::BooleanOr)), |
604 | .filter_map(|c| match c.kind() { | 608 | AMPAMP => Some((c, BinOp::BooleanAnd)), |
605 | PIPEPIPE => Some(BinOp::BooleanOr), | 609 | EQEQ => Some((c, BinOp::EqualityTest)), |
606 | AMPAMP => Some(BinOp::BooleanAnd), | 610 | NEQ => Some((c, BinOp::NegatedEqualityTest)), |
607 | EQEQ => Some(BinOp::EqualityTest), | 611 | LTEQ => Some((c, BinOp::LesserEqualTest)), |
608 | NEQ => Some(BinOp::NegatedEqualityTest), | 612 | GTEQ => Some((c, BinOp::GreaterEqualTest)), |
609 | LTEQ => Some(BinOp::LesserEqualTest), | 613 | L_ANGLE => Some((c, BinOp::LesserTest)), |
610 | GTEQ => Some(BinOp::GreaterEqualTest), | 614 | R_ANGLE => Some((c, BinOp::GreaterTest)), |
611 | L_ANGLE => Some(BinOp::LesserTest), | 615 | PLUS => Some((c, BinOp::Addition)), |
612 | R_ANGLE => Some(BinOp::GreaterTest), | 616 | STAR => Some((c, BinOp::Multiplication)), |
613 | PLUS => Some(BinOp::Addition), | 617 | MINUS => Some((c, BinOp::Subtraction)), |
614 | STAR => Some(BinOp::Multiplication), | 618 | SLASH => Some((c, BinOp::Division)), |
615 | MINUS => Some(BinOp::Subtraction), | 619 | PERCENT => Some((c, BinOp::Remainder)), |
616 | SLASH => Some(BinOp::Division), | 620 | SHL => Some((c, BinOp::LeftShift)), |
617 | PERCENT => Some(BinOp::Remainder), | 621 | SHR => Some((c, BinOp::RightShift)), |
618 | SHL => Some(BinOp::LeftShift), | 622 | CARET => Some((c, BinOp::BitwiseXor)), |
619 | SHR => Some(BinOp::RightShift), | 623 | PIPE => Some((c, BinOp::BitwiseOr)), |
620 | CARET => Some(BinOp::BitwiseXor), | 624 | AMP => Some((c, BinOp::BitwiseAnd)), |
621 | PIPE => Some(BinOp::BitwiseOr), | 625 | DOTDOT => Some((c, BinOp::RangeRightOpen)), |
622 | AMP => Some(BinOp::BitwiseAnd), | 626 | DOTDOTEQ => Some((c, BinOp::RangeRightClosed)), |
623 | DOTDOT => Some(BinOp::RangeRightOpen), | 627 | EQ => Some((c, BinOp::Assignment)), |
624 | DOTDOTEQ => Some(BinOp::RangeRightClosed), | 628 | PLUSEQ => Some((c, BinOp::AddAssign)), |
625 | EQ => Some(BinOp::Assignment), | 629 | SLASHEQ => Some((c, BinOp::DivAssign)), |
626 | PLUSEQ => Some(BinOp::AddAssign), | 630 | STAREQ => Some((c, BinOp::MulAssign)), |
627 | SLASHEQ => Some(BinOp::DivAssign), | 631 | PERCENTEQ => Some((c, BinOp::RemAssign)), |
628 | STAREQ => Some(BinOp::MulAssign), | 632 | SHREQ => Some((c, BinOp::ShrAssign)), |
629 | PERCENTEQ => Some(BinOp::RemAssign), | 633 | SHLEQ => Some((c, BinOp::ShlAssign)), |
630 | SHREQ => Some(BinOp::ShrAssign), | 634 | MINUSEQ => Some((c, BinOp::SubAssign)), |
631 | SHLEQ => Some(BinOp::ShlAssign), | 635 | PIPEEQ => Some((c, BinOp::BitOrAssign)), |
632 | MINUSEQ => Some(BinOp::SubAssign), | 636 | AMPEQ => Some((c, BinOp::BitAndAssign)), |
633 | PIPEEQ => Some(BinOp::BitOrAssign), | 637 | CARETEQ => Some((c, BinOp::BitXorAssign)), |
634 | AMPEQ => Some(BinOp::BitAndAssign), | 638 | _ => None, |
635 | CARETEQ => Some(BinOp::BitXorAssign), | 639 | }) |
636 | _ => None, | 640 | } |
637 | }) | 641 | |
638 | .next() | 642 | pub fn op_kind(&self) -> Option<BinOp> { |
643 | self.op_details().map(|t| t.1) | ||
644 | } | ||
645 | |||
646 | pub fn op(&self) -> Option<&SyntaxNode> { | ||
647 | self.op_details().map(|t| t.0) | ||
639 | } | 648 | } |
640 | 649 | ||
641 | pub fn lhs(&self) -> Option<&Expr> { | 650 | pub fn lhs(&self) -> Option<&Expr> { |
diff --git a/crates/ra_syntax/src/ptr.rs b/crates/ra_syntax/src/ptr.rs index aae590cb6..d8de1c4c1 100644 --- a/crates/ra_syntax/src/ptr.rs +++ b/crates/ra_syntax/src/ptr.rs | |||
@@ -64,6 +64,12 @@ impl<N: AstNode> AstPtr<N> { | |||
64 | } | 64 | } |
65 | } | 65 | } |
66 | 66 | ||
67 | impl<N: AstNode> From<AstPtr<N>> for SyntaxNodePtr { | ||
68 | fn from(ptr: AstPtr<N>) -> SyntaxNodePtr { | ||
69 | ptr.raw | ||
70 | } | ||
71 | } | ||
72 | |||
67 | #[test] | 73 | #[test] |
68 | fn test_local_syntax_ptr() { | 74 | fn test_local_syntax_ptr() { |
69 | use crate::{ast, AstNode}; | 75 | use crate::{ast, AstNode}; |