aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_syntax/src/ast/expr_extensions.rs
diff options
context:
space:
mode:
Diffstat (limited to 'crates/ra_syntax/src/ast/expr_extensions.rs')
-rw-r--r--crates/ra_syntax/src/ast/expr_extensions.rs77
1 files changed, 39 insertions, 38 deletions
diff --git a/crates/ra_syntax/src/ast/expr_extensions.rs b/crates/ra_syntax/src/ast/expr_extensions.rs
index 9484c3b9b..17763809d 100644
--- a/crates/ra_syntax/src/ast/expr_extensions.rs
+++ b/crates/ra_syntax/src/ast/expr_extensions.rs
@@ -3,7 +3,8 @@
3use crate::{ 3use crate::{
4 SyntaxToken, SyntaxElement, SmolStr, 4 SyntaxToken, SyntaxElement, SmolStr,
5 ast::{self, AstNode, AstChildren, children, child_opt}, 5 ast::{self, AstNode, AstChildren, children, child_opt},
6 SyntaxKind::* 6 SyntaxKind::*,
7 T
7}; 8};
8 9
9#[derive(Debug, Clone, PartialEq, Eq)] 10#[derive(Debug, Clone, PartialEq, Eq)]
@@ -34,7 +35,7 @@ impl ast::IfExpr {
34 35
35impl ast::RefExpr { 36impl ast::RefExpr {
36 pub fn is_mut(&self) -> bool { 37 pub fn is_mut(&self) -> bool {
37 self.syntax().children_with_tokens().any(|n| n.kind() == MUT_KW) 38 self.syntax().children_with_tokens().any(|n| n.kind() == T![mut])
38 } 39 }
39} 40}
40 41
@@ -51,9 +52,9 @@ pub enum PrefixOp {
51impl ast::PrefixExpr { 52impl ast::PrefixExpr {
52 pub fn op_kind(&self) -> Option<PrefixOp> { 53 pub fn op_kind(&self) -> Option<PrefixOp> {
53 match self.op_token()?.kind() { 54 match self.op_token()?.kind() {
54 STAR => Some(PrefixOp::Deref), 55 T![*] => Some(PrefixOp::Deref),
55 EXCL => Some(PrefixOp::Not), 56 T![!] => Some(PrefixOp::Not),
56 MINUS => Some(PrefixOp::Neg), 57 T![-] => Some(PrefixOp::Neg),
57 _ => None, 58 _ => None,
58 } 59 }
59 } 60 }
@@ -133,37 +134,37 @@ impl ast::BinExpr {
133 fn op_details(&self) -> Option<(SyntaxToken, BinOp)> { 134 fn op_details(&self) -> Option<(SyntaxToken, BinOp)> {
134 self.syntax().children_with_tokens().filter_map(|it| it.as_token()).find_map(|c| { 135 self.syntax().children_with_tokens().filter_map(|it| it.as_token()).find_map(|c| {
135 match c.kind() { 136 match c.kind() {
136 PIPEPIPE => Some((c, BinOp::BooleanOr)), 137 T![||] => Some((c, BinOp::BooleanOr)),
137 AMPAMP => Some((c, BinOp::BooleanAnd)), 138 T![&&] => Some((c, BinOp::BooleanAnd)),
138 EQEQ => Some((c, BinOp::EqualityTest)), 139 T![==] => Some((c, BinOp::EqualityTest)),
139 NEQ => Some((c, BinOp::NegatedEqualityTest)), 140 T![!=] => Some((c, BinOp::NegatedEqualityTest)),
140 LTEQ => Some((c, BinOp::LesserEqualTest)), 141 T![<=] => Some((c, BinOp::LesserEqualTest)),
141 GTEQ => Some((c, BinOp::GreaterEqualTest)), 142 T![>=] => Some((c, BinOp::GreaterEqualTest)),
142 L_ANGLE => Some((c, BinOp::LesserTest)), 143 T![<] => Some((c, BinOp::LesserTest)),
143 R_ANGLE => Some((c, BinOp::GreaterTest)), 144 T![>] => Some((c, BinOp::GreaterTest)),
144 PLUS => Some((c, BinOp::Addition)), 145 T![+] => Some((c, BinOp::Addition)),
145 STAR => Some((c, BinOp::Multiplication)), 146 T![*] => Some((c, BinOp::Multiplication)),
146 MINUS => Some((c, BinOp::Subtraction)), 147 T![-] => Some((c, BinOp::Subtraction)),
147 SLASH => Some((c, BinOp::Division)), 148 T![/] => Some((c, BinOp::Division)),
148 PERCENT => Some((c, BinOp::Remainder)), 149 T![%] => Some((c, BinOp::Remainder)),
149 SHL => Some((c, BinOp::LeftShift)), 150 T![<<] => Some((c, BinOp::LeftShift)),
150 SHR => Some((c, BinOp::RightShift)), 151 T![>>] => Some((c, BinOp::RightShift)),
151 CARET => Some((c, BinOp::BitwiseXor)), 152 T![^] => Some((c, BinOp::BitwiseXor)),
152 PIPE => Some((c, BinOp::BitwiseOr)), 153 T![|] => Some((c, BinOp::BitwiseOr)),
153 AMP => Some((c, BinOp::BitwiseAnd)), 154 T![&] => Some((c, BinOp::BitwiseAnd)),
154 DOTDOT => Some((c, BinOp::RangeRightOpen)), 155 T![..] => Some((c, BinOp::RangeRightOpen)),
155 DOTDOTEQ => Some((c, BinOp::RangeRightClosed)), 156 T![..=] => Some((c, BinOp::RangeRightClosed)),
156 EQ => Some((c, BinOp::Assignment)), 157 T![=] => Some((c, BinOp::Assignment)),
157 PLUSEQ => Some((c, BinOp::AddAssign)), 158 T![+=] => Some((c, BinOp::AddAssign)),
158 SLASHEQ => Some((c, BinOp::DivAssign)), 159 T![/=] => Some((c, BinOp::DivAssign)),
159 STAREQ => Some((c, BinOp::MulAssign)), 160 T![*=] => Some((c, BinOp::MulAssign)),
160 PERCENTEQ => Some((c, BinOp::RemAssign)), 161 T![%=] => Some((c, BinOp::RemAssign)),
161 SHREQ => Some((c, BinOp::ShrAssign)), 162 T![>>=] => Some((c, BinOp::ShrAssign)),
162 SHLEQ => Some((c, BinOp::ShlAssign)), 163 T![<<=] => Some((c, BinOp::ShlAssign)),
163 MINUSEQ => Some((c, BinOp::SubAssign)), 164 T![-=] => Some((c, BinOp::SubAssign)),
164 PIPEEQ => Some((c, BinOp::BitOrAssign)), 165 T![|=] => Some((c, BinOp::BitOrAssign)),
165 AMPEQ => Some((c, BinOp::BitAndAssign)), 166 T![&=] => Some((c, BinOp::BitAndAssign)),
166 CARETEQ => Some((c, BinOp::BitXorAssign)), 167 T![^=] => Some((c, BinOp::BitXorAssign)),
167 _ => None, 168 _ => None,
168 } 169 }
169 }) 170 })
@@ -211,7 +212,7 @@ impl ast::ArrayExpr {
211 } 212 }
212 213
213 fn is_repeat(&self) -> bool { 214 fn is_repeat(&self) -> bool {
214 self.syntax().children_with_tokens().any(|it| it.kind() == SEMI) 215 self.syntax().children_with_tokens().any(|it| it.kind() == T![;])
215 } 216 }
216} 217}
217 218
@@ -258,7 +259,7 @@ impl ast::Literal {
258 LiteralKind::FloatNumber { suffix: suffix } 259 LiteralKind::FloatNumber { suffix: suffix }
259 } 260 }
260 STRING | RAW_STRING => LiteralKind::String, 261 STRING | RAW_STRING => LiteralKind::String,
261 TRUE_KW | FALSE_KW => LiteralKind::Bool, 262 T![true] | T![false] => LiteralKind::Bool,
262 BYTE_STRING | RAW_BYTE_STRING => LiteralKind::ByteString, 263 BYTE_STRING | RAW_BYTE_STRING => LiteralKind::ByteString,
263 CHAR => LiteralKind::Char, 264 CHAR => LiteralKind::Char,
264 BYTE => LiteralKind::Byte, 265 BYTE => LiteralKind::Byte,