From 993abedd77cf23ce2281b6c8e60cab49ab4fa97e Mon Sep 17 00:00:00 2001 From: Sergey Parilin Date: Wed, 15 May 2019 15:35:47 +0300 Subject: apply T! macro where it is possible --- crates/ra_syntax/src/ast/expr_extensions.rs | 77 +++++++++++++++-------------- crates/ra_syntax/src/ast/extensions.rs | 44 ++++++++--------- 2 files changed, 61 insertions(+), 60 deletions(-) (limited to 'crates/ra_syntax/src/ast') 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 @@ use crate::{ SyntaxToken, SyntaxElement, SmolStr, ast::{self, AstNode, AstChildren, children, child_opt}, - SyntaxKind::* + SyntaxKind::*, + T }; #[derive(Debug, Clone, PartialEq, Eq)] @@ -34,7 +35,7 @@ impl ast::IfExpr { impl ast::RefExpr { pub fn is_mut(&self) -> bool { - self.syntax().children_with_tokens().any(|n| n.kind() == MUT_KW) + self.syntax().children_with_tokens().any(|n| n.kind() == T![mut]) } } @@ -51,9 +52,9 @@ pub enum PrefixOp { impl ast::PrefixExpr { pub fn op_kind(&self) -> Option { match self.op_token()?.kind() { - STAR => Some(PrefixOp::Deref), - EXCL => Some(PrefixOp::Not), - MINUS => Some(PrefixOp::Neg), + T![*] => Some(PrefixOp::Deref), + T![!] => Some(PrefixOp::Not), + T![-] => Some(PrefixOp::Neg), _ => None, } } @@ -133,37 +134,37 @@ impl ast::BinExpr { fn op_details(&self) -> Option<(SyntaxToken, BinOp)> { self.syntax().children_with_tokens().filter_map(|it| it.as_token()).find_map(|c| { match c.kind() { - PIPEPIPE => Some((c, BinOp::BooleanOr)), - AMPAMP => Some((c, BinOp::BooleanAnd)), - EQEQ => Some((c, BinOp::EqualityTest)), - NEQ => Some((c, BinOp::NegatedEqualityTest)), - LTEQ => Some((c, BinOp::LesserEqualTest)), - GTEQ => Some((c, BinOp::GreaterEqualTest)), - L_ANGLE => Some((c, BinOp::LesserTest)), - R_ANGLE => Some((c, BinOp::GreaterTest)), - PLUS => Some((c, BinOp::Addition)), - STAR => Some((c, BinOp::Multiplication)), - MINUS => Some((c, BinOp::Subtraction)), - SLASH => Some((c, BinOp::Division)), - PERCENT => Some((c, BinOp::Remainder)), - SHL => Some((c, BinOp::LeftShift)), - SHR => Some((c, BinOp::RightShift)), - CARET => Some((c, BinOp::BitwiseXor)), - PIPE => Some((c, BinOp::BitwiseOr)), - AMP => Some((c, BinOp::BitwiseAnd)), - DOTDOT => Some((c, BinOp::RangeRightOpen)), - DOTDOTEQ => Some((c, BinOp::RangeRightClosed)), - EQ => Some((c, BinOp::Assignment)), - PLUSEQ => Some((c, BinOp::AddAssign)), - SLASHEQ => Some((c, BinOp::DivAssign)), - STAREQ => Some((c, BinOp::MulAssign)), - PERCENTEQ => Some((c, BinOp::RemAssign)), - SHREQ => Some((c, BinOp::ShrAssign)), - SHLEQ => Some((c, BinOp::ShlAssign)), - MINUSEQ => Some((c, BinOp::SubAssign)), - PIPEEQ => Some((c, BinOp::BitOrAssign)), - AMPEQ => Some((c, BinOp::BitAndAssign)), - CARETEQ => Some((c, BinOp::BitXorAssign)), + 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, } }) @@ -211,7 +212,7 @@ impl ast::ArrayExpr { } fn is_repeat(&self) -> bool { - self.syntax().children_with_tokens().any(|it| it.kind() == SEMI) + self.syntax().children_with_tokens().any(|it| it.kind() == T![;]) } } @@ -258,7 +259,7 @@ impl ast::Literal { LiteralKind::FloatNumber { suffix: suffix } } STRING | RAW_STRING => LiteralKind::String, - TRUE_KW | FALSE_KW => LiteralKind::Bool, + T![true] | T![false] => LiteralKind::Bool, BYTE_STRING | RAW_BYTE_STRING => LiteralKind::ByteString, CHAR => LiteralKind::Char, BYTE => LiteralKind::Byte, diff --git a/crates/ra_syntax/src/ast/extensions.rs b/crates/ra_syntax/src/ast/extensions.rs index f3466c585..f030e0df8 100644 --- a/crates/ra_syntax/src/ast/extensions.rs +++ b/crates/ra_syntax/src/ast/extensions.rs @@ -3,7 +3,7 @@ use itertools::Itertools; -use crate::{SmolStr, SyntaxToken, ast::{self, AstNode, children, child_opt}, SyntaxKind::*, SyntaxElement}; +use crate::{SmolStr, SyntaxToken, ast::{self, AstNode, children, child_opt}, SyntaxKind::*, SyntaxElement, T}; use ra_parser::SyntaxKind; impl ast::Name { @@ -32,7 +32,7 @@ impl ast::Attr { Some(prev) => prev, }; - prev.kind() == EXCL + prev.kind() == T![!] } pub fn as_atom(&self) -> Option { @@ -102,9 +102,9 @@ impl ast::PathSegment { PathSegmentKind::Name(name_ref) } else { match self.syntax().first_child_or_token()?.kind() { - SELF_KW => PathSegmentKind::SelfKw, - SUPER_KW => PathSegmentKind::SuperKw, - CRATE_KW => PathSegmentKind::CrateKw, + T![self] => PathSegmentKind::SelfKw, + T![super] => PathSegmentKind::SuperKw, + T![crate] => PathSegmentKind::CrateKw, _ => return None, } }; @@ -113,7 +113,7 @@ impl ast::PathSegment { pub fn has_colon_colon(&self) -> bool { match self.syntax.first_child_or_token().map(|s| s.kind()) { - Some(COLONCOLON) => true, + Some(T![::]) => true, _ => false, } } @@ -129,14 +129,14 @@ impl ast::Module { pub fn has_semi(&self) -> bool { match self.syntax().last_child_or_token() { None => false, - Some(node) => node.kind() == SEMI, + Some(node) => node.kind() == T![;], } } } impl ast::UseTree { pub fn has_star(&self) -> bool { - self.syntax().children_with_tokens().any(|it| it.kind() == STAR) + self.syntax().children_with_tokens().any(|it| it.kind() == T![*]) } } @@ -172,7 +172,7 @@ impl ast::ImplBlock { } pub fn is_negative(&self) -> bool { - self.syntax().children_with_tokens().any(|t| t.kind() == EXCL) + self.syntax().children_with_tokens().any(|t| t.kind() == T![!]) } } @@ -219,7 +219,7 @@ impl ast::FnDef { self.syntax() .last_child_or_token() .and_then(|it| it.as_token()) - .filter(|it| it.kind() == SEMI) + .filter(|it| it.kind() == T![;]) } } @@ -227,7 +227,7 @@ impl ast::LetStmt { pub fn has_semi(&self) -> bool { match self.syntax().last_child_or_token() { None => false, - Some(node) => node.kind() == SEMI, + Some(node) => node.kind() == T![;], } } } @@ -236,7 +236,7 @@ impl ast::ExprStmt { pub fn has_semi(&self) -> bool { match self.syntax().last_child_or_token() { None => false, - Some(node) => node.kind() == SEMI, + Some(node) => node.kind() == T![;], } } } @@ -270,29 +270,29 @@ impl ast::FieldExpr { impl ast::RefPat { pub fn is_mut(&self) -> bool { - self.syntax().children_with_tokens().any(|n| n.kind() == MUT_KW) + self.syntax().children_with_tokens().any(|n| n.kind() == T![mut]) } } impl ast::BindPat { pub fn is_mutable(&self) -> bool { - self.syntax().children_with_tokens().any(|n| n.kind() == MUT_KW) + self.syntax().children_with_tokens().any(|n| n.kind() == T![mut]) } pub fn is_ref(&self) -> bool { - self.syntax().children_with_tokens().any(|n| n.kind() == REF_KW) + self.syntax().children_with_tokens().any(|n| n.kind() == T![ref]) } } impl ast::PointerType { pub fn is_mut(&self) -> bool { - self.syntax().children_with_tokens().any(|n| n.kind() == MUT_KW) + self.syntax().children_with_tokens().any(|n| n.kind() == T![mut]) } } impl ast::ReferenceType { pub fn is_mut(&self) -> bool { - self.syntax().children_with_tokens().any(|n| n.kind() == MUT_KW) + self.syntax().children_with_tokens().any(|n| n.kind() == T![mut]) } } @@ -311,19 +311,19 @@ impl ast::SelfParam { self.syntax() .children_with_tokens() .filter_map(|it| it.as_token()) - .find(|it| it.kind() == SELF_KW) + .find(|it| it.kind() == T![self]) .expect("invalid tree: self param must have self") } pub fn kind(&self) -> SelfParamKind { - let borrowed = self.syntax().children_with_tokens().any(|n| n.kind() == AMP); + let borrowed = self.syntax().children_with_tokens().any(|n| n.kind() == T![&]); if borrowed { // check for a `mut` coming after the & -- `mut &self` != `&mut self` if self .syntax() .children_with_tokens() - .skip_while(|n| n.kind() != AMP) - .any(|n| n.kind() == MUT_KW) + .skip_while(|n| n.kind() != T![&]) + .any(|n| n.kind() == T![mut]) { SelfParamKind::MutRef } else { @@ -355,6 +355,6 @@ impl ast::WherePred { impl ast::TraitDef { pub fn is_auto(&self) -> bool { - self.syntax().children_with_tokens().any(|t| t.kind() == AUTO_KW) + self.syntax().children_with_tokens().any(|t| t.kind() == T![auto]) } } -- cgit v1.2.3