From fd4c083e429d055190fa830bd2216915fe634b98 Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Sat, 17 Aug 2019 17:14:22 +0300 Subject: simplify --- crates/ra_syntax/src/ast/expr_extensions.rs | 71 +++++++++++++++-------------- 1 file changed, 36 insertions(+), 35 deletions(-) (limited to 'crates/ra_syntax/src') diff --git a/crates/ra_syntax/src/ast/expr_extensions.rs b/crates/ra_syntax/src/ast/expr_extensions.rs index 8284f1b25..d2c19b98d 100644 --- a/crates/ra_syntax/src/ast/expr_extensions.rs +++ b/crates/ra_syntax/src/ast/expr_extensions.rs @@ -132,41 +132,42 @@ pub enum BinOp { impl ast::BinExpr { fn op_details(&self) -> Option<(SyntaxToken, BinOp)> { - self.syntax().children_with_tokens().filter_map(|it| it.into_token()).find_map(|c| match c - .kind() - { - T![||] => Some((c, BinOp::BooleanOr)), - T![&&] => Some((c, BinOp::BooleanAnd)), - T![==] => Some((c, BinOp::EqualityTest)), - T![!=] => Some((c, BinOp::NegatedEqualityTest)), - T![<=] => Some((c, BinOp::LesserEqualTest)), - T![>=] => Some((c, BinOp::GreaterEqualTest)), - T![<] => Some((c, BinOp::LesserTest)), - T![>] => Some((c, BinOp::GreaterTest)), - T![+] => Some((c, BinOp::Addition)), - T![*] => Some((c, BinOp::Multiplication)), - T![-] => Some((c, BinOp::Subtraction)), - T![/] => Some((c, BinOp::Division)), - T![%] => Some((c, BinOp::Remainder)), - T![<<] => Some((c, BinOp::LeftShift)), - T![>>] => Some((c, BinOp::RightShift)), - T![^] => Some((c, BinOp::BitwiseXor)), - T![|] => Some((c, BinOp::BitwiseOr)), - T![&] => Some((c, BinOp::BitwiseAnd)), - T![..] => Some((c, BinOp::RangeRightOpen)), - T![..=] => Some((c, BinOp::RangeRightClosed)), - T![=] => Some((c, BinOp::Assignment)), - T![+=] => Some((c, BinOp::AddAssign)), - T![/=] => Some((c, BinOp::DivAssign)), - T![*=] => Some((c, BinOp::MulAssign)), - T![%=] => Some((c, BinOp::RemAssign)), - T![>>=] => Some((c, BinOp::ShrAssign)), - T![<<=] => Some((c, BinOp::ShlAssign)), - T![-=] => Some((c, BinOp::SubAssign)), - T![|=] => Some((c, BinOp::BitOrAssign)), - T![&=] => Some((c, BinOp::BitAndAssign)), - T![^=] => Some((c, BinOp::BitXorAssign)), - _ => None, + self.syntax().children_with_tokens().filter_map(|it| it.into_token()).find_map(|c| { + let bin_op = match c.kind() { + T![||] => BinOp::BooleanOr, + T![&&] => BinOp::BooleanAnd, + T![==] => BinOp::EqualityTest, + T![!=] => BinOp::NegatedEqualityTest, + T![<=] => BinOp::LesserEqualTest, + T![>=] => BinOp::GreaterEqualTest, + T![<] => BinOp::LesserTest, + T![>] => BinOp::GreaterTest, + T![+] => BinOp::Addition, + T![*] => BinOp::Multiplication, + T![-] => BinOp::Subtraction, + T![/] => BinOp::Division, + T![%] => BinOp::Remainder, + T![<<] => BinOp::LeftShift, + T![>>] => BinOp::RightShift, + T![^] => BinOp::BitwiseXor, + T![|] => BinOp::BitwiseOr, + T![&] => BinOp::BitwiseAnd, + T![..] => BinOp::RangeRightOpen, + T![..=] => BinOp::RangeRightClosed, + T![=] => BinOp::Assignment, + T![+=] => BinOp::AddAssign, + T![/=] => BinOp::DivAssign, + T![*=] => BinOp::MulAssign, + T![%=] => BinOp::RemAssign, + T![>>=] => BinOp::ShrAssign, + T![<<=] => BinOp::ShlAssign, + T![-=] => BinOp::SubAssign, + T![|=] => BinOp::BitOrAssign, + T![&=] => BinOp::BitAndAssign, + T![^=] => BinOp::BitXorAssign, + _ => return None, + }; + Some((c, bin_op)) }) } -- cgit v1.2.3 From 8919aa8065c31d55050a6bfe10b574fc71bcec09 Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Sat, 17 Aug 2019 17:17:01 +0300 Subject: implement accessors for IndexExpr --- crates/ra_syntax/src/ast/expr_extensions.rs | 9 +++++++++ 1 file changed, 9 insertions(+) (limited to 'crates/ra_syntax/src') diff --git a/crates/ra_syntax/src/ast/expr_extensions.rs b/crates/ra_syntax/src/ast/expr_extensions.rs index d2c19b98d..20e390209 100644 --- a/crates/ra_syntax/src/ast/expr_extensions.rs +++ b/crates/ra_syntax/src/ast/expr_extensions.rs @@ -195,6 +195,15 @@ impl ast::BinExpr { } } +impl ast::IndexExpr { + pub fn base(&self) -> Option { + children(self).nth(0) + } + pub fn index(&self) -> Option { + children(self).nth(1) + } +} + pub enum ArrayExprKind { Repeat { initializer: Option, repeat: Option }, ElementList(AstChildren), -- cgit v1.2.3 From 7e5a186c1fe585aac95019addc963bf74cb112ae Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Sat, 17 Aug 2019 17:42:41 +0300 Subject: Introduce separate hir::BinaryOp Unlike ast::BinOp, it has significantly more structure to it, so it's easier to, say, handle all assignment-like operations in the same way. --- crates/ra_syntax/src/ast/expr_extensions.rs | 6 ------ 1 file changed, 6 deletions(-) (limited to 'crates/ra_syntax/src') diff --git a/crates/ra_syntax/src/ast/expr_extensions.rs b/crates/ra_syntax/src/ast/expr_extensions.rs index 20e390209..cf5b6f251 100644 --- a/crates/ra_syntax/src/ast/expr_extensions.rs +++ b/crates/ra_syntax/src/ast/expr_extensions.rs @@ -102,10 +102,6 @@ pub enum BinOp { BitwiseOr, /// The `&` operator for bitwise AND BitwiseAnd, - /// The `..` operator for right-open ranges - RangeRightOpen, - /// The `..=` operator for right-closed ranges - RangeRightClosed, /// The `=` operator for assignment Assignment, /// The `+=` operator for assignment after addition @@ -152,8 +148,6 @@ impl ast::BinExpr { T![^] => BinOp::BitwiseXor, T![|] => BinOp::BitwiseOr, T![&] => BinOp::BitwiseAnd, - T![..] => BinOp::RangeRightOpen, - T![..=] => BinOp::RangeRightClosed, T![=] => BinOp::Assignment, T![+=] => BinOp::AddAssign, T![/=] => BinOp::DivAssign, -- cgit v1.2.3