From 8d71a6bf0ca51ae099a5b470afdb957bca321441 Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Fri, 10 Apr 2020 11:49:13 +0200 Subject: Scale token generation back --- crates/ra_syntax/src/ast/extensions.rs | 12 +- crates/ra_syntax/src/ast/generated/nodes.rs | 124 +++++++------- crates/ra_syntax/src/ast/generated/tokens.rs | 239 --------------------------- 3 files changed, 69 insertions(+), 306 deletions(-) (limited to 'crates/ra_syntax/src') diff --git a/crates/ra_syntax/src/ast/extensions.rs b/crates/ra_syntax/src/ast/extensions.rs index eee98ebc2..03d94170d 100644 --- a/crates/ra_syntax/src/ast/extensions.rs +++ b/crates/ra_syntax/src/ast/extensions.rs @@ -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() } } @@ -315,7 +311,7 @@ pub enum TypeBoundKind { /// for<'a> ... ForType(ast::ForType), /// 'a - Lifetime(ast::Lifetime), + Lifetime(SyntaxToken), } impl ast::TypeBound { @@ -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,7 +405,7 @@ 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) } diff --git a/crates/ra_syntax/src/ast/generated/nodes.rs b/crates/ra_syntax/src/ast/generated/nodes.rs index 106a91c12..d67d733b1 100644 --- a/crates/ra_syntax/src/ast/generated/nodes.rs +++ b/crates/ra_syntax/src/ast/generated/nodes.rs @@ -1,6 +1,5 @@ //! Generated file, do not edit by hand, see `xtask/src/codegen` -use super::tokens::*; use crate::{ ast::{self, support, AstChildren, AstNode}, SyntaxKind::{self, *}, @@ -463,7 +462,7 @@ impl ImplDef { pub fn const_token(&self) -> Option { support::token2(&self.syntax, T![const]) } pub fn unsafe_token(&self) -> Option { support::token2(&self.syntax, T![unsafe]) } pub fn impl_token(&self) -> Option { support::token2(&self.syntax, T![impl]) } - pub fn excl_token(&self) -> Option { support::token(&self.syntax) } + pub fn excl_token(&self) -> Option { support::token2(&self.syntax, T![!]) } pub fn for_token(&self) -> Option { support::token2(&self.syntax, T![for]) } pub fn item_list(&self) -> Option { support::child(&self.syntax) } } @@ -523,7 +522,7 @@ 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::token2(&self.syntax, T![!]) } } #[derive(Debug, Clone, PartialEq, Eq, Hash)] pub struct PathType { @@ -559,7 +558,7 @@ impl AstNode for PointerType { fn syntax(&self) -> &SyntaxNode { &self.syntax } } impl PointerType { - pub fn star_token(&self) -> Option { support::token(&self.syntax) } + pub fn star_token(&self) -> Option { support::token2(&self.syntax, T![*]) } pub fn const_token(&self) -> Option { support::token2(&self.syntax, T![const]) } pub fn mut_token(&self) -> Option { support::token2(&self.syntax, T![mut]) } pub fn type_ref(&self) -> Option { support::child(&self.syntax) } @@ -622,8 +621,10 @@ 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 amp_token(&self) -> Option { support::token2(&self.syntax, T![&]) } + pub fn lifetime_token(&self) -> Option { + support::token2(&self.syntax, T![lifetime]) + } pub fn mut_token(&self) -> Option { support::token2(&self.syntax, T![mut]) } pub fn type_ref(&self) -> Option { support::child(&self.syntax) } } @@ -643,7 +644,7 @@ 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::token2(&self.syntax, T![_]) } } #[derive(Debug, Clone, PartialEq, Eq, Hash)] pub struct FnPointerType { @@ -955,7 +956,9 @@ impl ContinueExpr { pub fn continue_token(&self) -> Option { support::token2(&self.syntax, T![continue]) } - pub fn lifetime_token(&self) -> Option { support::token(&self.syntax) } + pub fn lifetime_token(&self) -> Option { + support::token2(&self.syntax, T![lifetime]) + } } #[derive(Debug, Clone, PartialEq, Eq, Hash)] pub struct BreakExpr { @@ -975,7 +978,9 @@ impl AstNode for BreakExpr { impl ast::AttrsOwner for BreakExpr {} impl BreakExpr { pub fn break_token(&self) -> Option { support::token2(&self.syntax, T![break]) } - pub fn lifetime_token(&self) -> Option { support::token(&self.syntax) } + pub fn lifetime_token(&self) -> Option { + support::token2(&self.syntax, T![lifetime]) + } pub fn expr(&self) -> Option { support::child(&self.syntax) } } #[derive(Debug, Clone, PartialEq, Eq, Hash)] @@ -994,7 +999,9 @@ 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::token2(&self.syntax, T![lifetime]) + } } #[derive(Debug, Clone, PartialEq, Eq, Hash)] pub struct BlockExpr { @@ -1074,7 +1081,7 @@ impl ast::AttrsOwner for MethodCallExpr {} impl ast::ArgListOwner for MethodCallExpr {} impl MethodCallExpr { pub fn expr(&self) -> Option { support::child(&self.syntax) } - pub fn dot_token(&self) -> Option { support::token(&self.syntax) } + pub fn dot_token(&self) -> Option { support::token2(&self.syntax, T![.]) } pub fn name_ref(&self) -> Option { support::child(&self.syntax) } pub fn type_arg_list(&self) -> Option { support::child(&self.syntax) } } @@ -1116,7 +1123,7 @@ impl AstNode for FieldExpr { impl ast::AttrsOwner for FieldExpr {} impl FieldExpr { pub fn expr(&self) -> Option { support::child(&self.syntax) } - pub fn dot_token(&self) -> Option { support::token(&self.syntax) } + pub fn dot_token(&self) -> Option { support::token2(&self.syntax, T![.]) } pub fn name_ref(&self) -> Option { support::child(&self.syntax) } } #[derive(Debug, Clone, PartialEq, Eq, Hash)] @@ -1137,7 +1144,7 @@ impl AstNode for AwaitExpr { impl ast::AttrsOwner for AwaitExpr {} impl AwaitExpr { pub fn expr(&self) -> Option { support::child(&self.syntax) } - pub fn dot_token(&self) -> Option { support::token(&self.syntax) } + pub fn dot_token(&self) -> Option { support::token2(&self.syntax, T![.]) } pub fn await_token(&self) -> Option { support::token2(&self.syntax, T![await]) } } #[derive(Debug, Clone, PartialEq, Eq, Hash)] @@ -1198,7 +1205,7 @@ impl AstNode for RefExpr { } impl ast::AttrsOwner for RefExpr {} impl RefExpr { - pub fn amp_token(&self) -> Option { support::token(&self.syntax) } + pub fn amp_token(&self) -> Option { support::token2(&self.syntax, T![&]) } pub fn raw_token(&self) -> Option { support::token2(&self.syntax, T![raw]) } pub fn mut_token(&self) -> Option { support::token2(&self.syntax, T![mut]) } pub fn expr(&self) -> Option { support::child(&self.syntax) } @@ -1220,7 +1227,6 @@ impl AstNode for PrefixExpr { } impl ast::AttrsOwner for PrefixExpr {} impl PrefixExpr { - pub fn prefix_op_token(&self) -> Option { support::token(&self.syntax) } pub fn expr(&self) -> Option { support::child(&self.syntax) } } #[derive(Debug, Clone, PartialEq, Eq, Hash)] @@ -1259,9 +1265,7 @@ impl AstNode for RangeExpr { fn syntax(&self) -> &SyntaxNode { &self.syntax } } impl ast::AttrsOwner for RangeExpr {} -impl RangeExpr { - pub fn range_op_token(&self) -> Option { support::token(&self.syntax) } -} +impl RangeExpr {} #[derive(Debug, Clone, PartialEq, Eq, Hash)] pub struct BinExpr { pub(crate) syntax: SyntaxNode, @@ -1294,9 +1298,7 @@ impl AstNode for Literal { } fn syntax(&self) -> &SyntaxNode { &self.syntax } } -impl Literal { - pub fn literal_token_token(&self) -> Option { support::token(&self.syntax) } -} +impl Literal {} #[derive(Debug, Clone, PartialEq, Eq, Hash)] pub struct MatchExpr { pub(crate) syntax: SyntaxNode, @@ -1358,7 +1360,7 @@ impl ast::AttrsOwner for MatchArm {} impl MatchArm { pub fn pat(&self) -> Option { support::child(&self.syntax) } pub fn guard(&self) -> Option { support::child(&self.syntax) } - pub fn fat_arrow_token(&self) -> Option { support::token(&self.syntax) } + pub fn fat_arrow_token(&self) -> Option { support::token2(&self.syntax, T![=>]) } pub fn expr(&self) -> Option { support::child(&self.syntax) } } #[derive(Debug, Clone, PartialEq, Eq, Hash)] @@ -1417,7 +1419,7 @@ impl AstNode for RecordFieldList { impl RecordFieldList { pub fn l_curly_token(&self) -> Option { support::token2(&self.syntax, T!['{']) } pub fn fields(&self) -> AstChildren { support::children(&self.syntax) } - pub fn dotdot_token(&self) -> Option { support::token(&self.syntax) } + pub fn dotdot_token(&self) -> Option { support::token2(&self.syntax, T![..]) } pub fn spread(&self) -> Option { support::child(&self.syntax) } pub fn r_curly_token(&self) -> Option { support::token2(&self.syntax, T!['}']) } } @@ -1439,7 +1441,7 @@ impl AstNode for RecordField { impl ast::AttrsOwner for RecordField {} impl RecordField { pub fn name_ref(&self) -> Option { support::child(&self.syntax) } - pub fn colon_token(&self) -> Option { support::token(&self.syntax) } + pub fn colon_token(&self) -> Option { support::token2(&self.syntax, T![:]) } pub fn expr(&self) -> Option { support::child(&self.syntax) } } #[derive(Debug, Clone, PartialEq, Eq, Hash)] @@ -1496,7 +1498,7 @@ impl AstNode for RefPat { fn syntax(&self) -> &SyntaxNode { &self.syntax } } impl RefPat { - pub fn amp_token(&self) -> Option { support::token(&self.syntax) } + pub fn amp_token(&self) -> Option { support::token2(&self.syntax, T![&]) } pub fn mut_token(&self) -> Option { support::token2(&self.syntax, T![mut]) } pub fn pat(&self) -> Option { support::child(&self.syntax) } } @@ -1539,7 +1541,7 @@ impl ast::NameOwner for BindPat {} impl BindPat { pub fn ref_token(&self) -> Option { support::token2(&self.syntax, T![ref]) } pub fn mut_token(&self) -> Option { support::token2(&self.syntax, T![mut]) } - pub fn at_token(&self) -> Option { support::token(&self.syntax) } + pub fn at_token(&self) -> Option { support::token2(&self.syntax, T![@]) } pub fn pat(&self) -> Option { support::child(&self.syntax) } } #[derive(Debug, Clone, PartialEq, Eq, Hash)] @@ -1558,7 +1560,7 @@ impl AstNode for PlaceholderPat { fn syntax(&self) -> &SyntaxNode { &self.syntax } } impl PlaceholderPat { - pub fn underscore_token(&self) -> Option { support::token(&self.syntax) } + pub fn underscore_token(&self) -> Option { support::token2(&self.syntax, T![_]) } } #[derive(Debug, Clone, PartialEq, Eq, Hash)] pub struct DotDotPat { @@ -1576,7 +1578,7 @@ impl AstNode for DotDotPat { fn syntax(&self) -> &SyntaxNode { &self.syntax } } impl DotDotPat { - pub fn dotdot_token(&self) -> Option { support::token(&self.syntax) } + pub fn dotdot_token(&self) -> Option { support::token2(&self.syntax, T![..]) } } #[derive(Debug, Clone, PartialEq, Eq, Hash)] pub struct PathPat { @@ -1631,9 +1633,7 @@ impl AstNode for RangePat { } fn syntax(&self) -> &SyntaxNode { &self.syntax } } -impl RangePat { - pub fn range_separator_token(&self) -> Option { support::token(&self.syntax) } -} +impl RangePat {} #[derive(Debug, Clone, PartialEq, Eq, Hash)] pub struct LiteralPat { pub(crate) syntax: SyntaxNode, @@ -1713,7 +1713,7 @@ impl RecordFieldPatList { support::children(&self.syntax) } pub fn bind_pats(&self) -> AstChildren { support::children(&self.syntax) } - pub fn dotdot_token(&self) -> Option { support::token(&self.syntax) } + pub fn dotdot_token(&self) -> Option { support::token2(&self.syntax, T![..]) } pub fn r_curly_token(&self) -> Option { support::token2(&self.syntax, T!['}']) } } #[derive(Debug, Clone, PartialEq, Eq, Hash)] @@ -1734,7 +1734,7 @@ impl AstNode for RecordFieldPat { impl ast::AttrsOwner for RecordFieldPat {} impl ast::NameOwner for RecordFieldPat {} impl RecordFieldPat { - pub fn colon_token(&self) -> Option { support::token(&self.syntax) } + pub fn colon_token(&self) -> Option { support::token2(&self.syntax, T![:]) } pub fn pat(&self) -> Option { support::child(&self.syntax) } } #[derive(Debug, Clone, PartialEq, Eq, Hash)] @@ -1815,7 +1815,7 @@ impl AstNode for Name { fn syntax(&self) -> &SyntaxNode { &self.syntax } } impl Name { - pub fn ident_token(&self) -> Option { support::token(&self.syntax) } + pub fn ident_token(&self) -> Option { support::token2(&self.syntax, T![ident]) } } #[derive(Debug, Clone, PartialEq, Eq, Hash)] pub struct NameRef { @@ -1832,9 +1832,7 @@ impl AstNode for NameRef { } fn syntax(&self) -> &SyntaxNode { &self.syntax } } -impl NameRef { - pub fn name_ref_token_token(&self) -> Option { support::token(&self.syntax) } -} +impl NameRef {} #[derive(Debug, Clone, PartialEq, Eq, Hash)] pub struct MacroCall { pub(crate) syntax: SyntaxNode, @@ -1855,7 +1853,7 @@ impl ast::AttrsOwner for MacroCall {} impl ast::DocCommentsOwner for MacroCall {} impl MacroCall { pub fn path(&self) -> Option { support::child(&self.syntax) } - pub fn excl_token(&self) -> Option { support::token(&self.syntax) } + pub fn excl_token(&self) -> Option { support::token2(&self.syntax, T![!]) } pub fn token_tree(&self) -> Option { support::child(&self.syntax) } pub fn semicolon_token(&self) -> Option { support::token2(&self.syntax, T![;]) } } @@ -1875,8 +1873,8 @@ impl AstNode for Attr { fn syntax(&self) -> &SyntaxNode { &self.syntax } } impl Attr { - pub fn pound_token(&self) -> Option { support::token(&self.syntax) } - pub fn excl_token(&self) -> Option { support::token(&self.syntax) } + pub fn pound_token(&self) -> Option { support::token2(&self.syntax, T![#]) } + pub fn excl_token(&self) -> Option { support::token2(&self.syntax, T![!]) } pub fn l_brack_token(&self) -> Option { support::token2(&self.syntax, T!['[']) } pub fn path(&self) -> Option { support::child(&self.syntax) } pub fn eq_token(&self) -> Option { support::token2(&self.syntax, T![=]) } @@ -1915,12 +1913,12 @@ impl AstNode for TypeParamList { fn syntax(&self) -> &SyntaxNode { &self.syntax } } impl TypeParamList { - pub fn l_angle_token(&self) -> Option { support::token(&self.syntax) } + pub fn l_angle_token(&self) -> Option { support::token2(&self.syntax, T![<]) } pub fn generic_params(&self) -> AstChildren { support::children(&self.syntax) } pub fn type_params(&self) -> AstChildren { support::children(&self.syntax) } pub fn lifetime_params(&self) -> AstChildren { support::children(&self.syntax) } pub fn const_params(&self) -> AstChildren { support::children(&self.syntax) } - pub fn r_angle_token(&self) -> Option { support::token(&self.syntax) } + pub fn r_angle_token(&self) -> Option { support::token2(&self.syntax, T![>]) } } #[derive(Debug, Clone, PartialEq, Eq, Hash)] pub struct TypeParam { @@ -1983,7 +1981,9 @@ impl AstNode for LifetimeParam { } impl ast::AttrsOwner for LifetimeParam {} impl LifetimeParam { - pub fn lifetime_token(&self) -> Option { support::token(&self.syntax) } + pub fn lifetime_token(&self) -> Option { + support::token2(&self.syntax, T![lifetime]) + } } #[derive(Debug, Clone, PartialEq, Eq, Hash)] pub struct TypeBound { @@ -2001,7 +2001,9 @@ impl AstNode for TypeBound { fn syntax(&self) -> &SyntaxNode { &self.syntax } } impl TypeBound { - pub fn lifetime_token(&self) -> Option { support::token(&self.syntax) } + pub fn lifetime_token(&self) -> Option { + support::token2(&self.syntax, T![lifetime]) + } pub fn const_token(&self) -> Option { support::token2(&self.syntax, T![const]) } pub fn type_ref(&self) -> Option { support::child(&self.syntax) } } @@ -2040,7 +2042,9 @@ impl AstNode for WherePred { } impl ast::TypeBoundsOwner for WherePred {} impl WherePred { - pub fn lifetime_token(&self) -> Option { support::token(&self.syntax) } + pub fn lifetime_token(&self) -> Option { + support::token2(&self.syntax, T![lifetime]) + } pub fn type_ref(&self) -> Option { support::child(&self.syntax) } } #[derive(Debug, Clone, PartialEq, Eq, Hash)] @@ -2077,9 +2081,7 @@ impl AstNode for Abi { } fn syntax(&self) -> &SyntaxNode { &self.syntax } } -impl Abi { - pub fn string_token(&self) -> Option { support::token(&self.syntax) } -} +impl Abi {} #[derive(Debug, Clone, PartialEq, Eq, Hash)] pub struct ExprStmt { pub(crate) syntax: SyntaxNode, @@ -2207,8 +2209,10 @@ impl AstNode for SelfParam { impl ast::TypeAscriptionOwner for SelfParam {} impl ast::AttrsOwner for SelfParam {} impl SelfParam { - pub fn amp_token(&self) -> Option { support::token(&self.syntax) } - pub fn lifetime_token(&self) -> Option { support::token(&self.syntax) } + pub fn amp_token(&self) -> Option { support::token2(&self.syntax, T![&]) } + pub fn lifetime_token(&self) -> Option { + support::token2(&self.syntax, T![lifetime]) + } pub fn self_token(&self) -> Option { support::token2(&self.syntax, T![self]) } } #[derive(Debug, Clone, PartialEq, Eq, Hash)] @@ -2230,7 +2234,7 @@ impl ast::TypeAscriptionOwner for Param {} impl ast::AttrsOwner for Param {} impl Param { pub fn pat(&self) -> Option { support::child(&self.syntax) } - pub fn dotdotdot_token(&self) -> Option { support::token(&self.syntax) } + pub fn dotdotdot_token(&self) -> Option { support::token2(&self.syntax, T![...]) } } #[derive(Debug, Clone, PartialEq, Eq, Hash)] pub struct UseItem { @@ -2270,7 +2274,7 @@ impl AstNode for UseTree { } impl UseTree { pub fn path(&self) -> Option { support::child(&self.syntax) } - pub fn star_token(&self) -> Option { support::token(&self.syntax) } + pub fn star_token(&self) -> Option { support::token2(&self.syntax, T![*]) } pub fn use_tree_list(&self) -> Option { support::child(&self.syntax) } pub fn alias(&self) -> Option { support::child(&self.syntax) } } @@ -2391,14 +2395,14 @@ impl AstNode for PathSegment { fn syntax(&self) -> &SyntaxNode { &self.syntax } } impl PathSegment { - pub fn coloncolon_token(&self) -> Option { support::token(&self.syntax) } - pub fn l_angle_token(&self) -> Option { support::token(&self.syntax) } + pub fn coloncolon_token(&self) -> Option { support::token2(&self.syntax, T![::]) } + pub fn l_angle_token(&self) -> Option { support::token2(&self.syntax, T![<]) } pub fn name_ref(&self) -> Option { support::child(&self.syntax) } pub fn type_arg_list(&self) -> Option { support::child(&self.syntax) } pub fn param_list(&self) -> Option { support::child(&self.syntax) } pub fn ret_type(&self) -> Option { support::child(&self.syntax) } pub fn path_type(&self) -> Option { support::child(&self.syntax) } - pub fn r_angle_token(&self) -> Option { support::token(&self.syntax) } + pub fn r_angle_token(&self) -> Option { support::token2(&self.syntax, T![>]) } } #[derive(Debug, Clone, PartialEq, Eq, Hash)] pub struct TypeArgList { @@ -2416,14 +2420,14 @@ impl AstNode for TypeArgList { fn syntax(&self) -> &SyntaxNode { &self.syntax } } impl TypeArgList { - pub fn coloncolon_token(&self) -> Option { support::token(&self.syntax) } - pub fn l_angle_token(&self) -> Option { support::token(&self.syntax) } + pub fn coloncolon_token(&self) -> Option { support::token2(&self.syntax, T![::]) } + pub fn l_angle_token(&self) -> Option { support::token2(&self.syntax, T![<]) } pub fn generic_args(&self) -> AstChildren { support::children(&self.syntax) } pub fn type_args(&self) -> AstChildren { support::children(&self.syntax) } pub fn lifetime_args(&self) -> AstChildren { support::children(&self.syntax) } pub fn assoc_type_args(&self) -> AstChildren { support::children(&self.syntax) } pub fn const_args(&self) -> AstChildren { support::children(&self.syntax) } - pub fn r_angle_token(&self) -> Option { support::token(&self.syntax) } + pub fn r_angle_token(&self) -> Option { support::token2(&self.syntax, T![>]) } } #[derive(Debug, Clone, PartialEq, Eq, Hash)] pub struct TypeArg { @@ -2480,7 +2484,9 @@ impl AstNode for LifetimeArg { fn syntax(&self) -> &SyntaxNode { &self.syntax } } impl LifetimeArg { - pub fn lifetime_token(&self) -> Option { support::token(&self.syntax) } + pub fn lifetime_token(&self) -> Option { + support::token2(&self.syntax, T![lifetime]) + } } #[derive(Debug, Clone, PartialEq, Eq, Hash)] pub struct ConstArg { diff --git a/crates/ra_syntax/src/ast/generated/tokens.rs b/crates/ra_syntax/src/ast/generated/tokens.rs index 7611ce4cb..293f91c2e 100644 --- a/crates/ra_syntax/src/ast/generated/tokens.rs +++ b/crates/ra_syntax/src/ast/generated/tokens.rs @@ -1365,242 +1365,3 @@ impl AstToken for RDollar { } fn syntax(&self) -> &SyntaxToken { &self.syntax } } -#[derive(Debug, Clone, PartialEq, Eq, Hash)] -pub enum RangeSeparator { - Dotdot(Dotdot), - Dotdotdot(Dotdotdot), - Dotdoteq(Dotdoteq), -} -impl From for RangeSeparator { - fn from(node: Dotdot) -> RangeSeparator { RangeSeparator::Dotdot(node) } -} -impl From for RangeSeparator { - fn from(node: Dotdotdot) -> RangeSeparator { RangeSeparator::Dotdotdot(node) } -} -impl From for RangeSeparator { - fn from(node: Dotdoteq) -> RangeSeparator { RangeSeparator::Dotdoteq(node) } -} -impl std::fmt::Display for RangeSeparator { - fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result { - std::fmt::Display::fmt(self.syntax(), f) - } -} -impl AstToken for RangeSeparator { - fn can_cast(kind: SyntaxKind) -> bool { - match kind { - DOTDOT | DOTDOTDOT | DOTDOTEQ => true, - _ => false, - } - } - fn cast(syntax: SyntaxToken) -> Option { - let res = match syntax.kind() { - DOTDOT => RangeSeparator::Dotdot(Dotdot { syntax }), - DOTDOTDOT => RangeSeparator::Dotdotdot(Dotdotdot { syntax }), - DOTDOTEQ => RangeSeparator::Dotdoteq(Dotdoteq { syntax }), - _ => return None, - }; - Some(res) - } - fn syntax(&self) -> &SyntaxToken { - match self { - RangeSeparator::Dotdot(it) => &it.syntax, - RangeSeparator::Dotdotdot(it) => &it.syntax, - RangeSeparator::Dotdoteq(it) => &it.syntax, - } - } -} -#[derive(Debug, Clone, PartialEq, Eq, Hash)] -pub enum PrefixOp { - Minus(Minus), - Excl(Excl), - Star(Star), -} -impl From for PrefixOp { - fn from(node: Minus) -> PrefixOp { PrefixOp::Minus(node) } -} -impl From for PrefixOp { - fn from(node: Excl) -> PrefixOp { PrefixOp::Excl(node) } -} -impl From for PrefixOp { - fn from(node: Star) -> PrefixOp { PrefixOp::Star(node) } -} -impl std::fmt::Display for PrefixOp { - fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result { - std::fmt::Display::fmt(self.syntax(), f) - } -} -impl AstToken for PrefixOp { - fn can_cast(kind: SyntaxKind) -> bool { - match kind { - MINUS | EXCL | STAR => true, - _ => false, - } - } - fn cast(syntax: SyntaxToken) -> Option { - let res = match syntax.kind() { - MINUS => PrefixOp::Minus(Minus { syntax }), - EXCL => PrefixOp::Excl(Excl { syntax }), - STAR => PrefixOp::Star(Star { syntax }), - _ => return None, - }; - Some(res) - } - fn syntax(&self) -> &SyntaxToken { - match self { - PrefixOp::Minus(it) => &it.syntax, - PrefixOp::Excl(it) => &it.syntax, - PrefixOp::Star(it) => &it.syntax, - } - } -} -#[derive(Debug, Clone, PartialEq, Eq, Hash)] -pub enum RangeOp { - Dotdot(Dotdot), - Dotdoteq(Dotdoteq), -} -impl From for RangeOp { - fn from(node: Dotdot) -> RangeOp { RangeOp::Dotdot(node) } -} -impl From for RangeOp { - fn from(node: Dotdoteq) -> RangeOp { RangeOp::Dotdoteq(node) } -} -impl std::fmt::Display for RangeOp { - fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result { - std::fmt::Display::fmt(self.syntax(), f) - } -} -impl AstToken for RangeOp { - fn can_cast(kind: SyntaxKind) -> bool { - match kind { - DOTDOT | DOTDOTEQ => true, - _ => false, - } - } - fn cast(syntax: SyntaxToken) -> Option { - let res = match syntax.kind() { - DOTDOT => RangeOp::Dotdot(Dotdot { syntax }), - DOTDOTEQ => RangeOp::Dotdoteq(Dotdoteq { syntax }), - _ => return None, - }; - Some(res) - } - fn syntax(&self) -> &SyntaxToken { - match self { - RangeOp::Dotdot(it) => &it.syntax, - RangeOp::Dotdoteq(it) => &it.syntax, - } - } -} -#[derive(Debug, Clone, PartialEq, Eq, Hash)] -pub enum LiteralToken { - IntNumber(IntNumber), - FloatNumber(FloatNumber), - String(String), - RawString(RawString), - ByteString(ByteString), - RawByteString(RawByteString), - Char(Char), - Byte(Byte), -} -impl From for LiteralToken { - fn from(node: IntNumber) -> LiteralToken { LiteralToken::IntNumber(node) } -} -impl From for LiteralToken { - fn from(node: FloatNumber) -> LiteralToken { LiteralToken::FloatNumber(node) } -} -impl From for LiteralToken { - fn from(node: String) -> LiteralToken { LiteralToken::String(node) } -} -impl From for LiteralToken { - fn from(node: RawString) -> LiteralToken { LiteralToken::RawString(node) } -} -impl From for LiteralToken { - fn from(node: ByteString) -> LiteralToken { LiteralToken::ByteString(node) } -} -impl From for LiteralToken { - fn from(node: RawByteString) -> LiteralToken { LiteralToken::RawByteString(node) } -} -impl From for LiteralToken { - fn from(node: Char) -> LiteralToken { LiteralToken::Char(node) } -} -impl From for LiteralToken { - fn from(node: Byte) -> LiteralToken { LiteralToken::Byte(node) } -} -impl std::fmt::Display for LiteralToken { - fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result { - std::fmt::Display::fmt(self.syntax(), f) - } -} -impl AstToken for LiteralToken { - fn can_cast(kind: SyntaxKind) -> bool { - match kind { - INT_NUMBER | FLOAT_NUMBER | STRING | RAW_STRING | BYTE_STRING | RAW_BYTE_STRING - | CHAR | BYTE => true, - _ => false, - } - } - fn cast(syntax: SyntaxToken) -> Option { - let res = match syntax.kind() { - INT_NUMBER => LiteralToken::IntNumber(IntNumber { syntax }), - FLOAT_NUMBER => LiteralToken::FloatNumber(FloatNumber { syntax }), - STRING => LiteralToken::String(String { syntax }), - RAW_STRING => LiteralToken::RawString(RawString { syntax }), - BYTE_STRING => LiteralToken::ByteString(ByteString { syntax }), - RAW_BYTE_STRING => LiteralToken::RawByteString(RawByteString { syntax }), - CHAR => LiteralToken::Char(Char { syntax }), - BYTE => LiteralToken::Byte(Byte { syntax }), - _ => return None, - }; - Some(res) - } - fn syntax(&self) -> &SyntaxToken { - match self { - LiteralToken::IntNumber(it) => &it.syntax, - LiteralToken::FloatNumber(it) => &it.syntax, - LiteralToken::String(it) => &it.syntax, - LiteralToken::RawString(it) => &it.syntax, - LiteralToken::ByteString(it) => &it.syntax, - LiteralToken::RawByteString(it) => &it.syntax, - LiteralToken::Char(it) => &it.syntax, - LiteralToken::Byte(it) => &it.syntax, - } - } -} -#[derive(Debug, Clone, PartialEq, Eq, Hash)] -pub enum NameRefToken { - Ident(Ident), - IntNumber(IntNumber), -} -impl From for NameRefToken { - fn from(node: Ident) -> NameRefToken { NameRefToken::Ident(node) } -} -impl From for NameRefToken { - fn from(node: IntNumber) -> NameRefToken { NameRefToken::IntNumber(node) } -} -impl std::fmt::Display for NameRefToken { - fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result { - std::fmt::Display::fmt(self.syntax(), f) - } -} -impl AstToken for NameRefToken { - fn can_cast(kind: SyntaxKind) -> bool { - match kind { - IDENT | INT_NUMBER => true, - _ => false, - } - } - fn cast(syntax: SyntaxToken) -> Option { - let res = match syntax.kind() { - IDENT => NameRefToken::Ident(Ident { syntax }), - INT_NUMBER => NameRefToken::IntNumber(IntNumber { syntax }), - _ => return None, - }; - Some(res) - } - fn syntax(&self) -> &SyntaxToken { - match self { - NameRefToken::Ident(it) => &it.syntax, - NameRefToken::IntNumber(it) => &it.syntax, - } - } -} -- cgit v1.2.3