diff --git a/crates/ra_assists/src/handlers/add_explicit_type.rs b/crates/ra_assists/src/handlers/add_explicit_type.rs index e7dcfb44e2..d86d804b2e 100644 --- a/crates/ra_assists/src/handlers/add_explicit_type.rs +++ b/crates/ra_assists/src/handlers/add_explicit_type.rs @@ -1,6 +1,6 @@ use hir::HirDisplay; use ra_syntax::{ - ast::{self, AstNode, AstToken, LetStmt, NameOwner, TypeAscriptionOwner}, + ast::{self, AstNode, LetStmt, NameOwner, TypeAscriptionOwner}, TextRange, }; @@ -35,7 +35,7 @@ pub(crate) fn add_explicit_type(ctx: AssistCtx) -> Option { let name = pat.name()?; let name_range = name.syntax().text_range(); let stmt_range = stmt.syntax().text_range(); - let eq_range = stmt.eq_token()?.syntax().text_range(); + let eq_range = stmt.eq_token()?.text_range(); // Assist should only be applicable if cursor is between 'let' and '=' let let_range = TextRange::from_to(stmt_range.start(), eq_range.start()); let cursor_in_range = ctx.frange.range.is_subrange(&let_range); diff --git a/crates/ra_assists/src/handlers/add_impl.rs b/crates/ra_assists/src/handlers/add_impl.rs index 26dfed2376..6622eadb2d 100644 --- a/crates/ra_assists/src/handlers/add_impl.rs +++ b/crates/ra_assists/src/handlers/add_impl.rs @@ -1,5 +1,5 @@ use ra_syntax::{ - ast::{self, AstNode, AstToken, NameOwner, TypeParamsOwner}, + ast::{self, AstNode, NameOwner, TypeParamsOwner}, TextUnit, }; use stdx::{format_to, SepBy}; diff --git a/crates/ra_assists/src/handlers/add_new.rs b/crates/ra_assists/src/handlers/add_new.rs index 30360af942..240b19fa37 100644 --- a/crates/ra_assists/src/handlers/add_new.rs +++ b/crates/ra_assists/src/handlers/add_new.rs @@ -1,8 +1,7 @@ use hir::Adt; use ra_syntax::{ ast::{ - self, AstNode, AstToken, NameOwner, StructKind, TypeAscriptionOwner, TypeParamsOwner, - VisibilityOwner, + self, AstNode, NameOwner, StructKind, TypeAscriptionOwner, TypeParamsOwner, VisibilityOwner, }, TextUnit, T, }; diff --git a/crates/ra_assists/src/handlers/introduce_variable.rs b/crates/ra_assists/src/handlers/introduce_variable.rs index ab6bdf6bbd..8d0f7e922a 100644 --- a/crates/ra_assists/src/handlers/introduce_variable.rs +++ b/crates/ra_assists/src/handlers/introduce_variable.rs @@ -61,7 +61,7 @@ pub(crate) fn introduce_variable(ctx: AssistCtx) -> Option { }; if is_full_stmt { tested_by!(test_introduce_var_expr_stmt); - if full_stmt.unwrap().semi_token().is_none() { + if full_stmt.unwrap().semicolon_token().is_none() { buf.push_str(";"); } edit.replace(expr.syntax().text_range(), buf); diff --git a/crates/ra_assists/src/handlers/merge_imports.rs b/crates/ra_assists/src/handlers/merge_imports.rs index 936d50ab49..0958f52f1f 100644 --- a/crates/ra_assists/src/handlers/merge_imports.rs +++ b/crates/ra_assists/src/handlers/merge_imports.rs @@ -3,7 +3,7 @@ use std::iter::successors; use ra_syntax::{ algo::{neighbor, SyntaxRewriter}, ast::{self, edit::AstNodeEdit, make}, - AstNode, AstToken, Direction, InsertPosition, SyntaxElement, T, + AstNode, Direction, InsertPosition, SyntaxElement, T, }; use crate::{Assist, AssistCtx, AssistId}; @@ -82,7 +82,7 @@ fn try_merge_trees(old: &ast::UseTree, new: &ast::UseTree) -> Option Option { ast::EnumDef(it) => it.variant_list()?.syntax().clone().into(), ast::StructDef(it) => { it.syntax().children_with_tokens() - .find(|it| it.kind() == RECORD_FIELD_DEF_LIST || it.kind() == SEMI)? + .find(|it| it.kind() == RECORD_FIELD_DEF_LIST || it.kind() == T![;])? }, _ => return None } diff --git a/crates/ra_hir_def/src/nameres/raw.rs b/crates/ra_hir_def/src/nameres/raw.rs index e72ba52cfb..afd538e4ac 100644 --- a/crates/ra_hir_def/src/nameres/raw.rs +++ b/crates/ra_hir_def/src/nameres/raw.rs @@ -287,7 +287,7 @@ impl RawItemsCollector { let visibility = RawVisibility::from_ast_with_hygiene(module.visibility(), &self.hygiene); let ast_id = self.source_ast_id_map.ast_id(&module); - if module.semi_token().is_some() { + if module.semicolon_token().is_some() { let item = self.raw_items.modules.alloc(ModuleData::Declaration { name, visibility, ast_id }); self.push_item(current_module, attrs, RawItemKind::Module(item)); diff --git a/crates/ra_ide/src/completion/complete_trait_impl.rs b/crates/ra_ide/src/completion/complete_trait_impl.rs index ded1ff3bcc..fab02945c5 100644 --- a/crates/ra_ide/src/completion/complete_trait_impl.rs +++ b/crates/ra_ide/src/completion/complete_trait_impl.rs @@ -35,7 +35,7 @@ use hir::{self, Docs, HasSource}; use ra_assists::utils::get_missing_impl_items; use ra_syntax::{ ast::{self, edit, ImplDef}, - AstNode, SyntaxKind, SyntaxNode, TextRange, + AstNode, SyntaxKind, SyntaxNode, TextRange, T, }; use ra_text_edit::TextEdit; @@ -204,7 +204,7 @@ fn make_const_compl_syntax(const_: &ast::ConstDef) -> String { let end = const_ .syntax() .children_with_tokens() - .find(|s| s.kind() == SyntaxKind::SEMI || s.kind() == SyntaxKind::EQ) + .find(|s| s.kind() == T![;] || s.kind() == T![=]) .map_or(const_end, |f| f.text_range().start()); let len = end - start; diff --git a/crates/ra_ide/src/syntax_tree.rs b/crates/ra_ide/src/syntax_tree.rs index f58e436d1d..5842ae2e86 100644 --- a/crates/ra_ide/src/syntax_tree.rs +++ b/crates/ra_ide/src/syntax_tree.rs @@ -165,7 +165,7 @@ SOURCE_FILE@[0; 60) PATH_SEGMENT@[16; 22) NAME_REF@[16; 22) IDENT@[16; 22) "assert" - EXCL@[22; 23) "!" + BANG@[22; 23) "!" TOKEN_TREE@[23; 57) L_PAREN@[23; 24) "(" STRING@[24; 52) "\"\n fn foo() {\n ..." @@ -173,7 +173,7 @@ SOURCE_FILE@[0; 60) WHITESPACE@[53; 54) " " STRING@[54; 56) "\"\"" R_PAREN@[56; 57) ")" - SEMI@[57; 58) ";" + SEMICOLON@[57; 58) ";" WHITESPACE@[58; 59) "\n" R_CURLY@[59; 60) "}" "# @@ -226,7 +226,7 @@ EXPR_STMT@[16; 58) PATH_SEGMENT@[16; 22) NAME_REF@[16; 22) IDENT@[16; 22) "assert" - EXCL@[22; 23) "!" + BANG@[22; 23) "!" TOKEN_TREE@[23; 57) L_PAREN@[23; 24) "(" STRING@[24; 52) "\"\n fn foo() {\n ..." @@ -234,7 +234,7 @@ EXPR_STMT@[16; 58) WHITESPACE@[53; 54) " " STRING@[54; 56) "\"\"" R_PAREN@[56; 57) ")" - SEMI@[57; 58) ";" + SEMICOLON@[57; 58) ";" "# .trim() ); diff --git a/crates/ra_ide/src/typing.rs b/crates/ra_ide/src/typing.rs index 71d2bcb045..f55cd3bf53 100644 --- a/crates/ra_ide/src/typing.rs +++ b/crates/ra_ide/src/typing.rs @@ -63,7 +63,7 @@ fn on_char_typed_inner( fn on_eq_typed(file: &SourceFile, offset: TextUnit) -> Option { assert_eq!(file.syntax().text().char_at(offset), Some('=')); let let_stmt: ast::LetStmt = find_node_at_offset(file.syntax(), offset)?; - if let_stmt.semi_token().is_some() { + if let_stmt.semicolon_token().is_some() { return None; } if let Some(expr) = let_stmt.initializer() { diff --git a/crates/ra_mbe/src/tests.rs b/crates/ra_mbe/src/tests.rs index 1ef6f6eedd..5d1274d21f 100644 --- a/crates/ra_mbe/src/tests.rs +++ b/crates/ra_mbe/src/tests.rs @@ -252,7 +252,7 @@ fn test_expr_order() { STAR@[11; 12) "*" LITERAL@[12; 13) INT_NUMBER@[12; 13) "2" - SEMI@[13; 14) ";" + SEMICOLON@[13; 14) ";" R_CURLY@[14; 15) "}""#, ); } @@ -605,7 +605,7 @@ fn test_tt_to_stmts() { EQ@[4; 5) "=" LITERAL@[5; 6) INT_NUMBER@[5; 6) "0" - SEMI@[6; 7) ";" + SEMICOLON@[6; 7) ";" EXPR_STMT@[7; 14) BIN_EXPR@[7; 13) PATH_EXPR@[7; 8) @@ -620,7 +620,7 @@ fn test_tt_to_stmts() { PLUS@[11; 12) "+" LITERAL@[12; 13) INT_NUMBER@[12; 13) "1" - SEMI@[13; 14) ";" + SEMICOLON@[13; 14) ";" EXPR_STMT@[14; 15) PATH_EXPR@[14; 15) PATH@[14; 15) @@ -953,7 +953,7 @@ fn test_tt_composite2() { PATH_SEGMENT@[0; 3) NAME_REF@[0; 3) IDENT@[0; 3) "abs" - EXCL@[3; 4) "!" + BANG@[3; 4) "!" TOKEN_TREE@[4; 10) L_PAREN@[4; 5) "(" EQ@[5; 6) "=" @@ -1073,14 +1073,14 @@ fn test_vec() { PATH_SEGMENT@[9; 12) NAME_REF@[9; 12) IDENT@[9; 12) "Vec" - COLONCOLON@[12; 14) "::" + COLON2@[12; 14) "::" PATH_SEGMENT@[14; 17) NAME_REF@[14; 17) IDENT@[14; 17) "new" ARG_LIST@[17; 19) L_PAREN@[17; 18) "(" R_PAREN@[18; 19) ")" - SEMI@[19; 20) ";" + SEMICOLON@[19; 20) ";" EXPR_STMT@[20; 33) METHOD_CALL_EXPR@[20; 32) PATH_EXPR@[20; 21) @@ -1096,7 +1096,7 @@ fn test_vec() { LITERAL@[27; 31) INT_NUMBER@[27; 31) "1u32" R_PAREN@[31; 32) ")" - SEMI@[32; 33) ";" + SEMICOLON@[32; 33) ";" EXPR_STMT@[33; 43) METHOD_CALL_EXPR@[33; 42) PATH_EXPR@[33; 34) @@ -1112,7 +1112,7 @@ fn test_vec() { LITERAL@[40; 41) INT_NUMBER@[40; 41) "2" R_PAREN@[41; 42) ")" - SEMI@[42; 43) ";" + SEMICOLON@[42; 43) ";" PATH_EXPR@[43; 44) PATH@[43; 44) PATH_SEGMENT@[43; 44) @@ -1760,7 +1760,7 @@ fn test_no_space_after_semi_colon() { MOD_KW@[21; 24) "mod" NAME@[24; 25) IDENT@[24; 25) "m" - SEMI@[25; 26) ";" + SEMICOLON@[25; 26) ";" MODULE@[26; 52) ATTR@[26; 47) POUND@[26; 27) "#" @@ -1779,7 +1779,7 @@ fn test_no_space_after_semi_colon() { MOD_KW@[47; 50) "mod" NAME@[50; 51) IDENT@[50; 51) "f" - SEMI@[51; 52) ";""###, + SEMICOLON@[51; 52) ";""###, ); } diff --git a/crates/ra_parser/src/grammar/expressions.rs b/crates/ra_parser/src/grammar/expressions.rs index c486c02113..a1bd530638 100644 --- a/crates/ra_parser/src/grammar/expressions.rs +++ b/crates/ra_parser/src/grammar/expressions.rs @@ -339,7 +339,8 @@ fn expr_bp(p: &mut Parser, mut r: Restrictions, bp: u8) -> (Option Option<(CompletedMarker, BlockLike)> { let m; diff --git a/crates/ra_parser/src/grammar/types.rs b/crates/ra_parser/src/grammar/types.rs index 386969d2d7..fe1a039cbf 100644 --- a/crates/ra_parser/src/grammar/types.rs +++ b/crates/ra_parser/src/grammar/types.rs @@ -3,8 +3,19 @@ use super::*; pub(super) const TYPE_FIRST: TokenSet = paths::PATH_FIRST.union(token_set![ - L_PAREN, EXCL, STAR, L_BRACK, AMP, UNDERSCORE, FN_KW, UNSAFE_KW, EXTERN_KW, FOR_KW, IMPL_KW, - DYN_KW, L_ANGLE, + T!['('], + T!['['], + T![<], + T![!], + T![*], + T![&], + T![_], + T![fn], + T![unsafe], + T![extern], + T![for], + T![impl], + T![dyn], ]); const TYPE_RECOVERY_SET: TokenSet = token_set![R_PAREN, COMMA, L_DOLLAR]; diff --git a/crates/ra_parser/src/syntax_kind/generated.rs b/crates/ra_parser/src/syntax_kind/generated.rs index 004f4e5643..524e7d784e 100644 --- a/crates/ra_parser/src/syntax_kind/generated.rs +++ b/crates/ra_parser/src/syntax_kind/generated.rs @@ -9,7 +9,7 @@ pub enum SyntaxKind { TOMBSTONE, #[doc(hidden)] EOF, - SEMI, + SEMICOLON, COMMA, L_PAREN, R_PAREN, @@ -33,15 +33,15 @@ pub enum SyntaxKind { PERCENT, UNDERSCORE, DOT, - DOTDOT, - DOTDOTDOT, - DOTDOTEQ, + DOT2, + DOT3, + DOT2EQ, COLON, - COLONCOLON, + COLON2, EQ, - EQEQ, + EQ2, FAT_ARROW, - EXCL, + BANG, NEQ, MINUS, THIN_ARROW, @@ -55,8 +55,8 @@ pub enum SyntaxKind { SLASHEQ, STAREQ, PERCENTEQ, - AMPAMP, - PIPEPIPE, + AMP2, + PIPE2, SHL, SHR, SHLEQ, @@ -265,12 +265,12 @@ impl SyntaxKind { } pub fn is_punct(self) -> bool { match self { - SEMI | COMMA | L_PAREN | R_PAREN | L_CURLY | R_CURLY | L_BRACK | R_BRACK | L_ANGLE - | R_ANGLE | AT | POUND | TILDE | QUESTION | DOLLAR | AMP | PIPE | PLUS | STAR - | SLASH | CARET | PERCENT | UNDERSCORE | DOT | DOTDOT | DOTDOTDOT | DOTDOTEQ - | COLON | COLONCOLON | EQ | EQEQ | FAT_ARROW | EXCL | NEQ | MINUS | THIN_ARROW - | LTEQ | GTEQ | PLUSEQ | MINUSEQ | PIPEEQ | AMPEQ | CARETEQ | SLASHEQ | STAREQ - | PERCENTEQ | AMPAMP | PIPEPIPE | SHL | SHR | SHLEQ | SHREQ => true, + SEMICOLON | COMMA | L_PAREN | R_PAREN | L_CURLY | R_CURLY | L_BRACK | R_BRACK + | L_ANGLE | R_ANGLE | AT | POUND | TILDE | QUESTION | DOLLAR | AMP | PIPE | PLUS + | STAR | SLASH | CARET | PERCENT | UNDERSCORE | DOT | DOT2 | DOT3 | DOT2EQ | COLON + | COLON2 | EQ | EQ2 | FAT_ARROW | BANG | NEQ | MINUS | THIN_ARROW | LTEQ | GTEQ + | PLUSEQ | MINUSEQ | PIPEEQ | AMPEQ | CARETEQ | SLASHEQ | STAREQ | PERCENTEQ | AMP2 + | PIPE2 | SHL | SHR | SHLEQ | SHREQ => true, _ => false, } } @@ -329,7 +329,7 @@ impl SyntaxKind { } pub fn from_char(c: char) -> Option { let tok = match c { - ';' => SEMI, + ';' => SEMICOLON, ',' => COMMA, '(' => L_PAREN, ')' => R_PAREN, @@ -355,7 +355,7 @@ impl SyntaxKind { '.' => DOT, ':' => COLON, '=' => EQ, - '!' => EXCL, + '!' => BANG, '-' => MINUS, _ => return None, }; @@ -363,296 +363,4 @@ impl SyntaxKind { } } #[macro_export] -macro_rules! T { - ( ; ) => { - $crate::SyntaxKind::SEMI - }; - ( , ) => { - $crate::SyntaxKind::COMMA - }; - ( '(' ) => { - $crate::SyntaxKind::L_PAREN - }; - ( ')' ) => { - $crate::SyntaxKind::R_PAREN - }; - ( '{' ) => { - $crate::SyntaxKind::L_CURLY - }; - ( '}' ) => { - $crate::SyntaxKind::R_CURLY - }; - ( '[' ) => { - $crate::SyntaxKind::L_BRACK - }; - ( ']' ) => { - $crate::SyntaxKind::R_BRACK - }; - ( < ) => { - $crate::SyntaxKind::L_ANGLE - }; - ( > ) => { - $crate::SyntaxKind::R_ANGLE - }; - ( @ ) => { - $crate::SyntaxKind::AT - }; - ( # ) => { - $crate::SyntaxKind::POUND - }; - ( ~ ) => { - $crate::SyntaxKind::TILDE - }; - ( ? ) => { - $crate::SyntaxKind::QUESTION - }; - ( $ ) => { - $crate::SyntaxKind::DOLLAR - }; - ( & ) => { - $crate::SyntaxKind::AMP - }; - ( | ) => { - $crate::SyntaxKind::PIPE - }; - ( + ) => { - $crate::SyntaxKind::PLUS - }; - ( * ) => { - $crate::SyntaxKind::STAR - }; - ( / ) => { - $crate::SyntaxKind::SLASH - }; - ( ^ ) => { - $crate::SyntaxKind::CARET - }; - ( % ) => { - $crate::SyntaxKind::PERCENT - }; - ( _ ) => { - $crate::SyntaxKind::UNDERSCORE - }; - ( . ) => { - $crate::SyntaxKind::DOT - }; - ( .. ) => { - $crate::SyntaxKind::DOTDOT - }; - ( ... ) => { - $crate::SyntaxKind::DOTDOTDOT - }; - ( ..= ) => { - $crate::SyntaxKind::DOTDOTEQ - }; - ( : ) => { - $crate::SyntaxKind::COLON - }; - ( :: ) => { - $crate::SyntaxKind::COLONCOLON - }; - ( = ) => { - $crate::SyntaxKind::EQ - }; - ( == ) => { - $crate::SyntaxKind::EQEQ - }; - ( => ) => { - $crate::SyntaxKind::FAT_ARROW - }; - ( ! ) => { - $crate::SyntaxKind::EXCL - }; - ( != ) => { - $crate::SyntaxKind::NEQ - }; - ( - ) => { - $crate::SyntaxKind::MINUS - }; - ( -> ) => { - $crate::SyntaxKind::THIN_ARROW - }; - ( <= ) => { - $crate::SyntaxKind::LTEQ - }; - ( >= ) => { - $crate::SyntaxKind::GTEQ - }; - ( += ) => { - $crate::SyntaxKind::PLUSEQ - }; - ( -= ) => { - $crate::SyntaxKind::MINUSEQ - }; - ( |= ) => { - $crate::SyntaxKind::PIPEEQ - }; - ( &= ) => { - $crate::SyntaxKind::AMPEQ - }; - ( ^= ) => { - $crate::SyntaxKind::CARETEQ - }; - ( /= ) => { - $crate::SyntaxKind::SLASHEQ - }; - ( *= ) => { - $crate::SyntaxKind::STAREQ - }; - ( %= ) => { - $crate::SyntaxKind::PERCENTEQ - }; - ( && ) => { - $crate::SyntaxKind::AMPAMP - }; - ( || ) => { - $crate::SyntaxKind::PIPEPIPE - }; - ( << ) => { - $crate::SyntaxKind::SHL - }; - ( >> ) => { - $crate::SyntaxKind::SHR - }; - ( <<= ) => { - $crate::SyntaxKind::SHLEQ - }; - ( >>= ) => { - $crate::SyntaxKind::SHREQ - }; - ( as ) => { - $crate::SyntaxKind::AS_KW - }; - ( async ) => { - $crate::SyntaxKind::ASYNC_KW - }; - ( await ) => { - $crate::SyntaxKind::AWAIT_KW - }; - ( box ) => { - $crate::SyntaxKind::BOX_KW - }; - ( break ) => { - $crate::SyntaxKind::BREAK_KW - }; - ( const ) => { - $crate::SyntaxKind::CONST_KW - }; - ( continue ) => { - $crate::SyntaxKind::CONTINUE_KW - }; - ( crate ) => { - $crate::SyntaxKind::CRATE_KW - }; - ( dyn ) => { - $crate::SyntaxKind::DYN_KW - }; - ( else ) => { - $crate::SyntaxKind::ELSE_KW - }; - ( enum ) => { - $crate::SyntaxKind::ENUM_KW - }; - ( extern ) => { - $crate::SyntaxKind::EXTERN_KW - }; - ( false ) => { - $crate::SyntaxKind::FALSE_KW - }; - ( fn ) => { - $crate::SyntaxKind::FN_KW - }; - ( for ) => { - $crate::SyntaxKind::FOR_KW - }; - ( if ) => { - $crate::SyntaxKind::IF_KW - }; - ( impl ) => { - $crate::SyntaxKind::IMPL_KW - }; - ( in ) => { - $crate::SyntaxKind::IN_KW - }; - ( let ) => { - $crate::SyntaxKind::LET_KW - }; - ( loop ) => { - $crate::SyntaxKind::LOOP_KW - }; - ( macro ) => { - $crate::SyntaxKind::MACRO_KW - }; - ( match ) => { - $crate::SyntaxKind::MATCH_KW - }; - ( mod ) => { - $crate::SyntaxKind::MOD_KW - }; - ( move ) => { - $crate::SyntaxKind::MOVE_KW - }; - ( mut ) => { - $crate::SyntaxKind::MUT_KW - }; - ( pub ) => { - $crate::SyntaxKind::PUB_KW - }; - ( ref ) => { - $crate::SyntaxKind::REF_KW - }; - ( return ) => { - $crate::SyntaxKind::RETURN_KW - }; - ( self ) => { - $crate::SyntaxKind::SELF_KW - }; - ( static ) => { - $crate::SyntaxKind::STATIC_KW - }; - ( struct ) => { - $crate::SyntaxKind::STRUCT_KW - }; - ( super ) => { - $crate::SyntaxKind::SUPER_KW - }; - ( trait ) => { - $crate::SyntaxKind::TRAIT_KW - }; - ( true ) => { - $crate::SyntaxKind::TRUE_KW - }; - ( try ) => { - $crate::SyntaxKind::TRY_KW - }; - ( type ) => { - $crate::SyntaxKind::TYPE_KW - }; - ( unsafe ) => { - $crate::SyntaxKind::UNSAFE_KW - }; - ( use ) => { - $crate::SyntaxKind::USE_KW - }; - ( where ) => { - $crate::SyntaxKind::WHERE_KW - }; - ( while ) => { - $crate::SyntaxKind::WHILE_KW - }; - ( auto ) => { - $crate::SyntaxKind::AUTO_KW - }; - ( default ) => { - $crate::SyntaxKind::DEFAULT_KW - }; - ( existential ) => { - $crate::SyntaxKind::EXISTENTIAL_KW - }; - ( union ) => { - $crate::SyntaxKind::UNION_KW - }; - ( raw ) => { - $crate::SyntaxKind::RAW_KW - }; -} +macro_rules ! T { [ ; ] => { $ crate :: SyntaxKind :: SEMICOLON } ; [ , ] => { $ crate :: SyntaxKind :: COMMA } ; [ '(' ] => { $ crate :: SyntaxKind :: L_PAREN } ; [ ')' ] => { $ crate :: SyntaxKind :: R_PAREN } ; [ '{' ] => { $ crate :: SyntaxKind :: L_CURLY } ; [ '}' ] => { $ crate :: SyntaxKind :: R_CURLY } ; [ '[' ] => { $ crate :: SyntaxKind :: L_BRACK } ; [ ']' ] => { $ crate :: SyntaxKind :: R_BRACK } ; [ < ] => { $ crate :: SyntaxKind :: L_ANGLE } ; [ > ] => { $ crate :: SyntaxKind :: R_ANGLE } ; [ @ ] => { $ crate :: SyntaxKind :: AT } ; [ # ] => { $ crate :: SyntaxKind :: POUND } ; [ ~ ] => { $ crate :: SyntaxKind :: TILDE } ; [ ? ] => { $ crate :: SyntaxKind :: QUESTION } ; [ $ ] => { $ crate :: SyntaxKind :: DOLLAR } ; [ & ] => { $ crate :: SyntaxKind :: AMP } ; [ | ] => { $ crate :: SyntaxKind :: PIPE } ; [ + ] => { $ crate :: SyntaxKind :: PLUS } ; [ * ] => { $ crate :: SyntaxKind :: STAR } ; [ / ] => { $ crate :: SyntaxKind :: SLASH } ; [ ^ ] => { $ crate :: SyntaxKind :: CARET } ; [ % ] => { $ crate :: SyntaxKind :: PERCENT } ; [ _ ] => { $ crate :: SyntaxKind :: UNDERSCORE } ; [ . ] => { $ crate :: SyntaxKind :: DOT } ; [ .. ] => { $ crate :: SyntaxKind :: DOT2 } ; [ ... ] => { $ crate :: SyntaxKind :: DOT3 } ; [ ..= ] => { $ crate :: SyntaxKind :: DOT2EQ } ; [ : ] => { $ crate :: SyntaxKind :: COLON } ; [ :: ] => { $ crate :: SyntaxKind :: COLON2 } ; [ = ] => { $ crate :: SyntaxKind :: EQ } ; [ == ] => { $ crate :: SyntaxKind :: EQ2 } ; [ => ] => { $ crate :: SyntaxKind :: FAT_ARROW } ; [ ! ] => { $ crate :: SyntaxKind :: BANG } ; [ != ] => { $ crate :: SyntaxKind :: NEQ } ; [ - ] => { $ crate :: SyntaxKind :: MINUS } ; [ -> ] => { $ crate :: SyntaxKind :: THIN_ARROW } ; [ <= ] => { $ crate :: SyntaxKind :: LTEQ } ; [ >= ] => { $ crate :: SyntaxKind :: GTEQ } ; [ += ] => { $ crate :: SyntaxKind :: PLUSEQ } ; [ -= ] => { $ crate :: SyntaxKind :: MINUSEQ } ; [ |= ] => { $ crate :: SyntaxKind :: PIPEEQ } ; [ &= ] => { $ crate :: SyntaxKind :: AMPEQ } ; [ ^= ] => { $ crate :: SyntaxKind :: CARETEQ } ; [ /= ] => { $ crate :: SyntaxKind :: SLASHEQ } ; [ *= ] => { $ crate :: SyntaxKind :: STAREQ } ; [ %= ] => { $ crate :: SyntaxKind :: PERCENTEQ } ; [ && ] => { $ crate :: SyntaxKind :: AMP2 } ; [ || ] => { $ crate :: SyntaxKind :: PIPE2 } ; [ << ] => { $ crate :: SyntaxKind :: SHL } ; [ >> ] => { $ crate :: SyntaxKind :: SHR } ; [ <<= ] => { $ crate :: SyntaxKind :: SHLEQ } ; [ >>= ] => { $ crate :: SyntaxKind :: SHREQ } ; [ as ] => { $ crate :: SyntaxKind :: AS_KW } ; [ async ] => { $ crate :: SyntaxKind :: ASYNC_KW } ; [ await ] => { $ crate :: SyntaxKind :: AWAIT_KW } ; [ box ] => { $ crate :: SyntaxKind :: BOX_KW } ; [ break ] => { $ crate :: SyntaxKind :: BREAK_KW } ; [ const ] => { $ crate :: SyntaxKind :: CONST_KW } ; [ continue ] => { $ crate :: SyntaxKind :: CONTINUE_KW } ; [ crate ] => { $ crate :: SyntaxKind :: CRATE_KW } ; [ dyn ] => { $ crate :: SyntaxKind :: DYN_KW } ; [ else ] => { $ crate :: SyntaxKind :: ELSE_KW } ; [ enum ] => { $ crate :: SyntaxKind :: ENUM_KW } ; [ extern ] => { $ crate :: SyntaxKind :: EXTERN_KW } ; [ false ] => { $ crate :: SyntaxKind :: FALSE_KW } ; [ fn ] => { $ crate :: SyntaxKind :: FN_KW } ; [ for ] => { $ crate :: SyntaxKind :: FOR_KW } ; [ if ] => { $ crate :: SyntaxKind :: IF_KW } ; [ impl ] => { $ crate :: SyntaxKind :: IMPL_KW } ; [ in ] => { $ crate :: SyntaxKind :: IN_KW } ; [ let ] => { $ crate :: SyntaxKind :: LET_KW } ; [ loop ] => { $ crate :: SyntaxKind :: LOOP_KW } ; [ macro ] => { $ crate :: SyntaxKind :: MACRO_KW } ; [ match ] => { $ crate :: SyntaxKind :: MATCH_KW } ; [ mod ] => { $ crate :: SyntaxKind :: MOD_KW } ; [ move ] => { $ crate :: SyntaxKind :: MOVE_KW } ; [ mut ] => { $ crate :: SyntaxKind :: MUT_KW } ; [ pub ] => { $ crate :: SyntaxKind :: PUB_KW } ; [ ref ] => { $ crate :: SyntaxKind :: REF_KW } ; [ return ] => { $ crate :: SyntaxKind :: RETURN_KW } ; [ self ] => { $ crate :: SyntaxKind :: SELF_KW } ; [ static ] => { $ crate :: SyntaxKind :: STATIC_KW } ; [ struct ] => { $ crate :: SyntaxKind :: STRUCT_KW } ; [ super ] => { $ crate :: SyntaxKind :: SUPER_KW } ; [ trait ] => { $ crate :: SyntaxKind :: TRAIT_KW } ; [ true ] => { $ crate :: SyntaxKind :: TRUE_KW } ; [ try ] => { $ crate :: SyntaxKind :: TRY_KW } ; [ type ] => { $ crate :: SyntaxKind :: TYPE_KW } ; [ unsafe ] => { $ crate :: SyntaxKind :: UNSAFE_KW } ; [ use ] => { $ crate :: SyntaxKind :: USE_KW } ; [ where ] => { $ crate :: SyntaxKind :: WHERE_KW } ; [ while ] => { $ crate :: SyntaxKind :: WHILE_KW } ; [ auto ] => { $ crate :: SyntaxKind :: AUTO_KW } ; [ default ] => { $ crate :: SyntaxKind :: DEFAULT_KW } ; [ existential ] => { $ crate :: SyntaxKind :: EXISTENTIAL_KW } ; [ union ] => { $ crate :: SyntaxKind :: UNION_KW } ; [ raw ] => { $ crate :: SyntaxKind :: RAW_KW } ; [ lifetime ] => { $ crate :: SyntaxKind :: LIFETIME } ; [ ident ] => { $ crate :: SyntaxKind :: IDENT } ; } diff --git a/crates/ra_syntax/src/ast.rs b/crates/ra_syntax/src/ast.rs index 1ee60e74ce..99c6b72197 100644 --- a/crates/ra_syntax/src/ast.rs +++ b/crates/ra_syntax/src/ast.rs @@ -80,7 +80,7 @@ impl Iterator for AstChildren { } mod support { - use super::{AstChildren, AstNode, AstToken, SyntaxKind, SyntaxNode, SyntaxToken}; + use super::{AstChildren, AstNode, SyntaxKind, SyntaxNode, SyntaxToken}; pub(super) fn child(parent: &SyntaxNode) -> Option { parent.children().find_map(N::cast) @@ -90,11 +90,7 @@ mod support { AstChildren::new(parent) } - pub(super) fn token(parent: &SyntaxNode) -> Option { - parent.children_with_tokens().filter_map(|it| it.into_token()).find_map(T::cast) - } - - pub(super) fn token2(parent: &SyntaxNode, kind: SyntaxKind) -> Option { + pub(super) fn token(parent: &SyntaxNode, kind: SyntaxKind) -> Option { parent.children_with_tokens().filter_map(|it| it.into_token()).find(|it| it.kind() == kind) } } diff --git a/crates/ra_syntax/src/ast/edit.rs b/crates/ra_syntax/src/ast/edit.rs index 3d428fab3a..9e5411ee58 100644 --- a/crates/ra_syntax/src/ast/edit.rs +++ b/crates/ra_syntax/src/ast/edit.rs @@ -32,9 +32,9 @@ impl ast::FnDef { let mut to_insert: ArrayVec<[SyntaxElement; 2]> = ArrayVec::new(); let old_body_or_semi: SyntaxElement = if let Some(old_body) = self.body() { old_body.syntax().clone().into() - } else if let Some(semi) = self.semi_token() { + } else if let Some(semi) = self.semicolon_token() { to_insert.push(make::tokens::single_space().into()); - semi.syntax.clone().into() + semi.into() } else { to_insert.push(make::tokens::single_space().into()); to_insert.push(body.syntax().clone().into()); @@ -98,7 +98,7 @@ impl ast::ItemList { None => match self.l_curly_token() { Some(it) => ( " ".to_string() + &leading_indent(self.syntax()).unwrap_or_default(), - InsertPosition::After(it.syntax().clone().into()), + InsertPosition::After(it.into()), ), None => return self.clone(), }, @@ -142,7 +142,7 @@ impl ast::RecordFieldList { macro_rules! after_l_curly { () => {{ let anchor = match self.l_curly_token() { - Some(it) => it.syntax().clone().into(), + Some(it) => it.into(), None => return self.clone(), }; InsertPosition::After(anchor) @@ -189,15 +189,15 @@ impl ast::RecordFieldList { impl ast::TypeParam { #[must_use] pub fn remove_bounds(&self) -> ast::TypeParam { - let colon = match self.colon() { + let colon = match self.colon_token() { Some(it) => it, None => return self.clone(), }; let end = match self.type_bound_list() { Some(it) => it.syntax().clone().into(), - None => colon.syntax().clone().into(), + None => colon.clone().into(), }; - self.replace_children(colon.syntax().clone().into()..=end, iter::empty()) + self.replace_children(colon.into()..=end, iter::empty()) } } diff --git a/crates/ra_syntax/src/ast/extensions.rs b/crates/ra_syntax/src/ast/extensions.rs index 11ec70bc09..1aacb06764 100644 --- a/crates/ra_syntax/src/ast/extensions.rs +++ b/crates/ra_syntax/src/ast/extensions.rs @@ -5,7 +5,7 @@ use itertools::Itertools; use ra_parser::SyntaxKind; use crate::{ - ast::{self, support, AstNode, AstToken, AttrInput, NameOwner, SyntaxNode}, + ast::{self, support, AstNode, AttrInput, NameOwner, SyntaxNode}, SmolStr, SyntaxElement, SyntaxToken, T, }; @@ -21,11 +21,7 @@ impl ast::NameRef { } pub fn as_tuple_field(&self) -> Option { - if let Some(ast::NameRefToken::IntNumber(token)) = self.name_ref_token_token() { - token.text().as_str().parse().ok() - } else { - None - } + self.text().parse().ok() } } @@ -81,7 +77,7 @@ impl ast::Attr { first_token.and_then(|token| token.next_token()).as_ref().map(SyntaxToken::kind); match (first_token_kind, second_token_kind) { - (Some(SyntaxKind::POUND), Some(SyntaxKind::EXCL)) => AttrKind::Inner, + (Some(SyntaxKind::POUND), Some(T![!])) => AttrKind::Inner, _ => AttrKind::Outer, } } @@ -315,7 +311,7 @@ pub enum TypeBoundKind { /// for<'a> ... ForType(ast::ForType), /// 'a - Lifetime(ast::Lifetime), + Lifetime(SyntaxToken), } impl ast::TypeBound { @@ -331,23 +327,23 @@ impl ast::TypeBound { } } - pub fn const_question_token(&self) -> Option { + pub fn const_question_token(&self) -> Option { self.syntax() .children_with_tokens() .filter_map(|it| it.into_token()) .take_while(|it| it.kind() != T![const]) - .find_map(ast::Question::cast) + .find(|it| it.kind() == T![?]) } - pub fn question_token(&self) -> Option { + pub fn question_token(&self) -> Option { if self.const_token().is_some() { self.syntax() .children_with_tokens() .filter_map(|it| it.into_token()) .skip_while(|it| it.kind() != T![const]) - .find_map(ast::Question::cast) + .find(|it| it.kind() == T![?]) } else { - support::token(&self.syntax) + support::token(&self.syntax, T![?]) } } } @@ -388,12 +384,12 @@ impl ast::MacroCall { } impl ast::LifetimeParam { - pub fn lifetime_bounds(&self) -> impl Iterator { + pub fn lifetime_bounds(&self) -> impl Iterator { self.syntax() .children_with_tokens() .filter_map(|it| it.into_token()) .skip_while(|x| x.kind() != T![:]) - .filter_map(ast::Lifetime::cast) + .filter(|it| it.kind() == T![lifetime]) } } @@ -401,7 +397,7 @@ impl ast::RangePat { pub fn start(&self) -> Option { self.syntax() .children_with_tokens() - .take_while(|it| !ast::RangeSeparator::can_cast(it.kind())) + .take_while(|it| !(it.kind() == T![..] || it.kind() == T![..=])) .filter_map(|it| it.into_node()) .find_map(ast::Pat::cast) } @@ -409,18 +405,24 @@ impl ast::RangePat { pub fn end(&self) -> Option { self.syntax() .children_with_tokens() - .skip_while(|it| !ast::RangeSeparator::can_cast(it.kind())) + .skip_while(|it| !(it.kind() == T![..] || it.kind() == T![..=])) .filter_map(|it| it.into_node()) .find_map(ast::Pat::cast) } } impl ast::TokenTree { - pub fn left_delimiter(&self) -> Option { - self.syntax().first_child_or_token()?.into_token().and_then(ast::LeftDelimiter::cast) + pub fn left_delimiter_token(&self) -> Option { + self.syntax().first_child_or_token()?.into_token().filter(|it| match it.kind() { + T!['{'] | T!['('] | T!['['] => true, + _ => false, + }) } - pub fn right_delimiter(&self) -> Option { - self.syntax().last_child_or_token()?.into_token().and_then(ast::RightDelimiter::cast) + pub fn right_delimiter_token(&self) -> Option { + self.syntax().last_child_or_token()?.into_token().filter(|it| match it.kind() { + T!['{'] | T!['('] | T!['['] => true, + _ => false, + }) } } diff --git a/crates/ra_syntax/src/ast/generated/nodes.rs b/crates/ra_syntax/src/ast/generated/nodes.rs index 20f6630467..0df7cfe526 100644 --- a/crates/ra_syntax/src/ast/generated/nodes.rs +++ b/crates/ra_syntax/src/ast/generated/nodes.rs @@ -1,11 +1,11 @@ //! Generated file, do not edit by hand, see `xtask/src/codegen` -use super::tokens::*; use crate::{ ast::{self, support, AstChildren, AstNode}, SyntaxKind::{self, *}, - SyntaxNode, SyntaxToken, + SyntaxNode, SyntaxToken, T, }; + #[derive(Debug, Clone, PartialEq, Eq, Hash)] pub struct SourceFile { pub(crate) syntax: SyntaxNode, @@ -26,6 +26,7 @@ impl ast::AttrsOwner for SourceFile {} impl SourceFile { pub fn modules(&self) -> AstChildren { support::children(&self.syntax) } } + #[derive(Debug, Clone, PartialEq, Eq, Hash)] pub struct FnDef { pub(crate) syntax: SyntaxNode, @@ -48,16 +49,17 @@ impl ast::DocCommentsOwner for FnDef {} impl ast::AttrsOwner for FnDef {} impl FnDef { pub fn abi(&self) -> Option { support::child(&self.syntax) } - pub fn const_token(&self) -> Option { support::token2(&self.syntax, CONST_KW) } - pub fn default_token(&self) -> Option { support::token2(&self.syntax, DEFAULT_KW) } - pub fn async_token(&self) -> Option { support::token2(&self.syntax, ASYNC_KW) } - pub fn unsafe_token(&self) -> Option { support::token2(&self.syntax, UNSAFE_KW) } - pub fn fn_token(&self) -> Option { support::token2(&self.syntax, FN_KW) } + pub fn const_token(&self) -> Option { support::token(&self.syntax, T![const]) } + pub fn default_token(&self) -> Option { support::token(&self.syntax, T![default]) } + pub fn async_token(&self) -> Option { support::token(&self.syntax, T![async]) } + pub fn unsafe_token(&self) -> Option { support::token(&self.syntax, T![unsafe]) } + pub fn fn_token(&self) -> Option { support::token(&self.syntax, T![fn]) } pub fn param_list(&self) -> Option { support::child(&self.syntax) } pub fn ret_type(&self) -> Option { support::child(&self.syntax) } pub fn body(&self) -> Option { support::child(&self.syntax) } - pub fn semi_token(&self) -> Option { support::token(&self.syntax) } + pub fn semicolon_token(&self) -> Option { support::token(&self.syntax, T![;]) } } + #[derive(Debug, Clone, PartialEq, Eq, Hash)] pub struct RetType { pub(crate) syntax: SyntaxNode, @@ -74,9 +76,10 @@ impl AstNode for RetType { fn syntax(&self) -> &SyntaxNode { &self.syntax } } impl RetType { - pub fn thin_arrow_token(&self) -> Option { support::token(&self.syntax) } + pub fn thin_arrow_token(&self) -> Option { support::token(&self.syntax, T![->]) } pub fn type_ref(&self) -> Option { support::child(&self.syntax) } } + #[derive(Debug, Clone, PartialEq, Eq, Hash)] pub struct StructDef { pub(crate) syntax: SyntaxNode, @@ -98,10 +101,11 @@ impl ast::TypeParamsOwner for StructDef {} impl ast::AttrsOwner for StructDef {} impl ast::DocCommentsOwner for StructDef {} impl StructDef { - pub fn struct_token(&self) -> Option { support::token2(&self.syntax, STRUCT_KW) } + pub fn struct_token(&self) -> Option { support::token(&self.syntax, T![struct]) } pub fn field_def_list(&self) -> Option { support::child(&self.syntax) } - pub fn semi_token(&self) -> Option { support::token(&self.syntax) } + pub fn semicolon_token(&self) -> Option { support::token(&self.syntax, T![;]) } } + #[derive(Debug, Clone, PartialEq, Eq, Hash)] pub struct UnionDef { pub(crate) syntax: SyntaxNode, @@ -123,11 +127,12 @@ impl ast::TypeParamsOwner for UnionDef {} impl ast::AttrsOwner for UnionDef {} impl ast::DocCommentsOwner for UnionDef {} impl UnionDef { - pub fn union_token(&self) -> Option { support::token2(&self.syntax, UNION_KW) } + pub fn union_token(&self) -> Option { support::token(&self.syntax, T![union]) } pub fn record_field_def_list(&self) -> Option { support::child(&self.syntax) } } + #[derive(Debug, Clone, PartialEq, Eq, Hash)] pub struct RecordFieldDefList { pub(crate) syntax: SyntaxNode, @@ -144,10 +149,11 @@ impl AstNode for RecordFieldDefList { fn syntax(&self) -> &SyntaxNode { &self.syntax } } impl RecordFieldDefList { - pub fn l_curly_token(&self) -> Option { support::token(&self.syntax) } + pub fn l_curly_token(&self) -> Option { support::token(&self.syntax, T!['{']) } pub fn fields(&self) -> AstChildren { support::children(&self.syntax) } - pub fn r_curly_token(&self) -> Option { support::token(&self.syntax) } + pub fn r_curly_token(&self) -> Option { support::token(&self.syntax, T!['}']) } } + #[derive(Debug, Clone, PartialEq, Eq, Hash)] pub struct RecordFieldDef { pub(crate) syntax: SyntaxNode, @@ -169,6 +175,7 @@ impl ast::AttrsOwner for RecordFieldDef {} impl ast::DocCommentsOwner for RecordFieldDef {} impl ast::TypeAscriptionOwner for RecordFieldDef {} impl RecordFieldDef {} + #[derive(Debug, Clone, PartialEq, Eq, Hash)] pub struct TupleFieldDefList { pub(crate) syntax: SyntaxNode, @@ -185,10 +192,11 @@ impl AstNode for TupleFieldDefList { fn syntax(&self) -> &SyntaxNode { &self.syntax } } impl TupleFieldDefList { - pub fn l_paren_token(&self) -> Option { support::token(&self.syntax) } + pub fn l_paren_token(&self) -> Option { support::token(&self.syntax, T!['(']) } pub fn fields(&self) -> AstChildren { support::children(&self.syntax) } - pub fn r_paren_token(&self) -> Option { support::token(&self.syntax) } + pub fn r_paren_token(&self) -> Option { support::token(&self.syntax, T![')']) } } + #[derive(Debug, Clone, PartialEq, Eq, Hash)] pub struct TupleFieldDef { pub(crate) syntax: SyntaxNode, @@ -209,6 +217,7 @@ impl ast::AttrsOwner for TupleFieldDef {} impl TupleFieldDef { pub fn type_ref(&self) -> Option { support::child(&self.syntax) } } + #[derive(Debug, Clone, PartialEq, Eq, Hash)] pub struct EnumDef { pub(crate) syntax: SyntaxNode, @@ -230,9 +239,10 @@ impl ast::TypeParamsOwner for EnumDef {} impl ast::AttrsOwner for EnumDef {} impl ast::DocCommentsOwner for EnumDef {} impl EnumDef { - pub fn enum_token(&self) -> Option { support::token2(&self.syntax, ENUM_KW) } + pub fn enum_token(&self) -> Option { support::token(&self.syntax, T![enum]) } pub fn variant_list(&self) -> Option { support::child(&self.syntax) } } + #[derive(Debug, Clone, PartialEq, Eq, Hash)] pub struct EnumVariantList { pub(crate) syntax: SyntaxNode, @@ -249,10 +259,11 @@ impl AstNode for EnumVariantList { fn syntax(&self) -> &SyntaxNode { &self.syntax } } impl EnumVariantList { - pub fn l_curly_token(&self) -> Option { support::token(&self.syntax) } + pub fn l_curly_token(&self) -> Option { support::token(&self.syntax, T!['{']) } pub fn variants(&self) -> AstChildren { support::children(&self.syntax) } - pub fn r_curly_token(&self) -> Option { support::token(&self.syntax) } + pub fn r_curly_token(&self) -> Option { support::token(&self.syntax, T!['}']) } } + #[derive(Debug, Clone, PartialEq, Eq, Hash)] pub struct EnumVariant { pub(crate) syntax: SyntaxNode, @@ -274,9 +285,10 @@ impl ast::DocCommentsOwner for EnumVariant {} impl ast::AttrsOwner for EnumVariant {} impl EnumVariant { pub fn field_def_list(&self) -> Option { support::child(&self.syntax) } - pub fn eq_token(&self) -> Option { support::token(&self.syntax) } + pub fn eq_token(&self) -> Option { support::token(&self.syntax, T![=]) } pub fn expr(&self) -> Option { support::child(&self.syntax) } } + #[derive(Debug, Clone, PartialEq, Eq, Hash)] pub struct TraitDef { pub(crate) syntax: SyntaxNode, @@ -299,11 +311,12 @@ impl ast::DocCommentsOwner for TraitDef {} impl ast::TypeParamsOwner for TraitDef {} impl ast::TypeBoundsOwner for TraitDef {} impl TraitDef { - pub fn unsafe_token(&self) -> Option { support::token2(&self.syntax, UNSAFE_KW) } - pub fn auto_token(&self) -> Option { support::token2(&self.syntax, AUTO_KW) } - pub fn trait_token(&self) -> Option { support::token2(&self.syntax, TRAIT_KW) } + pub fn unsafe_token(&self) -> Option { support::token(&self.syntax, T![unsafe]) } + pub fn auto_token(&self) -> Option { support::token(&self.syntax, T![auto]) } + pub fn trait_token(&self) -> Option { support::token(&self.syntax, T![trait]) } pub fn item_list(&self) -> Option { support::child(&self.syntax) } } + #[derive(Debug, Clone, PartialEq, Eq, Hash)] pub struct Module { pub(crate) syntax: SyntaxNode, @@ -324,10 +337,11 @@ impl ast::NameOwner for Module {} impl ast::AttrsOwner for Module {} impl ast::DocCommentsOwner for Module {} impl Module { - pub fn mod_token(&self) -> Option { support::token2(&self.syntax, MOD_KW) } + pub fn mod_token(&self) -> Option { support::token(&self.syntax, T![mod]) } pub fn item_list(&self) -> Option { support::child(&self.syntax) } - pub fn semi_token(&self) -> Option { support::token(&self.syntax) } + pub fn semicolon_token(&self) -> Option { support::token(&self.syntax, T![;]) } } + #[derive(Debug, Clone, PartialEq, Eq, Hash)] pub struct ItemList { pub(crate) syntax: SyntaxNode, @@ -345,10 +359,11 @@ impl AstNode for ItemList { } impl ast::ModuleItemOwner for ItemList {} impl ItemList { - pub fn l_curly_token(&self) -> Option { support::token(&self.syntax) } + pub fn l_curly_token(&self) -> Option { support::token(&self.syntax, T!['{']) } pub fn impl_items(&self) -> AstChildren { support::children(&self.syntax) } - pub fn r_curly_token(&self) -> Option { support::token(&self.syntax) } + pub fn r_curly_token(&self) -> Option { support::token(&self.syntax, T!['}']) } } + #[derive(Debug, Clone, PartialEq, Eq, Hash)] pub struct ConstDef { pub(crate) syntax: SyntaxNode, @@ -371,12 +386,13 @@ impl ast::AttrsOwner for ConstDef {} impl ast::DocCommentsOwner for ConstDef {} impl ast::TypeAscriptionOwner for ConstDef {} impl ConstDef { - pub fn default_token(&self) -> Option { support::token2(&self.syntax, DEFAULT_KW) } - pub fn const_token(&self) -> Option { support::token2(&self.syntax, CONST_KW) } - pub fn eq_token(&self) -> Option { support::token(&self.syntax) } + pub fn default_token(&self) -> Option { support::token(&self.syntax, T![default]) } + pub fn const_token(&self) -> Option { support::token(&self.syntax, T![const]) } + pub fn eq_token(&self) -> Option { support::token(&self.syntax, T![=]) } pub fn body(&self) -> Option { support::child(&self.syntax) } - pub fn semi_token(&self) -> Option { support::token(&self.syntax) } + pub fn semicolon_token(&self) -> Option { support::token(&self.syntax, T![;]) } } + #[derive(Debug, Clone, PartialEq, Eq, Hash)] pub struct StaticDef { pub(crate) syntax: SyntaxNode, @@ -399,12 +415,13 @@ impl ast::AttrsOwner for StaticDef {} impl ast::DocCommentsOwner for StaticDef {} impl ast::TypeAscriptionOwner for StaticDef {} impl StaticDef { - pub fn static_token(&self) -> Option { support::token2(&self.syntax, STATIC_KW) } - pub fn mut_token(&self) -> Option { support::token2(&self.syntax, MUT_KW) } - pub fn eq_token(&self) -> Option { support::token(&self.syntax) } + pub fn static_token(&self) -> Option { support::token(&self.syntax, T![static]) } + pub fn mut_token(&self) -> Option { support::token(&self.syntax, T![mut]) } + pub fn eq_token(&self) -> Option { support::token(&self.syntax, T![=]) } pub fn body(&self) -> Option { support::child(&self.syntax) } - pub fn semi_token(&self) -> Option { support::token(&self.syntax) } + pub fn semicolon_token(&self) -> Option { support::token(&self.syntax, T![;]) } } + #[derive(Debug, Clone, PartialEq, Eq, Hash)] pub struct TypeAliasDef { pub(crate) syntax: SyntaxNode, @@ -427,12 +444,13 @@ impl ast::AttrsOwner for TypeAliasDef {} impl ast::DocCommentsOwner for TypeAliasDef {} impl ast::TypeBoundsOwner for TypeAliasDef {} impl TypeAliasDef { - pub fn default_token(&self) -> Option { support::token2(&self.syntax, DEFAULT_KW) } - pub fn type_token(&self) -> Option { support::token2(&self.syntax, TYPE_KW) } - pub fn eq_token(&self) -> Option { support::token(&self.syntax) } + pub fn default_token(&self) -> Option { support::token(&self.syntax, T![default]) } + pub fn type_token(&self) -> Option { support::token(&self.syntax, T![type]) } + pub fn eq_token(&self) -> Option { support::token(&self.syntax, T![=]) } pub fn type_ref(&self) -> Option { support::child(&self.syntax) } - pub fn semi_token(&self) -> Option { support::token(&self.syntax) } + pub fn semicolon_token(&self) -> Option { support::token(&self.syntax, T![;]) } } + #[derive(Debug, Clone, PartialEq, Eq, Hash)] pub struct ImplDef { pub(crate) syntax: SyntaxNode, @@ -451,14 +469,15 @@ impl AstNode for ImplDef { impl ast::TypeParamsOwner for ImplDef {} impl ast::AttrsOwner for ImplDef {} impl ImplDef { - pub fn default_token(&self) -> Option { support::token2(&self.syntax, DEFAULT_KW) } - pub fn const_token(&self) -> Option { support::token2(&self.syntax, CONST_KW) } - pub fn unsafe_token(&self) -> Option { support::token2(&self.syntax, UNSAFE_KW) } - pub fn impl_token(&self) -> Option { support::token2(&self.syntax, IMPL_KW) } - pub fn excl_token(&self) -> Option { support::token(&self.syntax) } - pub fn for_token(&self) -> Option { support::token2(&self.syntax, FOR_KW) } + pub fn default_token(&self) -> Option { support::token(&self.syntax, T![default]) } + pub fn const_token(&self) -> Option { support::token(&self.syntax, T![const]) } + pub fn unsafe_token(&self) -> Option { support::token(&self.syntax, T![unsafe]) } + pub fn impl_token(&self) -> Option { support::token(&self.syntax, T![impl]) } + pub fn excl_token(&self) -> Option { support::token(&self.syntax, T![!]) } + pub fn for_token(&self) -> Option { support::token(&self.syntax, T![for]) } pub fn item_list(&self) -> Option { support::child(&self.syntax) } } + #[derive(Debug, Clone, PartialEq, Eq, Hash)] pub struct ParenType { pub(crate) syntax: SyntaxNode, @@ -475,10 +494,11 @@ impl AstNode for ParenType { fn syntax(&self) -> &SyntaxNode { &self.syntax } } impl ParenType { - pub fn l_paren_token(&self) -> Option { support::token(&self.syntax) } + pub fn l_paren_token(&self) -> Option { support::token(&self.syntax, T!['(']) } pub fn type_ref(&self) -> Option { support::child(&self.syntax) } - pub fn r_paren_token(&self) -> Option { support::token(&self.syntax) } + pub fn r_paren_token(&self) -> Option { support::token(&self.syntax, T![')']) } } + #[derive(Debug, Clone, PartialEq, Eq, Hash)] pub struct TupleType { pub(crate) syntax: SyntaxNode, @@ -495,10 +515,11 @@ impl AstNode for TupleType { fn syntax(&self) -> &SyntaxNode { &self.syntax } } impl TupleType { - pub fn l_paren_token(&self) -> Option { support::token(&self.syntax) } + pub fn l_paren_token(&self) -> Option { support::token(&self.syntax, T!['(']) } pub fn fields(&self) -> AstChildren { support::children(&self.syntax) } - pub fn r_paren_token(&self) -> Option { support::token(&self.syntax) } + pub fn r_paren_token(&self) -> Option { support::token(&self.syntax, T![')']) } } + #[derive(Debug, Clone, PartialEq, Eq, Hash)] pub struct NeverType { pub(crate) syntax: SyntaxNode, @@ -515,8 +536,9 @@ impl AstNode for NeverType { fn syntax(&self) -> &SyntaxNode { &self.syntax } } impl NeverType { - pub fn excl_token(&self) -> Option { support::token(&self.syntax) } + pub fn excl_token(&self) -> Option { support::token(&self.syntax, T![!]) } } + #[derive(Debug, Clone, PartialEq, Eq, Hash)] pub struct PathType { pub(crate) syntax: SyntaxNode, @@ -535,6 +557,7 @@ impl AstNode for PathType { impl PathType { pub fn path(&self) -> Option { support::child(&self.syntax) } } + #[derive(Debug, Clone, PartialEq, Eq, Hash)] pub struct PointerType { pub(crate) syntax: SyntaxNode, @@ -551,11 +574,12 @@ impl AstNode for PointerType { fn syntax(&self) -> &SyntaxNode { &self.syntax } } impl PointerType { - pub fn star_token(&self) -> Option { support::token(&self.syntax) } - pub fn const_token(&self) -> Option { support::token2(&self.syntax, CONST_KW) } - pub fn mut_token(&self) -> Option { support::token2(&self.syntax, MUT_KW) } + pub fn star_token(&self) -> Option { support::token(&self.syntax, T![*]) } + pub fn const_token(&self) -> Option { support::token(&self.syntax, T![const]) } + pub fn mut_token(&self) -> Option { support::token(&self.syntax, T![mut]) } pub fn type_ref(&self) -> Option { support::child(&self.syntax) } } + #[derive(Debug, Clone, PartialEq, Eq, Hash)] pub struct ArrayType { pub(crate) syntax: SyntaxNode, @@ -572,12 +596,13 @@ impl AstNode for ArrayType { fn syntax(&self) -> &SyntaxNode { &self.syntax } } impl ArrayType { - pub fn l_brack_token(&self) -> Option { support::token(&self.syntax) } + pub fn l_brack_token(&self) -> Option { support::token(&self.syntax, T!['[']) } pub fn type_ref(&self) -> Option { support::child(&self.syntax) } - pub fn semi_token(&self) -> Option { support::token(&self.syntax) } + pub fn semicolon_token(&self) -> Option { support::token(&self.syntax, T![;]) } pub fn expr(&self) -> Option { support::child(&self.syntax) } - pub fn r_brack_token(&self) -> Option { support::token(&self.syntax) } + pub fn r_brack_token(&self) -> Option { support::token(&self.syntax, T![']']) } } + #[derive(Debug, Clone, PartialEq, Eq, Hash)] pub struct SliceType { pub(crate) syntax: SyntaxNode, @@ -594,10 +619,11 @@ impl AstNode for SliceType { fn syntax(&self) -> &SyntaxNode { &self.syntax } } impl SliceType { - pub fn l_brack_token(&self) -> Option { support::token(&self.syntax) } + pub fn l_brack_token(&self) -> Option { support::token(&self.syntax, T!['[']) } pub fn type_ref(&self) -> Option { support::child(&self.syntax) } - pub fn r_brack_token(&self) -> Option { support::token(&self.syntax) } + pub fn r_brack_token(&self) -> Option { support::token(&self.syntax, T![']']) } } + #[derive(Debug, Clone, PartialEq, Eq, Hash)] pub struct ReferenceType { pub(crate) syntax: SyntaxNode, @@ -614,11 +640,14 @@ impl AstNode for ReferenceType { fn syntax(&self) -> &SyntaxNode { &self.syntax } } impl ReferenceType { - pub fn amp_token(&self) -> Option { support::token(&self.syntax) } - pub fn lifetime_token(&self) -> Option { support::token(&self.syntax) } - pub fn mut_token(&self) -> Option { support::token2(&self.syntax, MUT_KW) } + pub fn amp_token(&self) -> Option { support::token(&self.syntax, T![&]) } + pub fn lifetime_token(&self) -> Option { + support::token(&self.syntax, T![lifetime]) + } + pub fn mut_token(&self) -> Option { support::token(&self.syntax, T![mut]) } pub fn type_ref(&self) -> Option { support::child(&self.syntax) } } + #[derive(Debug, Clone, PartialEq, Eq, Hash)] pub struct PlaceholderType { pub(crate) syntax: SyntaxNode, @@ -635,8 +664,9 @@ impl AstNode for PlaceholderType { fn syntax(&self) -> &SyntaxNode { &self.syntax } } impl PlaceholderType { - pub fn underscore_token(&self) -> Option { support::token(&self.syntax) } + pub fn underscore_token(&self) -> Option { support::token(&self.syntax, T![_]) } } + #[derive(Debug, Clone, PartialEq, Eq, Hash)] pub struct FnPointerType { pub(crate) syntax: SyntaxNode, @@ -654,11 +684,12 @@ impl AstNode for FnPointerType { } impl FnPointerType { pub fn abi(&self) -> Option { support::child(&self.syntax) } - pub fn unsafe_token(&self) -> Option { support::token2(&self.syntax, UNSAFE_KW) } - pub fn fn_token(&self) -> Option { support::token2(&self.syntax, FN_KW) } + pub fn unsafe_token(&self) -> Option { support::token(&self.syntax, T![unsafe]) } + pub fn fn_token(&self) -> Option { support::token(&self.syntax, T![fn]) } pub fn param_list(&self) -> Option { support::child(&self.syntax) } pub fn ret_type(&self) -> Option { support::child(&self.syntax) } } + #[derive(Debug, Clone, PartialEq, Eq, Hash)] pub struct ForType { pub(crate) syntax: SyntaxNode, @@ -675,10 +706,11 @@ impl AstNode for ForType { fn syntax(&self) -> &SyntaxNode { &self.syntax } } impl ForType { - pub fn for_token(&self) -> Option { support::token2(&self.syntax, FOR_KW) } + pub fn for_token(&self) -> Option { support::token(&self.syntax, T![for]) } pub fn type_param_list(&self) -> Option { support::child(&self.syntax) } pub fn type_ref(&self) -> Option { support::child(&self.syntax) } } + #[derive(Debug, Clone, PartialEq, Eq, Hash)] pub struct ImplTraitType { pub(crate) syntax: SyntaxNode, @@ -696,8 +728,9 @@ impl AstNode for ImplTraitType { } impl ast::TypeBoundsOwner for ImplTraitType {} impl ImplTraitType { - pub fn impl_token(&self) -> Option { support::token2(&self.syntax, IMPL_KW) } + pub fn impl_token(&self) -> Option { support::token(&self.syntax, T![impl]) } } + #[derive(Debug, Clone, PartialEq, Eq, Hash)] pub struct DynTraitType { pub(crate) syntax: SyntaxNode, @@ -715,8 +748,9 @@ impl AstNode for DynTraitType { } impl ast::TypeBoundsOwner for DynTraitType {} impl DynTraitType { - pub fn dyn_token(&self) -> Option { support::token2(&self.syntax, DYN_KW) } + pub fn dyn_token(&self) -> Option { support::token(&self.syntax, T![dyn]) } } + #[derive(Debug, Clone, PartialEq, Eq, Hash)] pub struct TupleExpr { pub(crate) syntax: SyntaxNode, @@ -734,10 +768,11 @@ impl AstNode for TupleExpr { } impl ast::AttrsOwner for TupleExpr {} impl TupleExpr { - pub fn l_paren_token(&self) -> Option { support::token(&self.syntax) } + pub fn l_paren_token(&self) -> Option { support::token(&self.syntax, T!['(']) } pub fn exprs(&self) -> AstChildren { support::children(&self.syntax) } - pub fn r_paren_token(&self) -> Option { support::token(&self.syntax) } + pub fn r_paren_token(&self) -> Option { support::token(&self.syntax, T![')']) } } + #[derive(Debug, Clone, PartialEq, Eq, Hash)] pub struct ArrayExpr { pub(crate) syntax: SyntaxNode, @@ -755,11 +790,12 @@ impl AstNode for ArrayExpr { } impl ast::AttrsOwner for ArrayExpr {} impl ArrayExpr { - pub fn l_brack_token(&self) -> Option { support::token(&self.syntax) } + pub fn l_brack_token(&self) -> Option { support::token(&self.syntax, T!['[']) } pub fn exprs(&self) -> AstChildren { support::children(&self.syntax) } - pub fn semi_token(&self) -> Option { support::token(&self.syntax) } - pub fn r_brack_token(&self) -> Option { support::token(&self.syntax) } + pub fn semicolon_token(&self) -> Option { support::token(&self.syntax, T![;]) } + pub fn r_brack_token(&self) -> Option { support::token(&self.syntax, T![']']) } } + #[derive(Debug, Clone, PartialEq, Eq, Hash)] pub struct ParenExpr { pub(crate) syntax: SyntaxNode, @@ -777,10 +813,11 @@ impl AstNode for ParenExpr { } impl ast::AttrsOwner for ParenExpr {} impl ParenExpr { - pub fn l_paren_token(&self) -> Option { support::token(&self.syntax) } + pub fn l_paren_token(&self) -> Option { support::token(&self.syntax, T!['(']) } pub fn expr(&self) -> Option { support::child(&self.syntax) } - pub fn r_paren_token(&self) -> Option { support::token(&self.syntax) } + pub fn r_paren_token(&self) -> Option { support::token(&self.syntax, T![')']) } } + #[derive(Debug, Clone, PartialEq, Eq, Hash)] pub struct PathExpr { pub(crate) syntax: SyntaxNode, @@ -799,6 +836,7 @@ impl AstNode for PathExpr { impl PathExpr { pub fn path(&self) -> Option { support::child(&self.syntax) } } + #[derive(Debug, Clone, PartialEq, Eq, Hash)] pub struct LambdaExpr { pub(crate) syntax: SyntaxNode, @@ -816,13 +854,14 @@ impl AstNode for LambdaExpr { } impl ast::AttrsOwner for LambdaExpr {} impl LambdaExpr { - pub fn static_token(&self) -> Option { support::token2(&self.syntax, STATIC_KW) } - pub fn async_token(&self) -> Option { support::token2(&self.syntax, ASYNC_KW) } - pub fn move_token(&self) -> Option { support::token2(&self.syntax, MOVE_KW) } + pub fn static_token(&self) -> Option { support::token(&self.syntax, T![static]) } + pub fn async_token(&self) -> Option { support::token(&self.syntax, T![async]) } + pub fn move_token(&self) -> Option { support::token(&self.syntax, T![move]) } pub fn param_list(&self) -> Option { support::child(&self.syntax) } pub fn ret_type(&self) -> Option { support::child(&self.syntax) } pub fn body(&self) -> Option { support::child(&self.syntax) } } + #[derive(Debug, Clone, PartialEq, Eq, Hash)] pub struct IfExpr { pub(crate) syntax: SyntaxNode, @@ -840,9 +879,10 @@ impl AstNode for IfExpr { } impl ast::AttrsOwner for IfExpr {} impl IfExpr { - pub fn if_token(&self) -> Option { support::token2(&self.syntax, IF_KW) } + pub fn if_token(&self) -> Option { support::token(&self.syntax, T![if]) } pub fn condition(&self) -> Option { support::child(&self.syntax) } } + #[derive(Debug, Clone, PartialEq, Eq, Hash)] pub struct LoopExpr { pub(crate) syntax: SyntaxNode, @@ -861,8 +901,9 @@ impl AstNode for LoopExpr { impl ast::AttrsOwner for LoopExpr {} impl ast::LoopBodyOwner for LoopExpr {} impl LoopExpr { - pub fn loop_token(&self) -> Option { support::token2(&self.syntax, LOOP_KW) } + pub fn loop_token(&self) -> Option { support::token(&self.syntax, T![loop]) } } + #[derive(Debug, Clone, PartialEq, Eq, Hash)] pub struct TryBlockExpr { pub(crate) syntax: SyntaxNode, @@ -880,9 +921,10 @@ impl AstNode for TryBlockExpr { } impl ast::AttrsOwner for TryBlockExpr {} impl TryBlockExpr { - pub fn try_token(&self) -> Option { support::token2(&self.syntax, TRY_KW) } + pub fn try_token(&self) -> Option { support::token(&self.syntax, T![try]) } pub fn body(&self) -> Option { support::child(&self.syntax) } } + #[derive(Debug, Clone, PartialEq, Eq, Hash)] pub struct ForExpr { pub(crate) syntax: SyntaxNode, @@ -901,11 +943,12 @@ impl AstNode for ForExpr { impl ast::AttrsOwner for ForExpr {} impl ast::LoopBodyOwner for ForExpr {} impl ForExpr { - pub fn for_token(&self) -> Option { support::token2(&self.syntax, FOR_KW) } + pub fn for_token(&self) -> Option { support::token(&self.syntax, T![for]) } pub fn pat(&self) -> Option { support::child(&self.syntax) } - pub fn in_token(&self) -> Option { support::token2(&self.syntax, IN_KW) } + pub fn in_token(&self) -> Option { support::token(&self.syntax, T![in]) } pub fn iterable(&self) -> Option { support::child(&self.syntax) } } + #[derive(Debug, Clone, PartialEq, Eq, Hash)] pub struct WhileExpr { pub(crate) syntax: SyntaxNode, @@ -924,9 +967,10 @@ impl AstNode for WhileExpr { impl ast::AttrsOwner for WhileExpr {} impl ast::LoopBodyOwner for WhileExpr {} impl WhileExpr { - pub fn while_token(&self) -> Option { support::token2(&self.syntax, WHILE_KW) } + pub fn while_token(&self) -> Option { support::token(&self.syntax, T![while]) } pub fn condition(&self) -> Option { support::child(&self.syntax) } } + #[derive(Debug, Clone, PartialEq, Eq, Hash)] pub struct ContinueExpr { pub(crate) syntax: SyntaxNode, @@ -945,10 +989,13 @@ impl AstNode for ContinueExpr { impl ast::AttrsOwner for ContinueExpr {} impl ContinueExpr { pub fn continue_token(&self) -> Option { - support::token2(&self.syntax, CONTINUE_KW) + support::token(&self.syntax, T![continue]) + } + pub fn lifetime_token(&self) -> Option { + support::token(&self.syntax, T![lifetime]) } - pub fn lifetime_token(&self) -> Option { support::token(&self.syntax) } } + #[derive(Debug, Clone, PartialEq, Eq, Hash)] pub struct BreakExpr { pub(crate) syntax: SyntaxNode, @@ -966,10 +1013,13 @@ impl AstNode for BreakExpr { } impl ast::AttrsOwner for BreakExpr {} impl BreakExpr { - pub fn break_token(&self) -> Option { support::token2(&self.syntax, BREAK_KW) } - pub fn lifetime_token(&self) -> Option { support::token(&self.syntax) } + pub fn break_token(&self) -> Option { support::token(&self.syntax, T![break]) } + pub fn lifetime_token(&self) -> Option { + support::token(&self.syntax, T![lifetime]) + } pub fn expr(&self) -> Option { support::child(&self.syntax) } } + #[derive(Debug, Clone, PartialEq, Eq, Hash)] pub struct Label { pub(crate) syntax: SyntaxNode, @@ -986,8 +1036,11 @@ impl AstNode for Label { fn syntax(&self) -> &SyntaxNode { &self.syntax } } impl Label { - pub fn lifetime_token(&self) -> Option { support::token(&self.syntax) } + pub fn lifetime_token(&self) -> Option { + support::token(&self.syntax, T![lifetime]) + } } + #[derive(Debug, Clone, PartialEq, Eq, Hash)] pub struct BlockExpr { pub(crate) syntax: SyntaxNode, @@ -1006,9 +1059,10 @@ impl AstNode for BlockExpr { impl ast::AttrsOwner for BlockExpr {} impl BlockExpr { pub fn label(&self) -> Option