From d4b007a7438a818c69110f8c9ab4d944647bb5ec Mon Sep 17 00:00:00 2001 From: Kennedy Tedesco Date: Wed, 18 Jan 2023 20:59:28 -0300 Subject: [PATCH 1/2] chore: from `self` to `&self` --- src/lexer/token.rs | 2 +- src/parser/internal/expression/precedence.rs | 2 +- src/tree/definition/class.rs | 6 +++--- src/tree/definition/enum.rs | 22 ++++++++++---------- src/tree/definition/interface.rs | 4 ++-- src/tree/definition/mod.rs | 4 ++-- src/tree/definition/modifier.rs | 8 +++---- src/tree/definition/property.rs | 8 +++---- src/tree/definition/type.rs | 20 +++++++++--------- src/tree/definition/use.rs | 6 +++--- src/tree/expression/argument.rs | 8 +++---- src/tree/expression/construct.rs | 8 +++---- src/tree/expression/control_flow.rs | 6 +++--- src/tree/expression/literal.rs | 6 +++--- src/tree/expression/magic_constant.rs | 6 +++--- src/tree/expression/mod.rs | 12 +++++------ src/tree/expression/operator.rs | 2 +- src/tree/statement/loop.rs | 16 +++++++------- src/tree/statement/try.rs | 6 +++--- 19 files changed, 76 insertions(+), 76 deletions(-) diff --git a/src/lexer/token.rs b/src/lexer/token.rs index e7c2edc..8ac6874 100644 --- a/src/lexer/token.rs +++ b/src/lexer/token.rs @@ -229,7 +229,7 @@ impl Display for Token { impl Display for TokenKind { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { - let s = match self { + let s = match &self { Self::Self_ => "self", Self::Parent => "parent", Self::BangEquals => "!=", diff --git a/src/parser/internal/expression/precedence.rs b/src/parser/internal/expression/precedence.rs index ec75789..200c9fc 100644 --- a/src/parser/internal/expression/precedence.rs +++ b/src/parser/internal/expression/precedence.rs @@ -92,7 +92,7 @@ impl Precedence { } pub fn associativity(&self) -> Option { - Some(match self { + Some(match &self { Self::TypeCheck | Self::ArrayContains | Self::MulDivMod diff --git a/src/tree/definition/class.rs b/src/tree/definition/class.rs index 76fcde7..e4afa10 100644 --- a/src/tree/definition/class.rs +++ b/src/tree/definition/class.rs @@ -191,7 +191,7 @@ impl Node for ClassDefinitionBody { impl Node for ClassDefinitionMember { fn comments(&self) -> Option<&CommentGroup> { - match self { + match &self { Self::Constant(constant) => constant.comments(), Self::Property(property) => property.comments(), Self::AbstractMethod(method) => method.comments(), @@ -202,7 +202,7 @@ impl Node for ClassDefinitionMember { } fn initial_position(&self) -> usize { - match self { + match &self { Self::Constant(constant) => constant.initial_position(), Self::Property(property) => property.initial_position(), Self::AbstractMethod(method) => method.initial_position(), @@ -213,7 +213,7 @@ impl Node for ClassDefinitionMember { } fn final_position(&self) -> usize { - match self { + match &self { Self::Constant(constant) => constant.final_position(), Self::Property(property) => property.final_position(), Self::AbstractMethod(method) => method.final_position(), diff --git a/src/tree/definition/enum.rs b/src/tree/definition/enum.rs index d9d6a53..94fff34 100644 --- a/src/tree/definition/enum.rs +++ b/src/tree/definition/enum.rs @@ -115,14 +115,14 @@ impl Node for EnumDefinition { } fn initial_position(&self) -> usize { - match self { + match &self { EnumDefinition::Backed(definition) => definition.initial_position(), EnumDefinition::Unit(definition) => definition.initial_position(), } } fn final_position(&self) -> usize { - match self { + match &self { EnumDefinition::Backed(definition) => definition.final_position(), EnumDefinition::Unit(definition) => definition.final_position(), } @@ -240,7 +240,7 @@ impl Node for UnitEnumBodyDefinition { impl Node for UnitEnumMemberDefinition { fn initial_position(&self) -> usize { - match self { + match &self { Self::Case(case) => case.initial_position(), Self::Method(method) => method.initial_position(), Self::Constant(constant) => constant.initial_position(), @@ -248,7 +248,7 @@ impl Node for UnitEnumMemberDefinition { } fn final_position(&self) -> usize { - match self { + match &self { Self::Case(case) => case.final_position(), Self::Method(method) => method.final_position(), Self::Constant(constant) => constant.final_position(), @@ -256,7 +256,7 @@ impl Node for UnitEnumMemberDefinition { } fn children(&self) -> Vec<&dyn Node> { - match self { + match &self { Self::Case(case) => vec![case], Self::Method(method) => vec![method], Self::Constant(constant) => vec![constant], @@ -264,7 +264,7 @@ impl Node for UnitEnumMemberDefinition { } fn get_description(&self) -> String { - match self { + match &self { Self::Case(case) => case.get_description(), Self::Method(method) => method.get_description(), Self::Constant(constant) => constant.get_description(), @@ -338,19 +338,19 @@ impl Node for BackedEnumDefinition { impl Node for BackedEnumTypeDefinition { fn initial_position(&self) -> usize { - match self { + match &self { Self::String(colon, _) | Self::Int(colon, _) => *colon, } } fn final_position(&self) -> usize { - match self { + match &self { Self::String(_, identifier) | Self::Int(_, identifier) => identifier.final_position(), } } fn children(&self) -> Vec<&dyn Node> { - match self { + match &self { Self::String(_, identifier) | Self::Int(_, identifier) => vec![identifier], } } @@ -383,7 +383,7 @@ impl Node for BackedEnumBodyDefinition { impl Node for BackedEnumMemberDefinition { fn initial_position(&self) -> usize { - match self { + match &self { Self::Case(case) => case.initial_position(), Self::Method(method) => method.initial_position(), Self::Constant(constant) => constant.initial_position(), @@ -391,7 +391,7 @@ impl Node for BackedEnumMemberDefinition { } fn final_position(&self) -> usize { - match self { + match &self { Self::Case(case) => case.final_position(), Self::Method(method) => method.final_position(), Self::Constant(constant) => constant.final_position(), diff --git a/src/tree/definition/interface.rs b/src/tree/definition/interface.rs index bc7857b..2297ca6 100644 --- a/src/tree/definition/interface.rs +++ b/src/tree/definition/interface.rs @@ -149,7 +149,7 @@ impl Node for InterfaceDefinitionBody { impl Node for InterfaceDefinitionMember { fn initial_position(&self) -> usize { - match self { + match &self { Self::Constant(constant) => constant.initial_position(), Self::Constructor(constructor) => constructor.initial_position(), Self::Method(method) => method.initial_position(), @@ -157,7 +157,7 @@ impl Node for InterfaceDefinitionMember { } fn final_position(&self) -> usize { - match self { + match &self { Self::Constant(constant) => constant.final_position(), Self::Constructor(constructor) => constructor.final_position(), Self::Method(method) => method.final_position(), diff --git a/src/tree/definition/mod.rs b/src/tree/definition/mod.rs index 7a8ac77..005d4e3 100644 --- a/src/tree/definition/mod.rs +++ b/src/tree/definition/mod.rs @@ -65,7 +65,7 @@ impl Node for DefinitionTree { impl Node for Definition { fn initial_position(&self) -> usize { - match self { + match &self { Definition::Namespace(definition) => definition.initial_position(), Definition::Use(definition) => definition.initial_position(), Definition::TypeAlias(definition) => definition.initial_position(), @@ -78,7 +78,7 @@ impl Node for Definition { } fn final_position(&self) -> usize { - match self { + match &self { Definition::Namespace(definition) => definition.final_position(), Definition::Use(definition) => definition.final_position(), Definition::TypeAlias(definition) => definition.final_position(), diff --git a/src/tree/definition/modifier.rs b/src/tree/definition/modifier.rs index 519bea9..8eb55d1 100644 --- a/src/tree/definition/modifier.rs +++ b/src/tree/definition/modifier.rs @@ -53,7 +53,7 @@ impl Node for ModifierGroupDefinition { impl Node for ModifierDefinition { fn initial_position(&self) -> usize { - match self { + match &self { ModifierDefinition::Public(keyword) | ModifierDefinition::Protected(keyword) | ModifierDefinition::Private(keyword) @@ -65,7 +65,7 @@ impl Node for ModifierDefinition { } fn final_position(&self) -> usize { - match self { + match &self { ModifierDefinition::Public(keyword) | ModifierDefinition::Protected(keyword) | ModifierDefinition::Private(keyword) @@ -77,7 +77,7 @@ impl Node for ModifierDefinition { } fn children(&self) -> Vec<&dyn Node> { - match self { + match &self { ModifierDefinition::Public(keyword) | ModifierDefinition::Protected(keyword) | ModifierDefinition::Private(keyword) @@ -103,7 +103,7 @@ impl Node for ModifierDefinition { impl std::fmt::Display for ModifierDefinition { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { - match self { + match &self { ModifierDefinition::Public(keyword) | ModifierDefinition::Protected(keyword) | ModifierDefinition::Private(keyword) diff --git a/src/tree/definition/property.rs b/src/tree/definition/property.rs index d152765..317ffcc 100644 --- a/src/tree/definition/property.rs +++ b/src/tree/definition/property.rs @@ -34,7 +34,7 @@ pub enum PropertyEntryDefinition { impl PropertyEntryDefinition { pub fn variable(&self) -> &Variable { - match self { + match &self { PropertyEntryDefinition::Uninitialized { variable } => variable, PropertyEntryDefinition::Initialized { variable, .. } => variable, } @@ -79,21 +79,21 @@ impl Node for PropertyDefinition { impl Node for PropertyEntryDefinition { fn initial_position(&self) -> usize { - match self { + match &self { PropertyEntryDefinition::Uninitialized { variable } => variable.initial_position(), PropertyEntryDefinition::Initialized { variable, .. } => variable.initial_position(), } } fn final_position(&self) -> usize { - match self { + match &self { PropertyEntryDefinition::Uninitialized { variable } => variable.final_position(), PropertyEntryDefinition::Initialized { value, .. } => value.final_position(), } } fn children(&self) -> Vec<&dyn Node> { - match self { + match &self { PropertyEntryDefinition::Uninitialized { variable } => vec![variable], PropertyEntryDefinition::Initialized { variable, value, .. diff --git a/src/tree/definition/type.rs b/src/tree/definition/type.rs index 3004af0..1403cbc 100644 --- a/src/tree/definition/type.rs +++ b/src/tree/definition/type.rs @@ -105,7 +105,7 @@ impl TypeDefinition { } pub fn is_scalar(&self) -> bool { - match self { + match &self { TypeDefinition::Literal(literal) => !matches!(literal, Literal::Null(_)), | TypeDefinition::Boolean(_) | TypeDefinition::SignedInteger(_) @@ -144,7 +144,7 @@ impl Node for TypeAliasDefinition { impl Node for SignedIntegerTypeDefinition { fn initial_position(&self) -> usize { - match self { + match &self { SignedIntegerTypeDefinition::Default(keyword) | SignedIntegerTypeDefinition::I128(keyword) | SignedIntegerTypeDefinition::I64(keyword) @@ -155,7 +155,7 @@ impl Node for SignedIntegerTypeDefinition { } fn final_position(&self) -> usize { - match self { + match &self { SignedIntegerTypeDefinition::Default(keyword) | SignedIntegerTypeDefinition::I128(keyword) | SignedIntegerTypeDefinition::I64(keyword) @@ -166,7 +166,7 @@ impl Node for SignedIntegerTypeDefinition { } fn children(&self) -> Vec<&dyn Node> { - match self { + match &self { SignedIntegerTypeDefinition::Default(keyword) | SignedIntegerTypeDefinition::I128(keyword) | SignedIntegerTypeDefinition::I64(keyword) @@ -183,7 +183,7 @@ impl Node for SignedIntegerTypeDefinition { impl Node for UnsignedIntegerTypeDefinition { fn initial_position(&self) -> usize { - match self { + match &self { UnsignedIntegerTypeDefinition::Default(keyword) | UnsignedIntegerTypeDefinition::U32(keyword) | UnsignedIntegerTypeDefinition::U16(keyword) @@ -192,7 +192,7 @@ impl Node for UnsignedIntegerTypeDefinition { } fn final_position(&self) -> usize { - match self { + match &self { UnsignedIntegerTypeDefinition::Default(keyword) | UnsignedIntegerTypeDefinition::U32(keyword) | UnsignedIntegerTypeDefinition::U16(keyword) @@ -201,7 +201,7 @@ impl Node for UnsignedIntegerTypeDefinition { } fn children(&self) -> Vec<&dyn Node> { - match self { + match &self { UnsignedIntegerTypeDefinition::Default(keyword) | UnsignedIntegerTypeDefinition::U32(keyword) | UnsignedIntegerTypeDefinition::U16(keyword) @@ -216,7 +216,7 @@ impl Node for UnsignedIntegerTypeDefinition { impl Node for FloatingPointTypeDefinition { fn initial_position(&self) -> usize { - match self { + match &self { FloatingPointTypeDefinition::Default(keyword) | FloatingPointTypeDefinition::F64(keyword) | FloatingPointTypeDefinition::F32(keyword) => keyword.initial_position(), @@ -224,7 +224,7 @@ impl Node for FloatingPointTypeDefinition { } fn final_position(&self) -> usize { - match self { + match &self { FloatingPointTypeDefinition::Default(keyword) | FloatingPointTypeDefinition::F64(keyword) | FloatingPointTypeDefinition::F32(keyword) => keyword.final_position(), @@ -232,7 +232,7 @@ impl Node for FloatingPointTypeDefinition { } fn children(&self) -> Vec<&dyn Node> { - match self { + match &self { FloatingPointTypeDefinition::Default(keyword) | FloatingPointTypeDefinition::F64(keyword) | FloatingPointTypeDefinition::F32(keyword) => vec![keyword], diff --git a/src/tree/definition/use.rs b/src/tree/definition/use.rs index a975544..61f8934 100644 --- a/src/tree/definition/use.rs +++ b/src/tree/definition/use.rs @@ -41,7 +41,7 @@ pub struct UseDefinitionSymbolAlias { impl Node for UseDefinition { fn initial_position(&self) -> usize { - match self { + match &self { UseDefinition::Default { r#use, .. } | UseDefinition::Function { r#use, .. } | UseDefinition::Constant { r#use, .. } => r#use.initial_position(), @@ -49,7 +49,7 @@ impl Node for UseDefinition { } fn final_position(&self) -> usize { - match self { + match &self { UseDefinition::Default { semicolon, .. } | UseDefinition::Function { semicolon, .. } | UseDefinition::Constant { semicolon, .. } => semicolon + 1, @@ -57,7 +57,7 @@ impl Node for UseDefinition { } fn children(&self) -> Vec<&dyn Node> { - match self { + match &self { UseDefinition::Default { r#use, name, alias, .. } => { diff --git a/src/tree/expression/argument.rs b/src/tree/expression/argument.rs index 668899c..388d176 100644 --- a/src/tree/expression/argument.rs +++ b/src/tree/expression/argument.rs @@ -62,7 +62,7 @@ impl Node for ArgumentExpression { } fn initial_position(&self) -> usize { - match self { + match &self { ArgumentExpression::Value { value, .. } | ArgumentExpression::ReverseSpread { value, .. } => value.initial_position(), ArgumentExpression::Spread { ellipsis, .. } => *ellipsis, @@ -71,7 +71,7 @@ impl Node for ArgumentExpression { } fn final_position(&self) -> usize { - match self { + match &self { ArgumentExpression::Value { value, .. } | ArgumentExpression::Spread { value, .. } => { value.final_position() } @@ -81,7 +81,7 @@ impl Node for ArgumentExpression { } fn children(&self) -> Vec<&dyn Node> { - match self { + match &self { ArgumentExpression::Value { value, .. } | ArgumentExpression::Spread { value, .. } | ArgumentExpression::ReverseSpread { value, .. } => vec![value], @@ -90,7 +90,7 @@ impl Node for ArgumentExpression { } fn get_description(&self) -> String { - match self { + match &self { ArgumentExpression::Value { .. } => "value argument expression".to_string(), ArgumentExpression::Spread { .. } => "spread argument expression".to_string(), ArgumentExpression::ReverseSpread { .. } => { diff --git a/src/tree/expression/construct.rs b/src/tree/expression/construct.rs index 8f04c24..548186e 100644 --- a/src/tree/expression/construct.rs +++ b/src/tree/expression/construct.rs @@ -26,21 +26,21 @@ pub enum ExitConstructExpression { impl Node for ExitConstructExpression { fn comments(&self) -> Option<&CommentGroup> { - match self { + match &self { ExitConstructExpression::Exit { comments, .. } => Some(comments), ExitConstructExpression::ExitWith { comments, .. } => Some(comments), } } fn initial_position(&self) -> usize { - match self { + match &self { ExitConstructExpression::Exit { exit, .. } | ExitConstructExpression::ExitWith { exit, .. } => exit.initial_position(), } } fn final_position(&self) -> usize { - match self { + match &self { ExitConstructExpression::Exit { exit, .. } => exit.final_position(), ExitConstructExpression::ExitWith { right_parenthesis, .. @@ -49,7 +49,7 @@ impl Node for ExitConstructExpression { } fn children(&self) -> Vec<&dyn Node> { - match self { + match &self { ExitConstructExpression::Exit { exit, .. } => vec![exit], ExitConstructExpression::ExitWith { exit, value, .. } => { if let Some(value) = value { diff --git a/src/tree/expression/control_flow.rs b/src/tree/expression/control_flow.rs index eafebb3..2fc1e45 100644 --- a/src/tree/expression/control_flow.rs +++ b/src/tree/expression/control_flow.rs @@ -104,21 +104,21 @@ impl Node for MatchArmExpression { impl Node for MatchArmConditionExpression { fn initial_position(&self) -> usize { - match self { + match &self { Self::Expressions(expressions) => expressions.inner.first().unwrap().initial_position(), Self::Default(default) => default.initial_position(), } } fn final_position(&self) -> usize { - match self { + match &self { Self::Expressions(expressions) => expressions.inner.last().unwrap().final_position(), Self::Default(default) => default.final_position(), } } fn children(&self) -> Vec<&dyn Node> { - match self { + match &self { Self::Expressions(expressions) => expressions .inner .iter() diff --git a/src/tree/expression/literal.rs b/src/tree/expression/literal.rs index ebd519f..0274e0f 100644 --- a/src/tree/expression/literal.rs +++ b/src/tree/expression/literal.rs @@ -65,7 +65,7 @@ pub struct LiteralFalse { impl Node for Literal { fn comments(&self) -> Option<&CommentGroup> { - match self { + match &self { Literal::String(literal) => literal.comments(), Literal::Integer(literal) => literal.comments(), Literal::Float(literal) => literal.comments(), @@ -76,7 +76,7 @@ impl Node for Literal { } fn initial_position(&self) -> usize { - match self { + match &self { Literal::String(literal) => literal.initial_position(), Literal::Integer(literal) => literal.initial_position(), Literal::Float(literal) => literal.initial_position(), @@ -87,7 +87,7 @@ impl Node for Literal { } fn final_position(&self) -> usize { - match self { + match &self { Literal::String(literal) => literal.final_position(), Literal::Integer(literal) => literal.final_position(), Literal::Float(literal) => literal.final_position(), diff --git a/src/tree/expression/magic_constant.rs b/src/tree/expression/magic_constant.rs index 6d9fef8..2fd6930 100644 --- a/src/tree/expression/magic_constant.rs +++ b/src/tree/expression/magic_constant.rs @@ -19,7 +19,7 @@ pub enum MagicConstant { impl Node for MagicConstant { fn initial_position(&self) -> usize { - match self { + match &self { MagicConstant::Directory { position, .. } => *position, MagicConstant::File { position, .. } => *position, MagicConstant::Line { position, .. } => *position, @@ -31,7 +31,7 @@ impl Node for MagicConstant { } fn final_position(&self) -> usize { - match self { + match &self { MagicConstant::Directory { position, value } => position + value.len(), MagicConstant::File { position, value } => position + value.len(), MagicConstant::Line { position, value } => position + value.len(), @@ -47,7 +47,7 @@ impl Node for MagicConstant { } fn get_description(&self) -> String { - match self { + match &self { MagicConstant::Directory { .. } => "directory magic constant expression".to_string(), MagicConstant::File { .. } => "file magic constant expression".to_string(), MagicConstant::Line { .. } => "line magic constant expression".to_string(), diff --git a/src/tree/expression/mod.rs b/src/tree/expression/mod.rs index ed3389e..1ac7496 100644 --- a/src/tree/expression/mod.rs +++ b/src/tree/expression/mod.rs @@ -115,7 +115,7 @@ impl Expression { /// /// If `initilization` is true, the expression is allowed to contain a class initialization expression. pub fn is_constant(&self, initilization: bool) -> bool { - match self { + match &self { Expression::Literal(_) => true, Expression::Identifier(_) => true, Expression::MagicConstant(_) => true, @@ -251,7 +251,7 @@ impl Expression { /// Return true if the expression is writable pub fn is_writable(&self) -> bool { - match self { + match &self { Expression::Variable(_) | Expression::ArrayOperation(ArrayOperationExpression::Push { .. }) | Expression::ArrayOperation(ArrayOperationExpression::Access { .. }) @@ -268,7 +268,7 @@ impl Expression { /// Return true if the expression is readable pub fn is_readable(&self) -> bool { - match self { + match &self { Expression::AssignmentOperation(..) | Expression::ExitConstruct(..) | Expression::ExceptionOperation(ExceptionOperationExpression::Throw { .. }) @@ -291,7 +291,7 @@ impl Node for Expression { } fn initial_position(&self) -> usize { - match self { + match &self { Expression::Parenthesized(expression) => expression.initial_position(), Expression::ExitConstruct(expression) => expression.initial_position(), Expression::Literal(expression) => expression.initial_position(), @@ -325,7 +325,7 @@ impl Node for Expression { } fn final_position(&self) -> usize { - match self { + match &self { Expression::Parenthesized(expression) => expression.final_position(), Expression::ExitConstruct(expression) => expression.final_position(), Expression::Literal(expression) => expression.final_position(), @@ -359,7 +359,7 @@ impl Node for Expression { } fn children(&self) -> Vec<&dyn Node> { - match self { + match &self { Expression::Parenthesized(expression) => vec![expression], Expression::ExitConstruct(expression) => vec![expression], Expression::Literal(expression) => vec![expression], diff --git a/src/tree/expression/operator.rs b/src/tree/expression/operator.rs index 0bc8772..c1a7951 100644 --- a/src/tree/expression/operator.rs +++ b/src/tree/expression/operator.rs @@ -619,7 +619,7 @@ pub enum RangeOperationExpression { impl RangeOperationExpression { pub fn has_start(&self) -> bool { - match self { + match &self { RangeOperationExpression::Between { .. } => true, RangeOperationExpression::BetweenInclusive { .. } => true, RangeOperationExpression::To { .. } => false, diff --git a/src/tree/statement/loop.rs b/src/tree/statement/loop.rs index 8385b3a..23f242b 100644 --- a/src/tree/statement/loop.rs +++ b/src/tree/statement/loop.rs @@ -123,7 +123,7 @@ pub struct ContinueStatement { impl ForeachIteratorStatement { pub fn expression(&self) -> &Expression { - match self { + match &self { ForeachIteratorStatement::Value { expression, .. } => expression, ForeachIteratorStatement::ParenthesizedValue { expression, .. } => expression, ForeachIteratorStatement::KeyAndValue { expression, .. } => expression, @@ -132,7 +132,7 @@ impl ForeachIteratorStatement { } pub fn key(&self) -> Option<&Variable> { - match self { + match &self { ForeachIteratorStatement::Value { .. } => None, ForeachIteratorStatement::ParenthesizedValue { .. } => None, ForeachIteratorStatement::KeyAndValue { key, .. } => Some(key), @@ -141,7 +141,7 @@ impl ForeachIteratorStatement { } pub fn value(&self) -> &Variable { - match self { + match &self { ForeachIteratorStatement::Value { value, .. } => value, ForeachIteratorStatement::ParenthesizedValue { value, .. } => value, ForeachIteratorStatement::KeyAndValue { value, .. } => value, @@ -178,7 +178,7 @@ impl Node for ForeachIteratorStatement { } fn initial_position(&self) -> usize { - match self { + match &self { ForeachIteratorStatement::Value { expression, .. } | ForeachIteratorStatement::KeyAndValue { expression, .. } => { expression.initial_position() @@ -193,7 +193,7 @@ impl Node for ForeachIteratorStatement { } fn final_position(&self) -> usize { - match self { + match &self { ForeachIteratorStatement::Value { value, .. } | ForeachIteratorStatement::KeyAndValue { value, .. } => value.final_position(), ForeachIteratorStatement::ParenthesizedValue { @@ -206,7 +206,7 @@ impl Node for ForeachIteratorStatement { } fn children(&self) -> Vec<&dyn Node> { - match self { + match &self { ForeachIteratorStatement::Value { expression, r#as, @@ -273,7 +273,7 @@ impl Node for ForIteratorStatement { } fn initial_position(&self) -> usize { - match self { + match &self { ForIteratorStatement::Standalone { initializations, initializations_semicolon, @@ -292,7 +292,7 @@ impl Node for ForIteratorStatement { } fn final_position(&self) -> usize { - match self { + match &self { ForIteratorStatement::Standalone { conditions_semicolon, r#loop, diff --git a/src/tree/statement/try.rs b/src/tree/statement/try.rs index affed77..06a9b31 100644 --- a/src/tree/statement/try.rs +++ b/src/tree/statement/try.rs @@ -136,14 +136,14 @@ impl Node for TryCatchTypeStatement { } fn initial_position(&self) -> usize { - match self { + match &self { TryCatchTypeStatement::Identifier(identifier) => identifier.initial_position(), TryCatchTypeStatement::Union(identifiers) => identifiers[0].initial_position(), } } fn final_position(&self) -> usize { - match self { + match &self { TryCatchTypeStatement::Identifier(identifier) => identifier.final_position(), TryCatchTypeStatement::Union(identifiers) => { identifiers[identifiers.len() - 1].final_position() @@ -152,7 +152,7 @@ impl Node for TryCatchTypeStatement { } fn children(&self) -> Vec<&dyn Node> { - match self { + match &self { TryCatchTypeStatement::Identifier(identifier) => vec![identifier], TryCatchTypeStatement::Union(identifiers) => identifiers .iter() From debca638e9ba1842beb450a61cf81accc7b925e4 Mon Sep 17 00:00:00 2001 From: Kennedy Tedesco Date: Wed, 18 Jan 2023 21:35:13 -0300 Subject: [PATCH 2/2] chore: from `Name::Member` to `Self::Member` --- src/tree/definition/enum.rs | 16 +- src/tree/definition/mod.rs | 64 +- src/tree/definition/modifier.rs | 70 +- src/tree/definition/property.rs | 22 +- src/tree/definition/type.rs | 338 ++++---- src/tree/definition/use.rs | 24 +- src/tree/expression/argument.rs | 43 +- src/tree/expression/class.rs | 38 +- src/tree/expression/construct.rs | 15 +- src/tree/expression/magic_constant.rs | 42 +- src/tree/expression/mod.rs | 305 ++++---- src/tree/expression/operator.rs | 1043 +++++++++++-------------- src/tree/statement/loop.rs | 58 +- src/tree/statement/mod.rs | 104 +-- src/tree/statement/return.rs | 20 +- src/tree/statement/try.rs | 14 +- 16 files changed, 1016 insertions(+), 1200 deletions(-) diff --git a/src/tree/definition/enum.rs b/src/tree/definition/enum.rs index 94fff34..1751584 100644 --- a/src/tree/definition/enum.rs +++ b/src/tree/definition/enum.rs @@ -116,29 +116,29 @@ impl Node for EnumDefinition { fn initial_position(&self) -> usize { match &self { - EnumDefinition::Backed(definition) => definition.initial_position(), - EnumDefinition::Unit(definition) => definition.initial_position(), + Self::Backed(definition) => definition.initial_position(), + Self::Unit(definition) => definition.initial_position(), } } fn final_position(&self) -> usize { match &self { - EnumDefinition::Backed(definition) => definition.final_position(), - EnumDefinition::Unit(definition) => definition.final_position(), + Self::Backed(definition) => definition.final_position(), + Self::Unit(definition) => definition.final_position(), } } fn children(&self) -> Vec<&dyn Node> { match &self { - EnumDefinition::Backed(definition) => vec![definition], - EnumDefinition::Unit(definition) => vec![definition], + Self::Backed(definition) => vec![definition], + Self::Unit(definition) => vec![definition], } } fn get_description(&self) -> String { match &self { - EnumDefinition::Backed(definition) => definition.get_description(), - EnumDefinition::Unit(definition) => definition.get_description(), + Self::Backed(definition) => definition.get_description(), + Self::Unit(definition) => definition.get_description(), } } } diff --git a/src/tree/definition/mod.rs b/src/tree/definition/mod.rs index 005d4e3..1ff96ce 100644 --- a/src/tree/definition/mod.rs +++ b/src/tree/definition/mod.rs @@ -66,53 +66,53 @@ impl Node for DefinitionTree { impl Node for Definition { fn initial_position(&self) -> usize { match &self { - Definition::Namespace(definition) => definition.initial_position(), - Definition::Use(definition) => definition.initial_position(), - Definition::TypeAlias(definition) => definition.initial_position(), - Definition::Constant(definition) => definition.initial_position(), - Definition::Function(definition) => definition.initial_position(), - Definition::Interface(definition) => definition.initial_position(), - Definition::Enum(definition) => definition.initial_position(), - Definition::Class(definition) => definition.initial_position(), + Self::Namespace(definition) => definition.initial_position(), + Self::Use(definition) => definition.initial_position(), + Self::TypeAlias(definition) => definition.initial_position(), + Self::Constant(definition) => definition.initial_position(), + Self::Function(definition) => definition.initial_position(), + Self::Interface(definition) => definition.initial_position(), + Self::Enum(definition) => definition.initial_position(), + Self::Class(definition) => definition.initial_position(), } } fn final_position(&self) -> usize { match &self { - Definition::Namespace(definition) => definition.final_position(), - Definition::Use(definition) => definition.final_position(), - Definition::TypeAlias(definition) => definition.final_position(), - Definition::Constant(definition) => definition.final_position(), - Definition::Function(definition) => definition.final_position(), - Definition::Interface(definition) => definition.final_position(), - Definition::Enum(definition) => definition.final_position(), - Definition::Class(definition) => definition.final_position(), + Self::Namespace(definition) => definition.final_position(), + Self::Use(definition) => definition.final_position(), + Self::TypeAlias(definition) => definition.final_position(), + Self::Constant(definition) => definition.final_position(), + Self::Function(definition) => definition.final_position(), + Self::Interface(definition) => definition.final_position(), + Self::Enum(definition) => definition.final_position(), + Self::Class(definition) => definition.final_position(), } } fn children(&self) -> Vec<&dyn Node> { match &self { - Definition::Namespace(definition) => vec![definition.as_ref()], - Definition::Use(definition) => vec![definition.as_ref()], - Definition::TypeAlias(definition) => vec![definition.as_ref()], - Definition::Constant(definition) => vec![definition.as_ref()], - Definition::Function(definition) => vec![definition.as_ref()], - Definition::Interface(definition) => vec![definition.as_ref()], - Definition::Enum(definition) => vec![definition.as_ref()], - Definition::Class(definition) => vec![definition.as_ref()], + Self::Namespace(definition) => vec![definition.as_ref()], + Self::Use(definition) => vec![definition.as_ref()], + Self::TypeAlias(definition) => vec![definition.as_ref()], + Self::Constant(definition) => vec![definition.as_ref()], + Self::Function(definition) => vec![definition.as_ref()], + Self::Interface(definition) => vec![definition.as_ref()], + Self::Enum(definition) => vec![definition.as_ref()], + Self::Class(definition) => vec![definition.as_ref()], } } fn get_description(&self) -> String { match &self { - Definition::Namespace(definition) => definition.get_description(), - Definition::Use(definition) => definition.get_description(), - Definition::TypeAlias(definition) => definition.get_description(), - Definition::Constant(definition) => definition.get_description(), - Definition::Function(definition) => definition.get_description(), - Definition::Interface(definition) => definition.get_description(), - Definition::Enum(definition) => definition.get_description(), - Definition::Class(definition) => definition.get_description(), + Self::Namespace(definition) => definition.get_description(), + Self::Use(definition) => definition.get_description(), + Self::TypeAlias(definition) => definition.get_description(), + Self::Constant(definition) => definition.get_description(), + Self::Function(definition) => definition.get_description(), + Self::Interface(definition) => definition.get_description(), + Self::Enum(definition) => definition.get_description(), + Self::Class(definition) => definition.get_description(), } } } diff --git a/src/tree/definition/modifier.rs b/src/tree/definition/modifier.rs index 8eb55d1..e5150d3 100644 --- a/src/tree/definition/modifier.rs +++ b/src/tree/definition/modifier.rs @@ -54,49 +54,49 @@ impl Node for ModifierGroupDefinition { impl Node for ModifierDefinition { fn initial_position(&self) -> usize { match &self { - ModifierDefinition::Public(keyword) - | ModifierDefinition::Protected(keyword) - | ModifierDefinition::Private(keyword) - | ModifierDefinition::Readonly(keyword) - | ModifierDefinition::Static(keyword) - | ModifierDefinition::Abstract(keyword) - | ModifierDefinition::Final(keyword) => keyword.initial_position(), + Self::Public(keyword) + | Self::Protected(keyword) + | Self::Private(keyword) + | Self::Readonly(keyword) + | Self::Static(keyword) + | Self::Abstract(keyword) + | Self::Final(keyword) => keyword.initial_position(), } } fn final_position(&self) -> usize { match &self { - ModifierDefinition::Public(keyword) - | ModifierDefinition::Protected(keyword) - | ModifierDefinition::Private(keyword) - | ModifierDefinition::Readonly(keyword) - | ModifierDefinition::Static(keyword) - | ModifierDefinition::Abstract(keyword) - | ModifierDefinition::Final(keyword) => keyword.final_position(), + Self::Public(keyword) + | Self::Protected(keyword) + | Self::Private(keyword) + | Self::Readonly(keyword) + | Self::Static(keyword) + | Self::Abstract(keyword) + | Self::Final(keyword) => keyword.final_position(), } } fn children(&self) -> Vec<&dyn Node> { match &self { - ModifierDefinition::Public(keyword) - | ModifierDefinition::Protected(keyword) - | ModifierDefinition::Private(keyword) - | ModifierDefinition::Readonly(keyword) - | ModifierDefinition::Static(keyword) - | ModifierDefinition::Abstract(keyword) - | ModifierDefinition::Final(keyword) => vec![keyword as &dyn Node], + Self::Public(keyword) + | Self::Protected(keyword) + | Self::Private(keyword) + | Self::Readonly(keyword) + | Self::Static(keyword) + | Self::Abstract(keyword) + | Self::Final(keyword) => vec![keyword as &dyn Node], } } fn get_description(&self) -> String { match &self { - ModifierDefinition::Public(_keyword) => "public modifier definition".to_string(), - ModifierDefinition::Protected(_keyword) => "protected modifier definition".to_string(), - ModifierDefinition::Private(_keyword) => "private modifier definition".to_string(), - ModifierDefinition::Readonly(_keyword) => "readonly modifier definition".to_string(), - ModifierDefinition::Static(_keyword) => "static modifier definition".to_string(), - ModifierDefinition::Abstract(_keyword) => "abstract modifier definition".to_string(), - ModifierDefinition::Final(_keyword) => "final modifier definition".to_string(), + Self::Public(_keyword) => "public modifier definition".to_string(), + Self::Protected(_keyword) => "protected modifier definition".to_string(), + Self::Private(_keyword) => "private modifier definition".to_string(), + Self::Readonly(_keyword) => "readonly modifier definition".to_string(), + Self::Static(_keyword) => "static modifier definition".to_string(), + Self::Abstract(_keyword) => "abstract modifier definition".to_string(), + Self::Final(_keyword) => "final modifier definition".to_string(), } } } @@ -104,13 +104,13 @@ impl Node for ModifierDefinition { impl std::fmt::Display for ModifierDefinition { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { match &self { - ModifierDefinition::Public(keyword) - | ModifierDefinition::Protected(keyword) - | ModifierDefinition::Private(keyword) - | ModifierDefinition::Readonly(keyword) - | ModifierDefinition::Static(keyword) - | ModifierDefinition::Abstract(keyword) - | ModifierDefinition::Final(keyword) => write!(f, "{}", keyword.value), + Self::Public(keyword) + | Self::Protected(keyword) + | Self::Private(keyword) + | Self::Readonly(keyword) + | Self::Static(keyword) + | Self::Abstract(keyword) + | Self::Final(keyword) => write!(f, "{}", keyword.value), } } } diff --git a/src/tree/definition/property.rs b/src/tree/definition/property.rs index 317ffcc..5930b50 100644 --- a/src/tree/definition/property.rs +++ b/src/tree/definition/property.rs @@ -35,8 +35,8 @@ pub enum PropertyEntryDefinition { impl PropertyEntryDefinition { pub fn variable(&self) -> &Variable { match &self { - PropertyEntryDefinition::Uninitialized { variable } => variable, - PropertyEntryDefinition::Initialized { variable, .. } => variable, + Self::Uninitialized { variable } => variable, + Self::Initialized { variable, .. } => variable, } } } @@ -80,22 +80,22 @@ impl Node for PropertyDefinition { impl Node for PropertyEntryDefinition { fn initial_position(&self) -> usize { match &self { - PropertyEntryDefinition::Uninitialized { variable } => variable.initial_position(), - PropertyEntryDefinition::Initialized { variable, .. } => variable.initial_position(), + Self::Uninitialized { variable } => variable.initial_position(), + Self::Initialized { variable, .. } => variable.initial_position(), } } fn final_position(&self) -> usize { match &self { - PropertyEntryDefinition::Uninitialized { variable } => variable.final_position(), - PropertyEntryDefinition::Initialized { value, .. } => value.final_position(), + Self::Uninitialized { variable } => variable.final_position(), + Self::Initialized { value, .. } => value.final_position(), } } fn children(&self) -> Vec<&dyn Node> { match &self { - PropertyEntryDefinition::Uninitialized { variable } => vec![variable], - PropertyEntryDefinition::Initialized { + Self::Uninitialized { variable } => vec![variable], + Self::Initialized { variable, value, .. } => vec![variable, value], } @@ -103,10 +103,8 @@ impl Node for PropertyEntryDefinition { fn get_description(&self) -> String { match &self { - PropertyEntryDefinition::Uninitialized { .. } => { - "uninitialized property entry".to_string() - } - PropertyEntryDefinition::Initialized { .. } => "initialized property entry".to_string(), + Self::Uninitialized { .. } => "uninitialized property entry".to_string(), + Self::Initialized { .. } => "initialized property entry".to_string(), } } } diff --git a/src/tree/definition/type.rs b/src/tree/definition/type.rs index 1403cbc..677af04 100644 --- a/src/tree/definition/type.rs +++ b/src/tree/definition/type.rs @@ -87,40 +87,40 @@ impl TypeDefinition { pub fn is_standalone(&self) -> bool { matches!( self, - TypeDefinition::Mixed(_) - | TypeDefinition::Never(_) - | TypeDefinition::Void(_) - | TypeDefinition::Nullable(_, _) - | TypeDefinition::NonNull(_) - | TypeDefinition::Resource(_) + Self::Mixed(_) + | Self::Never(_) + | Self::Void(_) + | Self::Nullable(_, _) + | Self::NonNull(_) + | Self::Resource(_) ) } pub fn is_nullable(&self) -> bool { - matches!(self, TypeDefinition::Nullable(_, _)) + matches!(self, Self::Nullable(_, _)) } pub fn is_bottom(&self) -> bool { - matches!(self, TypeDefinition::Never(_) | TypeDefinition::Void(_)) + matches!(self, Self::Never(_) | Self::Void(_)) } pub fn is_scalar(&self) -> bool { match &self { - TypeDefinition::Literal(literal) => !matches!(literal, Literal::Null(_)), - | TypeDefinition::Boolean(_) - | TypeDefinition::SignedInteger(_) - | TypeDefinition::UnsignedInteger(_) - | TypeDefinition::FloatingPoint(_) - | TypeDefinition::String(_) + Self::Literal(literal) => !matches!(literal, Literal::Null(_)), + | Self::Boolean(_) + | Self::SignedInteger(_) + | Self::UnsignedInteger(_) + | Self::FloatingPoint(_) + | Self::String(_) // class, and interface are represented as strings at runtime, so they are considered scalars - | TypeDefinition::Class(_, _) - | TypeDefinition::Interface(_, _) => true, + | Self::Class(_, _) + | Self::Interface(_, _) => true, _ => false, } } pub fn is_literal(&self) -> bool { - matches!(self, TypeDefinition::Literal(_)) + matches!(self, Self::Literal(_)) } } @@ -145,34 +145,34 @@ impl Node for TypeAliasDefinition { impl Node for SignedIntegerTypeDefinition { fn initial_position(&self) -> usize { match &self { - SignedIntegerTypeDefinition::Default(keyword) - | SignedIntegerTypeDefinition::I128(keyword) - | SignedIntegerTypeDefinition::I64(keyword) - | SignedIntegerTypeDefinition::I32(keyword) - | SignedIntegerTypeDefinition::I16(keyword) - | SignedIntegerTypeDefinition::I8(keyword) => keyword.initial_position(), + Self::Default(keyword) + | Self::I128(keyword) + | Self::I64(keyword) + | Self::I32(keyword) + | Self::I16(keyword) + | Self::I8(keyword) => keyword.initial_position(), } } fn final_position(&self) -> usize { match &self { - SignedIntegerTypeDefinition::Default(keyword) - | SignedIntegerTypeDefinition::I128(keyword) - | SignedIntegerTypeDefinition::I64(keyword) - | SignedIntegerTypeDefinition::I32(keyword) - | SignedIntegerTypeDefinition::I16(keyword) - | SignedIntegerTypeDefinition::I8(keyword) => keyword.final_position(), + Self::Default(keyword) + | Self::I128(keyword) + | Self::I64(keyword) + | Self::I32(keyword) + | Self::I16(keyword) + | Self::I8(keyword) => keyword.final_position(), } } fn children(&self) -> Vec<&dyn Node> { match &self { - SignedIntegerTypeDefinition::Default(keyword) - | SignedIntegerTypeDefinition::I128(keyword) - | SignedIntegerTypeDefinition::I64(keyword) - | SignedIntegerTypeDefinition::I32(keyword) - | SignedIntegerTypeDefinition::I16(keyword) - | SignedIntegerTypeDefinition::I8(keyword) => vec![keyword], + Self::Default(keyword) + | Self::I128(keyword) + | Self::I64(keyword) + | Self::I32(keyword) + | Self::I16(keyword) + | Self::I8(keyword) => vec![keyword], } } @@ -184,28 +184,28 @@ impl Node for SignedIntegerTypeDefinition { impl Node for UnsignedIntegerTypeDefinition { fn initial_position(&self) -> usize { match &self { - UnsignedIntegerTypeDefinition::Default(keyword) - | UnsignedIntegerTypeDefinition::U32(keyword) - | UnsignedIntegerTypeDefinition::U16(keyword) - | UnsignedIntegerTypeDefinition::U8(keyword) => keyword.initial_position(), + Self::Default(keyword) + | Self::U32(keyword) + | Self::U16(keyword) + | Self::U8(keyword) => keyword.initial_position(), } } fn final_position(&self) -> usize { match &self { - UnsignedIntegerTypeDefinition::Default(keyword) - | UnsignedIntegerTypeDefinition::U32(keyword) - | UnsignedIntegerTypeDefinition::U16(keyword) - | UnsignedIntegerTypeDefinition::U8(keyword) => keyword.final_position(), + Self::Default(keyword) + | Self::U32(keyword) + | Self::U16(keyword) + | Self::U8(keyword) => keyword.final_position(), } } fn children(&self) -> Vec<&dyn Node> { match &self { - UnsignedIntegerTypeDefinition::Default(keyword) - | UnsignedIntegerTypeDefinition::U32(keyword) - | UnsignedIntegerTypeDefinition::U16(keyword) - | UnsignedIntegerTypeDefinition::U8(keyword) => vec![keyword], + Self::Default(keyword) + | Self::U32(keyword) + | Self::U16(keyword) + | Self::U8(keyword) => vec![keyword], } } @@ -217,25 +217,23 @@ impl Node for UnsignedIntegerTypeDefinition { impl Node for FloatingPointTypeDefinition { fn initial_position(&self) -> usize { match &self { - FloatingPointTypeDefinition::Default(keyword) - | FloatingPointTypeDefinition::F64(keyword) - | FloatingPointTypeDefinition::F32(keyword) => keyword.initial_position(), + Self::Default(keyword) | Self::F64(keyword) | Self::F32(keyword) => { + keyword.initial_position() + } } } fn final_position(&self) -> usize { match &self { - FloatingPointTypeDefinition::Default(keyword) - | FloatingPointTypeDefinition::F64(keyword) - | FloatingPointTypeDefinition::F32(keyword) => keyword.final_position(), + Self::Default(keyword) | Self::F64(keyword) | Self::F32(keyword) => { + keyword.final_position() + } } } fn children(&self) -> Vec<&dyn Node> { match &self { - FloatingPointTypeDefinition::Default(keyword) - | FloatingPointTypeDefinition::F64(keyword) - | FloatingPointTypeDefinition::F32(keyword) => vec![keyword], + Self::Default(keyword) | Self::F64(keyword) | Self::F32(keyword) => vec![keyword], } } @@ -247,32 +245,32 @@ impl Node for FloatingPointTypeDefinition { impl Node for TypeDefinition { fn initial_position(&self) -> usize { match &self { - TypeDefinition::Identifier(inner) => inner.initial_position(), - TypeDefinition::Union(inner) => inner[0].initial_position(), - TypeDefinition::Intersection(inner) => inner[0].initial_position(), - TypeDefinition::Literal(literal) => literal.initial_position(), - TypeDefinition::Nullable(position, _) => *position, - TypeDefinition::Void(keyword) - | TypeDefinition::Never(keyword) - | TypeDefinition::Boolean(keyword) - | TypeDefinition::String(keyword) - | TypeDefinition::Dict(keyword, _) - | TypeDefinition::Vec(keyword, _) - | TypeDefinition::Object(keyword) - | TypeDefinition::Mixed(keyword) - | TypeDefinition::NonNull(keyword) - | TypeDefinition::Resource(keyword) - | TypeDefinition::Class(keyword, _) - | TypeDefinition::Interface(keyword, _) - | TypeDefinition::Iterable(keyword, _) => keyword.initial_position(), - TypeDefinition::SignedInteger(signed) => signed.initial_position(), - TypeDefinition::UnsignedInteger(unsigned) => unsigned.initial_position(), - TypeDefinition::FloatingPoint(floating) => floating.initial_position(), - TypeDefinition::Tuple { + Self::Identifier(inner) => inner.initial_position(), + Self::Union(inner) => inner[0].initial_position(), + Self::Intersection(inner) => inner[0].initial_position(), + Self::Literal(literal) => literal.initial_position(), + Self::Nullable(position, _) => *position, + Self::Void(keyword) + | Self::Never(keyword) + | Self::Boolean(keyword) + | Self::String(keyword) + | Self::Dict(keyword, _) + | Self::Vec(keyword, _) + | Self::Object(keyword) + | Self::Mixed(keyword) + | Self::NonNull(keyword) + | Self::Resource(keyword) + | Self::Class(keyword, _) + | Self::Interface(keyword, _) + | Self::Iterable(keyword, _) => keyword.initial_position(), + Self::SignedInteger(signed) => signed.initial_position(), + Self::UnsignedInteger(unsigned) => unsigned.initial_position(), + Self::FloatingPoint(floating) => floating.initial_position(), + Self::Tuple { left_parenthesis: position, .. } - | TypeDefinition::Parenthesized { + | Self::Parenthesized { left_parenthesis: position, .. } => *position, @@ -281,31 +279,31 @@ impl Node for TypeDefinition { fn final_position(&self) -> usize { match &self { - TypeDefinition::Identifier(inner) => inner.final_position(), - TypeDefinition::Nullable(_, inner) => inner.final_position(), - TypeDefinition::Dict(_, template) - | TypeDefinition::Vec(_, template) - | TypeDefinition::Class(_, template) - | TypeDefinition::Interface(_, template) - | TypeDefinition::Iterable(_, template) => template.final_position(), - TypeDefinition::Union(inner) => inner[inner.len() - 1].final_position(), - TypeDefinition::Intersection(inner) => inner[inner.len() - 1].final_position(), - TypeDefinition::Literal(literal) => literal.final_position(), - TypeDefinition::Void(keyword) - | TypeDefinition::Never(keyword) - | TypeDefinition::Boolean(keyword) - | TypeDefinition::String(keyword) - | TypeDefinition::Object(keyword) - | TypeDefinition::Mixed(keyword) - | TypeDefinition::NonNull(keyword) - | TypeDefinition::Resource(keyword) => keyword.final_position(), - TypeDefinition::SignedInteger(signed) => signed.final_position(), - TypeDefinition::UnsignedInteger(unsigned) => unsigned.final_position(), - TypeDefinition::FloatingPoint(floating) => floating.final_position(), - TypeDefinition::Parenthesized { + Self::Identifier(inner) => inner.final_position(), + Self::Nullable(_, inner) => inner.final_position(), + Self::Dict(_, template) + | Self::Vec(_, template) + | Self::Class(_, template) + | Self::Interface(_, template) + | Self::Iterable(_, template) => template.final_position(), + Self::Union(inner) => inner[inner.len() - 1].final_position(), + Self::Intersection(inner) => inner[inner.len() - 1].final_position(), + Self::Literal(literal) => literal.final_position(), + Self::Void(keyword) + | Self::Never(keyword) + | Self::Boolean(keyword) + | Self::String(keyword) + | Self::Object(keyword) + | Self::Mixed(keyword) + | Self::NonNull(keyword) + | Self::Resource(keyword) => keyword.final_position(), + Self::SignedInteger(signed) => signed.final_position(), + Self::UnsignedInteger(unsigned) => unsigned.final_position(), + Self::FloatingPoint(floating) => floating.final_position(), + Self::Parenthesized { right_parenthesis, .. } - | TypeDefinition::Tuple { + | Self::Tuple { right_parenthesis, .. } => right_parenthesis + 1, } @@ -313,36 +311,36 @@ impl Node for TypeDefinition { fn children(&self) -> Vec<&dyn Node> { match &self { - TypeDefinition::Identifier(inner) => vec![inner], - TypeDefinition::Nullable(_, inner) => vec![inner.as_ref()], - TypeDefinition::Union(inner) | TypeDefinition::Intersection(inner) => { + Self::Identifier(inner) => vec![inner], + Self::Nullable(_, inner) => vec![inner.as_ref()], + Self::Union(inner) | Self::Intersection(inner) => { inner.iter().map(|t| t as &dyn Node).collect() } - TypeDefinition::Void(keyword) - | TypeDefinition::Object(keyword) - | TypeDefinition::NonNull(keyword) - | TypeDefinition::Mixed(keyword) - | TypeDefinition::Resource(keyword) - | TypeDefinition::Never(keyword) - | TypeDefinition::Boolean(keyword) - | TypeDefinition::String(keyword) => vec![keyword], - TypeDefinition::Literal(literal) => vec![literal], - TypeDefinition::SignedInteger(signed) => vec![signed], - TypeDefinition::UnsignedInteger(unsigned) => vec![unsigned], - TypeDefinition::FloatingPoint(floating) => vec![floating], - TypeDefinition::Class(keyword, template) - | TypeDefinition::Interface(keyword, template) - | TypeDefinition::Iterable(keyword, template) - | TypeDefinition::Dict(keyword, template) - | TypeDefinition::Vec(keyword, template) => vec![keyword, template], - TypeDefinition::Tuple { + Self::Void(keyword) + | Self::Object(keyword) + | Self::NonNull(keyword) + | Self::Mixed(keyword) + | Self::Resource(keyword) + | Self::Never(keyword) + | Self::Boolean(keyword) + | Self::String(keyword) => vec![keyword], + Self::Literal(literal) => vec![literal], + Self::SignedInteger(signed) => vec![signed], + Self::UnsignedInteger(unsigned) => vec![unsigned], + Self::FloatingPoint(floating) => vec![floating], + Self::Class(keyword, template) + | Self::Interface(keyword, template) + | Self::Iterable(keyword, template) + | Self::Dict(keyword, template) + | Self::Vec(keyword, template) => vec![keyword, template], + Self::Tuple { type_definitions, .. } => type_definitions .inner .iter() .map(|t| t as &dyn Node) .collect::>(), - TypeDefinition::Parenthesized { + Self::Parenthesized { type_definition, .. } => vec![type_definition.as_ref()], } @@ -351,29 +349,29 @@ impl Node for TypeDefinition { fn get_description(&self) -> String { match &self { // match &self and print all the variants: - TypeDefinition::Identifier(_) => "identifier type definition".to_string(), - TypeDefinition::Union(_) => "union type definition".to_string(), - TypeDefinition::Intersection(_) => "intersection type definition".to_string(), - TypeDefinition::Literal(literal) => literal.get_description(), - TypeDefinition::Nullable(_, _) => "nullable type definition".to_string(), - TypeDefinition::Void(_) => "void type definition".to_string(), - TypeDefinition::Never(_) => "never type definition".to_string(), - TypeDefinition::Boolean(_) => "boolean type definition".to_string(), - TypeDefinition::String(_) => "string type definition".to_string(), - TypeDefinition::Dict(_, _) => "dict type definition".to_string(), - TypeDefinition::Vec(_, _) => "vec type definition".to_string(), - TypeDefinition::Object(_) => "object type definition".to_string(), - TypeDefinition::Mixed(_) => "mixed type definition".to_string(), - TypeDefinition::NonNull(_) => "non-null type definition".to_string(), - TypeDefinition::Resource(_) => "resource type definition".to_string(), - TypeDefinition::Class(_, _) => "class type definition".to_string(), - TypeDefinition::Interface(_, _) => "interface type definition".to_string(), - TypeDefinition::Iterable(_, _) => "iterable type definition".to_string(), - TypeDefinition::SignedInteger(signed) => signed.get_description(), - TypeDefinition::UnsignedInteger(unsigned) => unsigned.get_description(), - TypeDefinition::FloatingPoint(floating) => floating.get_description(), - TypeDefinition::Tuple { .. } => "tuple type definition".to_string(), - TypeDefinition::Parenthesized { .. } => "parenthesized type definition".to_string(), + Self::Identifier(_) => "identifier type definition".to_string(), + Self::Union(_) => "union type definition".to_string(), + Self::Intersection(_) => "intersection type definition".to_string(), + Self::Literal(literal) => literal.get_description(), + Self::Nullable(_, _) => "nullable type definition".to_string(), + Self::Void(_) => "void type definition".to_string(), + Self::Never(_) => "never type definition".to_string(), + Self::Boolean(_) => "boolean type definition".to_string(), + Self::String(_) => "string type definition".to_string(), + Self::Dict(_, _) => "dict type definition".to_string(), + Self::Vec(_, _) => "vec type definition".to_string(), + Self::Object(_) => "object type definition".to_string(), + Self::Mixed(_) => "mixed type definition".to_string(), + Self::NonNull(_) => "non-null type definition".to_string(), + Self::Resource(_) => "resource type definition".to_string(), + Self::Class(_, _) => "class type definition".to_string(), + Self::Interface(_, _) => "interface type definition".to_string(), + Self::Iterable(_, _) => "iterable type definition".to_string(), + Self::SignedInteger(signed) => signed.get_description(), + Self::UnsignedInteger(unsigned) => unsigned.get_description(), + Self::FloatingPoint(floating) => floating.get_description(), + Self::Tuple { .. } => "tuple type definition".to_string(), + Self::Parenthesized { .. } => "parenthesized type definition".to_string(), } } } @@ -381,9 +379,9 @@ impl Node for TypeDefinition { impl std::fmt::Display for TypeDefinition { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { match &self { - TypeDefinition::Identifier(inner) => write!(f, "{}", inner), - TypeDefinition::Nullable(_, inner) => write!(f, "?{}", inner), - TypeDefinition::Union(inner) => write!( + Self::Identifier(inner) => write!(f, "{}", inner), + Self::Nullable(_, inner) => write!(f, "?{}", inner), + Self::Union(inner) => write!( f, "{}", inner @@ -392,7 +390,7 @@ impl std::fmt::Display for TypeDefinition { .collect::>() .join("|") ), - TypeDefinition::Intersection(inner) => write!( + Self::Intersection(inner) => write!( f, "{}", inner @@ -401,10 +399,10 @@ impl std::fmt::Display for TypeDefinition { .collect::>() .join("&") ), - TypeDefinition::Void(_) => write!(f, "void"), - TypeDefinition::Never(_) => write!(f, "never"), - TypeDefinition::Boolean(_) => write!(f, "bool"), - TypeDefinition::Literal(literal) => match literal { + Self::Void(_) => write!(f, "void"), + Self::Never(_) => write!(f, "never"), + Self::Boolean(_) => write!(f, "bool"), + Self::Literal(literal) => match literal { Literal::Null(_) => write!(f, "null"), Literal::False(_) => write!(f, "false"), Literal::True(_) => write!(f, "true"), @@ -412,7 +410,7 @@ impl std::fmt::Display for TypeDefinition { Literal::Float(inner) => write!(f, "{}", inner.value), Literal::String(inner) => write!(f, "{}", inner.value), }, - TypeDefinition::SignedInteger(signed) => match signed { + Self::SignedInteger(signed) => match signed { SignedIntegerTypeDefinition::Default(_) => write!(f, "int"), SignedIntegerTypeDefinition::I128(_) => write!(f, "i128"), SignedIntegerTypeDefinition::I64(_) => write!(f, "i64"), @@ -420,28 +418,28 @@ impl std::fmt::Display for TypeDefinition { SignedIntegerTypeDefinition::I16(_) => write!(f, "i16"), SignedIntegerTypeDefinition::I8(_) => write!(f, "i8"), }, - TypeDefinition::UnsignedInteger(unsigned) => match unsigned { + Self::UnsignedInteger(unsigned) => match unsigned { UnsignedIntegerTypeDefinition::Default(_) => write!(f, "uint"), UnsignedIntegerTypeDefinition::U32(_) => write!(f, "u32"), UnsignedIntegerTypeDefinition::U16(_) => write!(f, "u16"), UnsignedIntegerTypeDefinition::U8(_) => write!(f, "u8"), }, - TypeDefinition::FloatingPoint(floating) => match floating { + Self::FloatingPoint(floating) => match floating { FloatingPointTypeDefinition::Default(_) => write!(f, "float"), FloatingPointTypeDefinition::F64(_) => write!(f, "f64"), FloatingPointTypeDefinition::F32(_) => write!(f, "f32"), }, - TypeDefinition::String(_) => write!(f, "string"), - TypeDefinition::Dict(_, template) => write!(f, "dict{}", template), - TypeDefinition::Vec(_, template) => write!(f, "vec{}", template), - TypeDefinition::Iterable(_, template) => write!(f, "iterable{}", template), - TypeDefinition::Class(_, template) => write!(f, "class{}", template), - TypeDefinition::Interface(_, template) => write!(f, "interface{}", template), - TypeDefinition::Object(_) => write!(f, "object"), - TypeDefinition::Mixed(_) => write!(f, "mixed"), - TypeDefinition::NonNull(_) => write!(f, "nonnull"), - TypeDefinition::Resource(_) => write!(f, "resource"), - TypeDefinition::Tuple { + Self::String(_) => write!(f, "string"), + Self::Dict(_, template) => write!(f, "dict{}", template), + Self::Vec(_, template) => write!(f, "vec{}", template), + Self::Iterable(_, template) => write!(f, "iterable{}", template), + Self::Class(_, template) => write!(f, "class{}", template), + Self::Interface(_, template) => write!(f, "interface{}", template), + Self::Object(_) => write!(f, "object"), + Self::Mixed(_) => write!(f, "mixed"), + Self::NonNull(_) => write!(f, "nonnull"), + Self::Resource(_) => write!(f, "resource"), + Self::Tuple { type_definitions, .. } => write!( f, @@ -453,7 +451,7 @@ impl std::fmt::Display for TypeDefinition { .collect::>() .join(", ") ), - TypeDefinition::Parenthesized { + Self::Parenthesized { type_definition, .. } => { write!(f, "({})", type_definition) diff --git a/src/tree/definition/use.rs b/src/tree/definition/use.rs index 61f8934..1ab0c73 100644 --- a/src/tree/definition/use.rs +++ b/src/tree/definition/use.rs @@ -42,23 +42,23 @@ pub struct UseDefinitionSymbolAlias { impl Node for UseDefinition { fn initial_position(&self) -> usize { match &self { - UseDefinition::Default { r#use, .. } - | UseDefinition::Function { r#use, .. } - | UseDefinition::Constant { r#use, .. } => r#use.initial_position(), + Self::Default { r#use, .. } + | Self::Function { r#use, .. } + | Self::Constant { r#use, .. } => r#use.initial_position(), } } fn final_position(&self) -> usize { match &self { - UseDefinition::Default { semicolon, .. } - | UseDefinition::Function { semicolon, .. } - | UseDefinition::Constant { semicolon, .. } => semicolon + 1, + Self::Default { semicolon, .. } + | Self::Function { semicolon, .. } + | Self::Constant { semicolon, .. } => semicolon + 1, } } fn children(&self) -> Vec<&dyn Node> { match &self { - UseDefinition::Default { + Self::Default { r#use, name, alias, .. } => { let mut children: Vec<&dyn Node> = vec![r#use, name]; @@ -69,14 +69,14 @@ impl Node for UseDefinition { children } - UseDefinition::Function { + Self::Function { r#use, function: r#type, name, alias, .. } - | UseDefinition::Constant { + | Self::Constant { r#use, r#const: r#type, name, @@ -96,9 +96,9 @@ impl Node for UseDefinition { fn get_description(&self) -> String { match &self { - UseDefinition::Default { .. } => "use definition".to_string(), - UseDefinition::Function { .. } => "use function definition".to_string(), - UseDefinition::Constant { .. } => "use constant definition".to_string(), + Self::Default { .. } => "use definition".to_string(), + Self::Function { .. } => "use function definition".to_string(), + Self::Constant { .. } => "use constant definition".to_string(), } } } diff --git a/src/tree/expression/argument.rs b/src/tree/expression/argument.rs index 388d176..a8bf272 100644 --- a/src/tree/expression/argument.rs +++ b/src/tree/expression/argument.rs @@ -54,49 +54,46 @@ pub struct ArgumentPlaceholderExpression { impl Node for ArgumentExpression { fn comments(&self) -> Option<&CommentGroup> { match &self { - ArgumentExpression::Value { comments, .. } - | ArgumentExpression::Spread { comments, .. } - | ArgumentExpression::ReverseSpread { comments, .. } - | ArgumentExpression::Named { comments, .. } => Some(comments), + Self::Value { comments, .. } + | Self::Spread { comments, .. } + | Self::ReverseSpread { comments, .. } + | Self::Named { comments, .. } => Some(comments), } } fn initial_position(&self) -> usize { match &self { - ArgumentExpression::Value { value, .. } - | ArgumentExpression::ReverseSpread { value, .. } => value.initial_position(), - ArgumentExpression::Spread { ellipsis, .. } => *ellipsis, - ArgumentExpression::Named { name, .. } => name.initial_position(), + Self::Value { value, .. } | Self::ReverseSpread { value, .. } => { + value.initial_position() + } + Self::Spread { ellipsis, .. } => *ellipsis, + Self::Named { name, .. } => name.initial_position(), } } fn final_position(&self) -> usize { match &self { - ArgumentExpression::Value { value, .. } | ArgumentExpression::Spread { value, .. } => { - value.final_position() - } - ArgumentExpression::ReverseSpread { ellipsis, .. } => *ellipsis, - ArgumentExpression::Named { value, .. } => value.final_position(), + Self::Value { value, .. } | Self::Spread { value, .. } => value.final_position(), + Self::ReverseSpread { ellipsis, .. } => *ellipsis, + Self::Named { value, .. } => value.final_position(), } } fn children(&self) -> Vec<&dyn Node> { match &self { - ArgumentExpression::Value { value, .. } - | ArgumentExpression::Spread { value, .. } - | ArgumentExpression::ReverseSpread { value, .. } => vec![value], - ArgumentExpression::Named { name, value, .. } => vec![name, value], + Self::Value { value, .. } + | Self::Spread { value, .. } + | Self::ReverseSpread { value, .. } => vec![value], + Self::Named { name, value, .. } => vec![name, value], } } fn get_description(&self) -> String { match &self { - ArgumentExpression::Value { .. } => "value argument expression".to_string(), - ArgumentExpression::Spread { .. } => "spread argument expression".to_string(), - ArgumentExpression::ReverseSpread { .. } => { - "reverse spread argument expression".to_string() - } - ArgumentExpression::Named { .. } => "named argument expression".to_string(), + Self::Value { .. } => "value argument expression".to_string(), + Self::Spread { .. } => "spread argument expression".to_string(), + Self::ReverseSpread { .. } => "reverse spread argument expression".to_string(), + Self::Named { .. } => "named argument expression".to_string(), } } } diff --git a/src/tree/expression/class.rs b/src/tree/expression/class.rs index 235da8c..8d192e3 100644 --- a/src/tree/expression/class.rs +++ b/src/tree/expression/class.rs @@ -90,43 +90,37 @@ impl Node for AnonymousClassExpressionMember { fn initial_position(&self) -> usize { match &self { - AnonymousClassExpressionMember::Constant(constant) => constant.initial_position(), - AnonymousClassExpressionMember::Property(property) => property.initial_position(), - AnonymousClassExpressionMember::ConcreteMethod(method) => method.initial_position(), - AnonymousClassExpressionMember::ConcreteConstructor(constructor) => { - constructor.initial_position() - } + Self::Constant(constant) => constant.initial_position(), + Self::Property(property) => property.initial_position(), + Self::ConcreteMethod(method) => method.initial_position(), + Self::ConcreteConstructor(constructor) => constructor.initial_position(), } } fn final_position(&self) -> usize { match &self { - AnonymousClassExpressionMember::Constant(constant) => constant.final_position(), - AnonymousClassExpressionMember::Property(property) => property.final_position(), - AnonymousClassExpressionMember::ConcreteMethod(method) => method.final_position(), - AnonymousClassExpressionMember::ConcreteConstructor(constructor) => { - constructor.final_position() - } + Self::Constant(constant) => constant.final_position(), + Self::Property(property) => property.final_position(), + Self::ConcreteMethod(method) => method.final_position(), + Self::ConcreteConstructor(constructor) => constructor.final_position(), } } fn children(&self) -> Vec<&dyn Node> { match &self { - AnonymousClassExpressionMember::Constant(constant) => vec![constant], - AnonymousClassExpressionMember::Property(property) => vec![property], - AnonymousClassExpressionMember::ConcreteMethod(method) => vec![method], - AnonymousClassExpressionMember::ConcreteConstructor(constructor) => vec![constructor], + Self::Constant(constant) => vec![constant], + Self::Property(property) => vec![property], + Self::ConcreteMethod(method) => vec![method], + Self::ConcreteConstructor(constructor) => vec![constructor], } } fn get_description(&self) -> String { match &self { - AnonymousClassExpressionMember::Constant(constant) => constant.get_description(), - AnonymousClassExpressionMember::Property(property) => property.get_description(), - AnonymousClassExpressionMember::ConcreteMethod(method) => method.get_description(), - AnonymousClassExpressionMember::ConcreteConstructor(constructor) => { - constructor.get_description() - } + Self::Constant(constant) => constant.get_description(), + Self::Property(property) => property.get_description(), + Self::ConcreteMethod(method) => method.get_description(), + Self::ConcreteConstructor(constructor) => constructor.get_description(), } } } diff --git a/src/tree/expression/construct.rs b/src/tree/expression/construct.rs index 548186e..0a176ed 100644 --- a/src/tree/expression/construct.rs +++ b/src/tree/expression/construct.rs @@ -27,22 +27,21 @@ pub enum ExitConstructExpression { impl Node for ExitConstructExpression { fn comments(&self) -> Option<&CommentGroup> { match &self { - ExitConstructExpression::Exit { comments, .. } => Some(comments), - ExitConstructExpression::ExitWith { comments, .. } => Some(comments), + Self::Exit { comments, .. } => Some(comments), + Self::ExitWith { comments, .. } => Some(comments), } } fn initial_position(&self) -> usize { match &self { - ExitConstructExpression::Exit { exit, .. } - | ExitConstructExpression::ExitWith { exit, .. } => exit.initial_position(), + Self::Exit { exit, .. } | Self::ExitWith { exit, .. } => exit.initial_position(), } } fn final_position(&self) -> usize { match &self { - ExitConstructExpression::Exit { exit, .. } => exit.final_position(), - ExitConstructExpression::ExitWith { + Self::Exit { exit, .. } => exit.final_position(), + Self::ExitWith { right_parenthesis, .. } => right_parenthesis + 1, } @@ -50,8 +49,8 @@ impl Node for ExitConstructExpression { fn children(&self) -> Vec<&dyn Node> { match &self { - ExitConstructExpression::Exit { exit, .. } => vec![exit], - ExitConstructExpression::ExitWith { exit, value, .. } => { + Self::Exit { exit, .. } => vec![exit], + Self::ExitWith { exit, value, .. } => { if let Some(value) = value { vec![exit, value.as_ref()] } else { diff --git a/src/tree/expression/magic_constant.rs b/src/tree/expression/magic_constant.rs index 2fd6930..797b284 100644 --- a/src/tree/expression/magic_constant.rs +++ b/src/tree/expression/magic_constant.rs @@ -20,25 +20,25 @@ pub enum MagicConstant { impl Node for MagicConstant { fn initial_position(&self) -> usize { match &self { - MagicConstant::Directory { position, .. } => *position, - MagicConstant::File { position, .. } => *position, - MagicConstant::Line { position, .. } => *position, - MagicConstant::Class { position, .. } => *position, - MagicConstant::Function { position, .. } => *position, - MagicConstant::Method { position, .. } => *position, - MagicConstant::Namespace { position, .. } => *position, + Self::Directory { position, .. } => *position, + Self::File { position, .. } => *position, + Self::Line { position, .. } => *position, + Self::Class { position, .. } => *position, + Self::Function { position, .. } => *position, + Self::Method { position, .. } => *position, + Self::Namespace { position, .. } => *position, } } fn final_position(&self) -> usize { match &self { - MagicConstant::Directory { position, value } => position + value.len(), - MagicConstant::File { position, value } => position + value.len(), - MagicConstant::Line { position, value } => position + value.len(), - MagicConstant::Class { position, value } => position + value.len(), - MagicConstant::Function { position, value } => position + value.len(), - MagicConstant::Method { position, value } => position + value.len(), - MagicConstant::Namespace { position, value } => position + value.len(), + Self::Directory { position, value } => position + value.len(), + Self::File { position, value } => position + value.len(), + Self::Line { position, value } => position + value.len(), + Self::Class { position, value } => position + value.len(), + Self::Function { position, value } => position + value.len(), + Self::Method { position, value } => position + value.len(), + Self::Namespace { position, value } => position + value.len(), } } @@ -48,13 +48,13 @@ impl Node for MagicConstant { fn get_description(&self) -> String { match &self { - MagicConstant::Directory { .. } => "directory magic constant expression".to_string(), - MagicConstant::File { .. } => "file magic constant expression".to_string(), - MagicConstant::Line { .. } => "line magic constant expression".to_string(), - MagicConstant::Class { .. } => "class magic constant expression".to_string(), - MagicConstant::Function { .. } => "function magic constant expression".to_string(), - MagicConstant::Method { .. } => "method magic constant expression".to_string(), - MagicConstant::Namespace { .. } => "namespace magic constant expression".to_string(), + Self::Directory { .. } => "directory magic constant expression".to_string(), + Self::File { .. } => "file magic constant expression".to_string(), + Self::Line { .. } => "line magic constant expression".to_string(), + Self::Class { .. } => "class magic constant expression".to_string(), + Self::Function { .. } => "function magic constant expression".to_string(), + Self::Method { .. } => "method magic constant expression".to_string(), + Self::Namespace { .. } => "namespace magic constant expression".to_string(), } } } diff --git a/src/tree/expression/mod.rs b/src/tree/expression/mod.rs index 1ac7496..ac3d63b 100644 --- a/src/tree/expression/mod.rs +++ b/src/tree/expression/mod.rs @@ -116,13 +116,11 @@ impl Expression { /// If `initilization` is true, the expression is allowed to contain a class initialization expression. pub fn is_constant(&self, initilization: bool) -> bool { match &self { - Expression::Literal(_) => true, - Expression::Identifier(_) => true, - Expression::MagicConstant(_) => true, - Expression::Parenthesized(expression) => { - expression.expression.is_constant(initilization) - } - Expression::ArithmeticOperation(expression) => match &expression { + Self::Literal(_) => true, + Self::Identifier(_) => true, + Self::MagicConstant(_) => true, + Self::Parenthesized(expression) => expression.expression.is_constant(initilization), + Self::ArithmeticOperation(expression) => match &expression { ArithmeticOperationExpression::Addition { left, right, .. } | ArithmeticOperationExpression::Subtraction { left, right, .. } | ArithmeticOperationExpression::Multiplication { left, right, .. } @@ -140,10 +138,10 @@ impl Expression { | ArithmeticOperationExpression::PostIncrement { .. } | ArithmeticOperationExpression::PostDecrement { .. } => false, }, - Expression::ArrayOperation(ArrayOperationExpression::Access { - array, index, .. - }) => array.is_constant(initilization) && index.is_constant(initilization), - Expression::BitwiseOperation(expression) => match &expression { + Self::ArrayOperation(ArrayOperationExpression::Access { array, index, .. }) => { + array.is_constant(initilization) && index.is_constant(initilization) + } + Self::BitwiseOperation(expression) => match &expression { BitwiseOperationExpression::And { left, right, .. } | BitwiseOperationExpression::Or { left, right, .. } | BitwiseOperationExpression::Xor { left, right, .. } @@ -153,7 +151,7 @@ impl Expression { } BitwiseOperationExpression::Not { right, .. } => right.is_constant(initilization), }, - Expression::ClassOperation(expression) => match &expression { + Self::ClassOperation(expression) => match &expression { ClassOperationExpression::Initialization { class, arguments, .. } if initilization => match class { @@ -180,12 +178,10 @@ impl Expression { } _ => false, }, - Expression::CoalesceOperation(CoalesceOperationExpression::Coalesce { - left, - right, - .. + Self::CoalesceOperation(CoalesceOperationExpression::Coalesce { + left, right, .. }) => left.is_constant(initilization) && right.is_constant(initilization), - Expression::ComparisonOperation(expression) => match &expression { + Self::ComparisonOperation(expression) => match &expression { ComparisonOperationExpression::Equal { left, right, .. } | ComparisonOperationExpression::NotEqual { left, right, .. } | ComparisonOperationExpression::Identical { left, right, .. } @@ -200,17 +196,17 @@ impl Expression { left.is_constant(initilization) && right.is_constant(initilization) } }, - Expression::LogicalOperation(expression) => match &expression { + Self::LogicalOperation(expression) => match &expression { LogicalOperationExpression::And { left, right, .. } | LogicalOperationExpression::Or { left, right, .. } => { left.is_constant(initilization) && right.is_constant(initilization) } LogicalOperationExpression::Not { right, .. } => right.is_constant(initilization), }, - Expression::StringOperation(StringOperationExpression::Concat { - left, right, .. - }) => left.is_constant(initilization) && right.is_constant(initilization), - Expression::TernaryOperation(expression) => match &expression { + Self::StringOperation(StringOperationExpression::Concat { left, right, .. }) => { + left.is_constant(initilization) && right.is_constant(initilization) + } + Self::TernaryOperation(expression) => match &expression { TernaryOperationExpression::Ternary { condition, if_true, @@ -232,15 +228,15 @@ impl Expression { .. } => condition.is_constant(initilization) && if_false.is_constant(initilization), }, - Expression::Vec(expression) => expression + Self::Vec(expression) => expression .elements .inner .iter() .all(|element| element.value.is_constant(initilization)), - Expression::Dict(expression) => expression.elements.inner.iter().all(|element| { + Self::Dict(expression) => expression.elements.inner.iter().all(|element| { element.value.is_constant(initilization) && element.key.is_constant(initilization) }), - Expression::Tuple(expression) => expression + Self::Tuple(expression) => expression .elements .inner .iter() @@ -252,14 +248,12 @@ impl Expression { /// Return true if the expression is writable pub fn is_writable(&self) -> bool { match &self { - Expression::Variable(_) - | Expression::ArrayOperation(ArrayOperationExpression::Push { .. }) - | Expression::ArrayOperation(ArrayOperationExpression::Access { .. }) - | Expression::ObjectOperation(ObjectOperationExpression::PropertyFetch { .. }) - | Expression::ClassOperation(ClassOperationExpression::StaticPropertyFetch { - .. - }) => true, - Expression::Tuple(TupleExpression { elements, .. }) => { + Self::Variable(_) + | Self::ArrayOperation(ArrayOperationExpression::Push { .. }) + | Self::ArrayOperation(ArrayOperationExpression::Access { .. }) + | Self::ObjectOperation(ObjectOperationExpression::PropertyFetch { .. }) + | Self::ClassOperation(ClassOperationExpression::StaticPropertyFetch { .. }) => true, + Self::Tuple(TupleExpression { elements, .. }) => { elements.inner.iter().all(|element| element.is_writable()) } _ => false, @@ -269,13 +263,12 @@ impl Expression { /// Return true if the expression is readable pub fn is_readable(&self) -> bool { match &self { - Expression::AssignmentOperation(..) - | Expression::ExitConstruct(..) - | Expression::ExceptionOperation(ExceptionOperationExpression::Throw { .. }) - | Expression::ArrayOperation(ArrayOperationExpression::Push { .. }) => false, - Expression::AsyncOperation(AsyncOperationExpression::Concurrently { - expressions, - .. + Self::AssignmentOperation(..) + | Self::ExitConstruct(..) + | Self::ExceptionOperation(ExceptionOperationExpression::Throw { .. }) + | Self::ArrayOperation(ArrayOperationExpression::Push { .. }) => false, + Self::AsyncOperation(AsyncOperationExpression::Concurrently { + expressions, .. }) => expressions .inner .iter() @@ -292,137 +285,137 @@ impl Node for Expression { fn initial_position(&self) -> usize { match &self { - Expression::Parenthesized(expression) => expression.initial_position(), - Expression::ExitConstruct(expression) => expression.initial_position(), - Expression::Literal(expression) => expression.initial_position(), - Expression::ArithmeticOperation(expression) => expression.initial_position(), - Expression::AsyncOperation(expression) => expression.initial_position(), - Expression::ArrayOperation(expression) => expression.initial_position(), - Expression::AssignmentOperation(expression) => expression.initial_position(), - Expression::BitwiseOperation(expression) => expression.initial_position(), - Expression::ClassOperation(expression) => expression.initial_position(), - Expression::CoalesceOperation(expression) => expression.initial_position(), - Expression::ComparisonOperation(expression) => expression.initial_position(), - Expression::ExceptionOperation(expression) => expression.initial_position(), - Expression::FunctionOperation(expression) => expression.initial_position(), - Expression::GeneratorOperation(expression) => expression.initial_position(), - Expression::LogicalOperation(expression) => expression.initial_position(), - Expression::ObjectOperation(expression) => expression.initial_position(), - Expression::RangeOperation(expression) => expression.initial_position(), - Expression::StringOperation(expression) => expression.initial_position(), - Expression::TypeOperation(expression) => expression.initial_position(), - Expression::TernaryOperation(expression) => expression.initial_position(), - Expression::Identifier(expression) => expression.initial_position(), - Expression::Variable(expression) => expression.initial_position(), - Expression::Match(expression) => expression.initial_position(), - Expression::AnonymousFunction(expression) => expression.initial_position(), - Expression::ArrowFunction(expression) => expression.initial_position(), - Expression::Vec(expression) => expression.initial_position(), - Expression::Dict(expression) => expression.initial_position(), - Expression::Tuple(expression) => expression.initial_position(), - Expression::MagicConstant(expression) => expression.initial_position(), + Self::Parenthesized(expression) => expression.initial_position(), + Self::ExitConstruct(expression) => expression.initial_position(), + Self::Literal(expression) => expression.initial_position(), + Self::ArithmeticOperation(expression) => expression.initial_position(), + Self::AsyncOperation(expression) => expression.initial_position(), + Self::ArrayOperation(expression) => expression.initial_position(), + Self::AssignmentOperation(expression) => expression.initial_position(), + Self::BitwiseOperation(expression) => expression.initial_position(), + Self::ClassOperation(expression) => expression.initial_position(), + Self::CoalesceOperation(expression) => expression.initial_position(), + Self::ComparisonOperation(expression) => expression.initial_position(), + Self::ExceptionOperation(expression) => expression.initial_position(), + Self::FunctionOperation(expression) => expression.initial_position(), + Self::GeneratorOperation(expression) => expression.initial_position(), + Self::LogicalOperation(expression) => expression.initial_position(), + Self::ObjectOperation(expression) => expression.initial_position(), + Self::RangeOperation(expression) => expression.initial_position(), + Self::StringOperation(expression) => expression.initial_position(), + Self::TypeOperation(expression) => expression.initial_position(), + Self::TernaryOperation(expression) => expression.initial_position(), + Self::Identifier(expression) => expression.initial_position(), + Self::Variable(expression) => expression.initial_position(), + Self::Match(expression) => expression.initial_position(), + Self::AnonymousFunction(expression) => expression.initial_position(), + Self::ArrowFunction(expression) => expression.initial_position(), + Self::Vec(expression) => expression.initial_position(), + Self::Dict(expression) => expression.initial_position(), + Self::Tuple(expression) => expression.initial_position(), + Self::MagicConstant(expression) => expression.initial_position(), } } fn final_position(&self) -> usize { match &self { - Expression::Parenthesized(expression) => expression.final_position(), - Expression::ExitConstruct(expression) => expression.final_position(), - Expression::Literal(expression) => expression.final_position(), - Expression::ArithmeticOperation(expression) => expression.final_position(), - Expression::AsyncOperation(expression) => expression.final_position(), - Expression::ArrayOperation(expression) => expression.final_position(), - Expression::AssignmentOperation(expression) => expression.final_position(), - Expression::BitwiseOperation(expression) => expression.final_position(), - Expression::ClassOperation(expression) => expression.final_position(), - Expression::CoalesceOperation(expression) => expression.final_position(), - Expression::ComparisonOperation(expression) => expression.final_position(), - Expression::ExceptionOperation(expression) => expression.final_position(), - Expression::FunctionOperation(expression) => expression.final_position(), - Expression::GeneratorOperation(expression) => expression.final_position(), - Expression::LogicalOperation(expression) => expression.final_position(), - Expression::ObjectOperation(expression) => expression.final_position(), - Expression::RangeOperation(expression) => expression.final_position(), - Expression::StringOperation(expression) => expression.final_position(), - Expression::TypeOperation(expression) => expression.final_position(), - Expression::TernaryOperation(expression) => expression.final_position(), - Expression::Identifier(expression) => expression.final_position(), - Expression::Variable(expression) => expression.final_position(), - Expression::Match(expression) => expression.final_position(), - Expression::AnonymousFunction(expression) => expression.final_position(), - Expression::ArrowFunction(expression) => expression.final_position(), - Expression::Vec(expression) => expression.final_position(), - Expression::Dict(expression) => expression.final_position(), - Expression::Tuple(expression) => expression.final_position(), - Expression::MagicConstant(expression) => expression.final_position(), + Self::Parenthesized(expression) => expression.final_position(), + Self::ExitConstruct(expression) => expression.final_position(), + Self::Literal(expression) => expression.final_position(), + Self::ArithmeticOperation(expression) => expression.final_position(), + Self::AsyncOperation(expression) => expression.final_position(), + Self::ArrayOperation(expression) => expression.final_position(), + Self::AssignmentOperation(expression) => expression.final_position(), + Self::BitwiseOperation(expression) => expression.final_position(), + Self::ClassOperation(expression) => expression.final_position(), + Self::CoalesceOperation(expression) => expression.final_position(), + Self::ComparisonOperation(expression) => expression.final_position(), + Self::ExceptionOperation(expression) => expression.final_position(), + Self::FunctionOperation(expression) => expression.final_position(), + Self::GeneratorOperation(expression) => expression.final_position(), + Self::LogicalOperation(expression) => expression.final_position(), + Self::ObjectOperation(expression) => expression.final_position(), + Self::RangeOperation(expression) => expression.final_position(), + Self::StringOperation(expression) => expression.final_position(), + Self::TypeOperation(expression) => expression.final_position(), + Self::TernaryOperation(expression) => expression.final_position(), + Self::Identifier(expression) => expression.final_position(), + Self::Variable(expression) => expression.final_position(), + Self::Match(expression) => expression.final_position(), + Self::AnonymousFunction(expression) => expression.final_position(), + Self::ArrowFunction(expression) => expression.final_position(), + Self::Vec(expression) => expression.final_position(), + Self::Dict(expression) => expression.final_position(), + Self::Tuple(expression) => expression.final_position(), + Self::MagicConstant(expression) => expression.final_position(), } } fn children(&self) -> Vec<&dyn Node> { match &self { - Expression::Parenthesized(expression) => vec![expression], - Expression::ExitConstruct(expression) => vec![expression], - Expression::Literal(expression) => vec![expression], - Expression::ArithmeticOperation(expression) => vec![expression], - Expression::AsyncOperation(expression) => vec![expression], - Expression::ArrayOperation(expression) => vec![expression], - Expression::AssignmentOperation(expression) => vec![expression], - Expression::BitwiseOperation(expression) => vec![expression], - Expression::ClassOperation(expression) => vec![expression], - Expression::CoalesceOperation(expression) => vec![expression], - Expression::ComparisonOperation(expression) => vec![expression], - Expression::ExceptionOperation(expression) => vec![expression], - Expression::FunctionOperation(expression) => vec![expression], - Expression::GeneratorOperation(expression) => vec![expression], - Expression::LogicalOperation(expression) => vec![expression], - Expression::ObjectOperation(expression) => vec![expression], - Expression::RangeOperation(expression) => vec![expression], - Expression::StringOperation(expression) => vec![expression], - Expression::TypeOperation(expression) => vec![expression], - Expression::TernaryOperation(expression) => vec![expression], - Expression::Identifier(expression) => vec![expression], - Expression::Variable(expression) => vec![expression], - Expression::Match(expression) => vec![expression], - Expression::AnonymousFunction(expression) => vec![expression], - Expression::ArrowFunction(expression) => vec![expression], - Expression::Vec(expression) => vec![expression], - Expression::Dict(expression) => vec![expression], - Expression::Tuple(expression) => vec![expression], - Expression::MagicConstant(expression) => vec![expression], + Self::Parenthesized(expression) => vec![expression], + Self::ExitConstruct(expression) => vec![expression], + Self::Literal(expression) => vec![expression], + Self::ArithmeticOperation(expression) => vec![expression], + Self::AsyncOperation(expression) => vec![expression], + Self::ArrayOperation(expression) => vec![expression], + Self::AssignmentOperation(expression) => vec![expression], + Self::BitwiseOperation(expression) => vec![expression], + Self::ClassOperation(expression) => vec![expression], + Self::CoalesceOperation(expression) => vec![expression], + Self::ComparisonOperation(expression) => vec![expression], + Self::ExceptionOperation(expression) => vec![expression], + Self::FunctionOperation(expression) => vec![expression], + Self::GeneratorOperation(expression) => vec![expression], + Self::LogicalOperation(expression) => vec![expression], + Self::ObjectOperation(expression) => vec![expression], + Self::RangeOperation(expression) => vec![expression], + Self::StringOperation(expression) => vec![expression], + Self::TypeOperation(expression) => vec![expression], + Self::TernaryOperation(expression) => vec![expression], + Self::Identifier(expression) => vec![expression], + Self::Variable(expression) => vec![expression], + Self::Match(expression) => vec![expression], + Self::AnonymousFunction(expression) => vec![expression], + Self::ArrowFunction(expression) => vec![expression], + Self::Vec(expression) => vec![expression], + Self::Dict(expression) => vec![expression], + Self::Tuple(expression) => vec![expression], + Self::MagicConstant(expression) => vec![expression], } } fn get_description(&self) -> String { match &self { - Expression::Parenthesized(expression) => expression.get_description(), - Expression::ExitConstruct(expression) => expression.get_description(), - Expression::Literal(expression) => expression.get_description(), - Expression::ArithmeticOperation(expression) => expression.get_description(), - Expression::AsyncOperation(expression) => expression.get_description(), - Expression::ArrayOperation(expression) => expression.get_description(), - Expression::AssignmentOperation(expression) => expression.get_description(), - Expression::BitwiseOperation(expression) => expression.get_description(), - Expression::ClassOperation(expression) => expression.get_description(), - Expression::CoalesceOperation(expression) => expression.get_description(), - Expression::ComparisonOperation(expression) => expression.get_description(), - Expression::ExceptionOperation(expression) => expression.get_description(), - Expression::FunctionOperation(expression) => expression.get_description(), - Expression::GeneratorOperation(expression) => expression.get_description(), - Expression::LogicalOperation(expression) => expression.get_description(), - Expression::ObjectOperation(expression) => expression.get_description(), - Expression::RangeOperation(expression) => expression.get_description(), - Expression::StringOperation(expression) => expression.get_description(), - Expression::TypeOperation(expression) => expression.get_description(), - Expression::TernaryOperation(expression) => expression.get_description(), - Expression::Identifier(expression) => expression.get_description(), - Expression::Variable(expression) => expression.get_description(), - Expression::Match(expression) => expression.get_description(), - Expression::AnonymousFunction(expression) => expression.get_description(), - Expression::ArrowFunction(expression) => expression.get_description(), - Expression::Vec(expression) => expression.get_description(), - Expression::Dict(expression) => expression.get_description(), - Expression::Tuple(expression) => expression.get_description(), - Expression::MagicConstant(expression) => expression.get_description(), + Self::Parenthesized(expression) => expression.get_description(), + Self::ExitConstruct(expression) => expression.get_description(), + Self::Literal(expression) => expression.get_description(), + Self::ArithmeticOperation(expression) => expression.get_description(), + Self::AsyncOperation(expression) => expression.get_description(), + Self::ArrayOperation(expression) => expression.get_description(), + Self::AssignmentOperation(expression) => expression.get_description(), + Self::BitwiseOperation(expression) => expression.get_description(), + Self::ClassOperation(expression) => expression.get_description(), + Self::CoalesceOperation(expression) => expression.get_description(), + Self::ComparisonOperation(expression) => expression.get_description(), + Self::ExceptionOperation(expression) => expression.get_description(), + Self::FunctionOperation(expression) => expression.get_description(), + Self::GeneratorOperation(expression) => expression.get_description(), + Self::LogicalOperation(expression) => expression.get_description(), + Self::ObjectOperation(expression) => expression.get_description(), + Self::RangeOperation(expression) => expression.get_description(), + Self::StringOperation(expression) => expression.get_description(), + Self::TypeOperation(expression) => expression.get_description(), + Self::TernaryOperation(expression) => expression.get_description(), + Self::Identifier(expression) => expression.get_description(), + Self::Variable(expression) => expression.get_description(), + Self::Match(expression) => expression.get_description(), + Self::AnonymousFunction(expression) => expression.get_description(), + Self::ArrowFunction(expression) => expression.get_description(), + Self::Vec(expression) => expression.get_description(), + Self::Dict(expression) => expression.get_description(), + Self::Tuple(expression) => expression.get_description(), + Self::MagicConstant(expression) => expression.get_description(), } } } diff --git a/src/tree/expression/operator.rs b/src/tree/expression/operator.rs index c1a7951..74b399e 100644 --- a/src/tree/expression/operator.rs +++ b/src/tree/expression/operator.rs @@ -620,12 +620,12 @@ pub enum RangeOperationExpression { impl RangeOperationExpression { pub fn has_start(&self) -> bool { match &self { - RangeOperationExpression::Between { .. } => true, - RangeOperationExpression::BetweenInclusive { .. } => true, - RangeOperationExpression::To { .. } => false, - RangeOperationExpression::ToInclusive { .. } => false, - RangeOperationExpression::From { .. } => true, - RangeOperationExpression::Full { .. } => false, + Self::Between { .. } => true, + Self::BetweenInclusive { .. } => true, + Self::To { .. } => false, + Self::ToInclusive { .. } => false, + Self::From { .. } => true, + Self::Full { .. } => false, } } } @@ -633,71 +633,70 @@ impl RangeOperationExpression { impl Node for ArithmeticOperationExpression { fn comments(&self) -> Option<&CommentGroup> { match &self { - ArithmeticOperationExpression::Addition { comments, .. } => Some(comments), - ArithmeticOperationExpression::Subtraction { comments, .. } => Some(comments), - ArithmeticOperationExpression::Multiplication { comments, .. } => Some(comments), - ArithmeticOperationExpression::Division { comments, .. } => Some(comments), - ArithmeticOperationExpression::Modulo { comments, .. } => Some(comments), - ArithmeticOperationExpression::Exponentiation { comments, .. } => Some(comments), - ArithmeticOperationExpression::Negative { comments, .. } => Some(comments), - ArithmeticOperationExpression::Positive { comments, .. } => Some(comments), - ArithmeticOperationExpression::PreIncrement { comments, .. } => Some(comments), - ArithmeticOperationExpression::PreDecrement { comments, .. } => Some(comments), - ArithmeticOperationExpression::PostIncrement { .. } => None, - ArithmeticOperationExpression::PostDecrement { .. } => None, + Self::Addition { comments, .. } => Some(comments), + Self::Subtraction { comments, .. } => Some(comments), + Self::Multiplication { comments, .. } => Some(comments), + Self::Division { comments, .. } => Some(comments), + Self::Modulo { comments, .. } => Some(comments), + Self::Exponentiation { comments, .. } => Some(comments), + Self::Negative { comments, .. } => Some(comments), + Self::Positive { comments, .. } => Some(comments), + Self::PreIncrement { comments, .. } => Some(comments), + Self::PreDecrement { comments, .. } => Some(comments), + Self::PostIncrement { .. } => None, + Self::PostDecrement { .. } => None, } } fn initial_position(&self) -> usize { match &self { - ArithmeticOperationExpression::Addition { left, .. } => left.initial_position(), - ArithmeticOperationExpression::Subtraction { left, .. } => left.initial_position(), - ArithmeticOperationExpression::Multiplication { left, .. } => left.initial_position(), - ArithmeticOperationExpression::Division { left, .. } => left.initial_position(), - ArithmeticOperationExpression::Modulo { left, .. } => left.initial_position(), - ArithmeticOperationExpression::Exponentiation { left, .. } => left.initial_position(), - ArithmeticOperationExpression::Negative { minus, .. } => *minus, - ArithmeticOperationExpression::Positive { plus, .. } => *plus, - ArithmeticOperationExpression::PreIncrement { increment, .. } => *increment, - ArithmeticOperationExpression::PreDecrement { decrement, .. } => *decrement, - ArithmeticOperationExpression::PostIncrement { left, .. } => left.initial_position(), - ArithmeticOperationExpression::PostDecrement { left, .. } => left.initial_position(), + Self::Addition { left, .. } => left.initial_position(), + Self::Subtraction { left, .. } => left.initial_position(), + Self::Multiplication { left, .. } => left.initial_position(), + Self::Division { left, .. } => left.initial_position(), + Self::Modulo { left, .. } => left.initial_position(), + Self::Exponentiation { left, .. } => left.initial_position(), + Self::Negative { minus, .. } => *minus, + Self::Positive { plus, .. } => *plus, + Self::PreIncrement { increment, .. } => *increment, + Self::PreDecrement { decrement, .. } => *decrement, + Self::PostIncrement { left, .. } => left.initial_position(), + Self::PostDecrement { left, .. } => left.initial_position(), } } fn final_position(&self) -> usize { match &self { - ArithmeticOperationExpression::Addition { right, .. } => right.final_position(), - ArithmeticOperationExpression::Subtraction { right, .. } => right.final_position(), - ArithmeticOperationExpression::Multiplication { right, .. } => right.final_position(), - ArithmeticOperationExpression::Division { right, .. } => right.final_position(), - ArithmeticOperationExpression::Modulo { right, .. } => right.final_position(), - ArithmeticOperationExpression::Exponentiation { right, .. } => right.final_position(), - ArithmeticOperationExpression::Negative { right, .. } => right.final_position(), - ArithmeticOperationExpression::Positive { right, .. } => right.final_position(), - ArithmeticOperationExpression::PreIncrement { right, .. } => right.final_position(), - ArithmeticOperationExpression::PreDecrement { right, .. } => right.final_position(), - ArithmeticOperationExpression::PostIncrement { increment, .. } => *increment, - ArithmeticOperationExpression::PostDecrement { decrement, .. } => *decrement, + Self::Addition { right, .. } => right.final_position(), + Self::Subtraction { right, .. } => right.final_position(), + Self::Multiplication { right, .. } => right.final_position(), + Self::Division { right, .. } => right.final_position(), + Self::Modulo { right, .. } => right.final_position(), + Self::Exponentiation { right, .. } => right.final_position(), + Self::Negative { right, .. } => right.final_position(), + Self::Positive { right, .. } => right.final_position(), + Self::PreIncrement { right, .. } => right.final_position(), + Self::PreDecrement { right, .. } => right.final_position(), + Self::PostIncrement { increment, .. } => *increment, + Self::PostDecrement { decrement, .. } => *decrement, } } fn children(&self) -> Vec<&dyn Node> { match &self { - ArithmeticOperationExpression::Addition { left, right, .. } - | ArithmeticOperationExpression::Subtraction { left, right, .. } - | ArithmeticOperationExpression::Multiplication { left, right, .. } - | ArithmeticOperationExpression::Division { left, right, .. } - | ArithmeticOperationExpression::Modulo { left, right, .. } - | ArithmeticOperationExpression::Exponentiation { left, right, .. } => { + Self::Addition { left, right, .. } + | Self::Subtraction { left, right, .. } + | Self::Multiplication { left, right, .. } + | Self::Division { left, right, .. } + | Self::Modulo { left, right, .. } + | Self::Exponentiation { left, right, .. } => { vec![left.as_ref(), right.as_ref()] } - ArithmeticOperationExpression::Negative { right, .. } - | ArithmeticOperationExpression::Positive { right, .. } - | ArithmeticOperationExpression::PreIncrement { right, .. } - | ArithmeticOperationExpression::PreDecrement { right, .. } => vec![right.as_ref()], - ArithmeticOperationExpression::PostIncrement { left, .. } - | ArithmeticOperationExpression::PostDecrement { left, .. } => { + Self::Negative { right, .. } + | Self::Positive { right, .. } + | Self::PreIncrement { right, .. } + | Self::PreDecrement { right, .. } => vec![right.as_ref()], + Self::PostIncrement { left, .. } | Self::PostDecrement { left, .. } => { vec![left.as_ref()] } } @@ -705,40 +704,28 @@ impl Node for ArithmeticOperationExpression { fn get_description(&self) -> String { match &self { - ArithmeticOperationExpression::Addition { .. } => { - "addition arithmetic operation expression".to_string() - } - ArithmeticOperationExpression::Subtraction { .. } => { - "subtraction arithmetic operation expression".to_string() - } - ArithmeticOperationExpression::Multiplication { .. } => { + Self::Addition { .. } => "addition arithmetic operation expression".to_string(), + Self::Subtraction { .. } => "subtraction arithmetic operation expression".to_string(), + Self::Multiplication { .. } => { "multiplication arithmetic operation expression".to_string() } - ArithmeticOperationExpression::Division { .. } => { - "division arithmetic operation expression".to_string() - } - ArithmeticOperationExpression::Modulo { .. } => { - "modulo arithmetic operation expression".to_string() - } - ArithmeticOperationExpression::Exponentiation { .. } => { + Self::Division { .. } => "division arithmetic operation expression".to_string(), + Self::Modulo { .. } => "modulo arithmetic operation expression".to_string(), + Self::Exponentiation { .. } => { "exponentiation arithmetic operation expression".to_string() } - ArithmeticOperationExpression::Negative { .. } => { - "negative arithmetic operation expression".to_string() - } - ArithmeticOperationExpression::Positive { .. } => { - "positive arithmetic operation expression".to_string() - } - ArithmeticOperationExpression::PreIncrement { .. } => { + Self::Negative { .. } => "negative arithmetic operation expression".to_string(), + Self::Positive { .. } => "positive arithmetic operation expression".to_string(), + Self::PreIncrement { .. } => { "pre-increment arithmetic operation expression".to_string() } - ArithmeticOperationExpression::PreDecrement { .. } => { + Self::PreDecrement { .. } => { "pre-decrement arithmetic operation expression".to_string() } - ArithmeticOperationExpression::PostIncrement { .. } => { + Self::PostIncrement { .. } => { "post-increment arithmetic operation expression".to_string() } - ArithmeticOperationExpression::PostDecrement { .. } => { + Self::PostDecrement { .. } => { "post-decrement arithmetic operation expression".to_string() } } @@ -748,77 +735,77 @@ impl Node for ArithmeticOperationExpression { impl Node for AssignmentOperationExpression { fn comments(&self) -> Option<&CommentGroup> { match &self { - AssignmentOperationExpression::Assignment { comments, .. } => Some(comments), - AssignmentOperationExpression::Addition { comments, .. } => Some(comments), - AssignmentOperationExpression::Subtraction { comments, .. } => Some(comments), - AssignmentOperationExpression::Multiplication { comments, .. } => Some(comments), - AssignmentOperationExpression::Division { comments, .. } => Some(comments), - AssignmentOperationExpression::Modulo { comments, .. } => Some(comments), - AssignmentOperationExpression::Exponentiation { comments, .. } => Some(comments), - AssignmentOperationExpression::BitwiseAnd { comments, .. } => Some(comments), - AssignmentOperationExpression::BitwiseOr { comments, .. } => Some(comments), - AssignmentOperationExpression::BitwiseXor { comments, .. } => Some(comments), - AssignmentOperationExpression::LeftShift { comments, .. } => Some(comments), - AssignmentOperationExpression::RightShift { comments, .. } => Some(comments), - AssignmentOperationExpression::Coalesce { comments, .. } => Some(comments), - AssignmentOperationExpression::Concat { comments, .. } => Some(comments), + Self::Assignment { comments, .. } => Some(comments), + Self::Addition { comments, .. } => Some(comments), + Self::Subtraction { comments, .. } => Some(comments), + Self::Multiplication { comments, .. } => Some(comments), + Self::Division { comments, .. } => Some(comments), + Self::Modulo { comments, .. } => Some(comments), + Self::Exponentiation { comments, .. } => Some(comments), + Self::BitwiseAnd { comments, .. } => Some(comments), + Self::BitwiseOr { comments, .. } => Some(comments), + Self::BitwiseXor { comments, .. } => Some(comments), + Self::LeftShift { comments, .. } => Some(comments), + Self::RightShift { comments, .. } => Some(comments), + Self::Coalesce { comments, .. } => Some(comments), + Self::Concat { comments, .. } => Some(comments), } } fn initial_position(&self) -> usize { match &self { - AssignmentOperationExpression::Assignment { left, .. } => left.initial_position(), - AssignmentOperationExpression::Addition { left, .. } => left.initial_position(), - AssignmentOperationExpression::Subtraction { left, .. } => left.initial_position(), - AssignmentOperationExpression::Multiplication { left, .. } => left.initial_position(), - AssignmentOperationExpression::Division { left, .. } => left.initial_position(), - AssignmentOperationExpression::Modulo { left, .. } => left.initial_position(), - AssignmentOperationExpression::Exponentiation { left, .. } => left.initial_position(), - AssignmentOperationExpression::BitwiseAnd { left, .. } => left.initial_position(), - AssignmentOperationExpression::BitwiseOr { left, .. } => left.initial_position(), - AssignmentOperationExpression::BitwiseXor { left, .. } => left.initial_position(), - AssignmentOperationExpression::LeftShift { left, .. } => left.initial_position(), - AssignmentOperationExpression::RightShift { left, .. } => left.initial_position(), - AssignmentOperationExpression::Coalesce { left, .. } => left.initial_position(), - AssignmentOperationExpression::Concat { left, .. } => left.initial_position(), + Self::Assignment { left, .. } => left.initial_position(), + Self::Addition { left, .. } => left.initial_position(), + Self::Subtraction { left, .. } => left.initial_position(), + Self::Multiplication { left, .. } => left.initial_position(), + Self::Division { left, .. } => left.initial_position(), + Self::Modulo { left, .. } => left.initial_position(), + Self::Exponentiation { left, .. } => left.initial_position(), + Self::BitwiseAnd { left, .. } => left.initial_position(), + Self::BitwiseOr { left, .. } => left.initial_position(), + Self::BitwiseXor { left, .. } => left.initial_position(), + Self::LeftShift { left, .. } => left.initial_position(), + Self::RightShift { left, .. } => left.initial_position(), + Self::Coalesce { left, .. } => left.initial_position(), + Self::Concat { left, .. } => left.initial_position(), } } fn final_position(&self) -> usize { match &self { - AssignmentOperationExpression::Assignment { right, .. } => right.final_position(), - AssignmentOperationExpression::Addition { right, .. } => right.final_position(), - AssignmentOperationExpression::Subtraction { right, .. } => right.final_position(), - AssignmentOperationExpression::Multiplication { right, .. } => right.final_position(), - AssignmentOperationExpression::Division { right, .. } => right.final_position(), - AssignmentOperationExpression::Modulo { right, .. } => right.final_position(), - AssignmentOperationExpression::Exponentiation { right, .. } => right.final_position(), - AssignmentOperationExpression::BitwiseAnd { right, .. } => right.final_position(), - AssignmentOperationExpression::BitwiseOr { right, .. } => right.final_position(), - AssignmentOperationExpression::BitwiseXor { right, .. } => right.final_position(), - AssignmentOperationExpression::LeftShift { right, .. } => right.final_position(), - AssignmentOperationExpression::RightShift { right, .. } => right.final_position(), - AssignmentOperationExpression::Coalesce { right, .. } => right.final_position(), - AssignmentOperationExpression::Concat { right, .. } => right.final_position(), + Self::Assignment { right, .. } => right.final_position(), + Self::Addition { right, .. } => right.final_position(), + Self::Subtraction { right, .. } => right.final_position(), + Self::Multiplication { right, .. } => right.final_position(), + Self::Division { right, .. } => right.final_position(), + Self::Modulo { right, .. } => right.final_position(), + Self::Exponentiation { right, .. } => right.final_position(), + Self::BitwiseAnd { right, .. } => right.final_position(), + Self::BitwiseOr { right, .. } => right.final_position(), + Self::BitwiseXor { right, .. } => right.final_position(), + Self::LeftShift { right, .. } => right.final_position(), + Self::RightShift { right, .. } => right.final_position(), + Self::Coalesce { right, .. } => right.final_position(), + Self::Concat { right, .. } => right.final_position(), } } fn children(&self) -> Vec<&dyn Node> { match &self { - AssignmentOperationExpression::Assignment { left, right, .. } - | AssignmentOperationExpression::Addition { left, right, .. } - | AssignmentOperationExpression::Subtraction { left, right, .. } - | AssignmentOperationExpression::Multiplication { left, right, .. } - | AssignmentOperationExpression::Division { left, right, .. } - | AssignmentOperationExpression::Modulo { left, right, .. } - | AssignmentOperationExpression::Exponentiation { left, right, .. } - | AssignmentOperationExpression::BitwiseAnd { left, right, .. } - | AssignmentOperationExpression::BitwiseOr { left, right, .. } - | AssignmentOperationExpression::BitwiseXor { left, right, .. } - | AssignmentOperationExpression::LeftShift { left, right, .. } - | AssignmentOperationExpression::RightShift { left, right, .. } - | AssignmentOperationExpression::Coalesce { left, right, .. } - | AssignmentOperationExpression::Concat { left, right, .. } => { + Self::Assignment { left, right, .. } + | Self::Addition { left, right, .. } + | Self::Subtraction { left, right, .. } + | Self::Multiplication { left, right, .. } + | Self::Division { left, right, .. } + | Self::Modulo { left, right, .. } + | Self::Exponentiation { left, right, .. } + | Self::BitwiseAnd { left, right, .. } + | Self::BitwiseOr { left, right, .. } + | Self::BitwiseXor { left, right, .. } + | Self::LeftShift { left, right, .. } + | Self::RightShift { left, right, .. } + | Self::Coalesce { left, right, .. } + | Self::Concat { left, right, .. } => { vec![left.as_ref(), right.as_ref()] } } @@ -826,48 +813,24 @@ impl Node for AssignmentOperationExpression { fn get_description(&self) -> String { match &self { - AssignmentOperationExpression::Assignment { .. } => { - "assignment operation expression".to_string() - } - AssignmentOperationExpression::Addition { .. } => { - "addition assignment operation expression".to_string() - } - AssignmentOperationExpression::Subtraction { .. } => { - "subtraction assignment operation expression".to_string() - } - AssignmentOperationExpression::Multiplication { .. } => { + Self::Assignment { .. } => "assignment operation expression".to_string(), + Self::Addition { .. } => "addition assignment operation expression".to_string(), + Self::Subtraction { .. } => "subtraction assignment operation expression".to_string(), + Self::Multiplication { .. } => { "multiplication assignment operation expression".to_string() } - AssignmentOperationExpression::Division { .. } => { - "division assignment operation expression".to_string() - } - AssignmentOperationExpression::Modulo { .. } => { - "modulo assignment operation expression".to_string() - } - AssignmentOperationExpression::Exponentiation { .. } => { + Self::Division { .. } => "division assignment operation expression".to_string(), + Self::Modulo { .. } => "modulo assignment operation expression".to_string(), + Self::Exponentiation { .. } => { "exponentiation assignment operation expression".to_string() } - AssignmentOperationExpression::BitwiseAnd { .. } => { - "bitwise AND assignment operation expression".to_string() - } - AssignmentOperationExpression::BitwiseOr { .. } => { - "bitwise OR assignment operation expression".to_string() - } - AssignmentOperationExpression::BitwiseXor { .. } => { - "bitwise XOR assignment operation expression".to_string() - } - AssignmentOperationExpression::LeftShift { .. } => { - "left shift assignment operation expression".to_string() - } - AssignmentOperationExpression::RightShift { .. } => { - "right shift assignment operation expression".to_string() - } - AssignmentOperationExpression::Coalesce { .. } => { - "coalesce assignment operation expression".to_string() - } - AssignmentOperationExpression::Concat { .. } => { - "concat assignment operation expression".to_string() - } + Self::BitwiseAnd { .. } => "bitwise AND assignment operation expression".to_string(), + Self::BitwiseOr { .. } => "bitwise OR assignment operation expression".to_string(), + Self::BitwiseXor { .. } => "bitwise XOR assignment operation expression".to_string(), + Self::LeftShift { .. } => "left shift assignment operation expression".to_string(), + Self::RightShift { .. } => "right shift assignment operation expression".to_string(), + Self::Coalesce { .. } => "coalesce assignment operation expression".to_string(), + Self::Concat { .. } => "concat assignment operation expression".to_string(), } } } @@ -875,68 +838,58 @@ impl Node for AssignmentOperationExpression { impl Node for BitwiseOperationExpression { fn comments(&self) -> Option<&CommentGroup> { match &self { - BitwiseOperationExpression::And { comments, .. } => Some(comments), - BitwiseOperationExpression::Or { comments, .. } => Some(comments), - BitwiseOperationExpression::Xor { comments, .. } => Some(comments), - BitwiseOperationExpression::LeftShift { comments, .. } => Some(comments), - BitwiseOperationExpression::RightShift { comments, .. } => Some(comments), - BitwiseOperationExpression::Not { comments, .. } => Some(comments), + Self::And { comments, .. } => Some(comments), + Self::Or { comments, .. } => Some(comments), + Self::Xor { comments, .. } => Some(comments), + Self::LeftShift { comments, .. } => Some(comments), + Self::RightShift { comments, .. } => Some(comments), + Self::Not { comments, .. } => Some(comments), } } fn initial_position(&self) -> usize { match &self { - BitwiseOperationExpression::And { left, .. } => left.initial_position(), - BitwiseOperationExpression::Or { left, .. } => left.initial_position(), - BitwiseOperationExpression::Xor { left, .. } => left.initial_position(), - BitwiseOperationExpression::LeftShift { left, .. } => left.initial_position(), - BitwiseOperationExpression::RightShift { left, .. } => left.initial_position(), - BitwiseOperationExpression::Not { not, .. } => *not, + Self::And { left, .. } => left.initial_position(), + Self::Or { left, .. } => left.initial_position(), + Self::Xor { left, .. } => left.initial_position(), + Self::LeftShift { left, .. } => left.initial_position(), + Self::RightShift { left, .. } => left.initial_position(), + Self::Not { not, .. } => *not, } } fn final_position(&self) -> usize { match &self { - BitwiseOperationExpression::And { right, .. } => right.final_position(), - BitwiseOperationExpression::Or { right, .. } => right.final_position(), - BitwiseOperationExpression::Xor { right, .. } => right.final_position(), - BitwiseOperationExpression::LeftShift { right, .. } => right.final_position(), - BitwiseOperationExpression::RightShift { right, .. } => right.final_position(), - BitwiseOperationExpression::Not { right, .. } => right.final_position(), + Self::And { right, .. } => right.final_position(), + Self::Or { right, .. } => right.final_position(), + Self::Xor { right, .. } => right.final_position(), + Self::LeftShift { right, .. } => right.final_position(), + Self::RightShift { right, .. } => right.final_position(), + Self::Not { right, .. } => right.final_position(), } } fn children(&self) -> Vec<&dyn Node> { match &self { - BitwiseOperationExpression::And { left, right, .. } - | BitwiseOperationExpression::Or { left, right, .. } - | BitwiseOperationExpression::Xor { left, right, .. } - | BitwiseOperationExpression::LeftShift { left, right, .. } - | BitwiseOperationExpression::RightShift { left, right, .. } => { + Self::And { left, right, .. } + | Self::Or { left, right, .. } + | Self::Xor { left, right, .. } + | Self::LeftShift { left, right, .. } + | Self::RightShift { left, right, .. } => { vec![left.as_ref(), right.as_ref()] } - BitwiseOperationExpression::Not { right, .. } => vec![right.as_ref()], + Self::Not { right, .. } => vec![right.as_ref()], } } fn get_description(&self) -> String { match &self { - BitwiseOperationExpression::And { .. } => { - "bitwise AND operation expression".to_string() - } - BitwiseOperationExpression::Or { .. } => "bitwise OR operation expression".to_string(), - BitwiseOperationExpression::Xor { .. } => { - "bitwise XOR operation expression".to_string() - } - BitwiseOperationExpression::LeftShift { .. } => { - "left shift operation expression".to_string() - } - BitwiseOperationExpression::RightShift { .. } => { - "right shift operation expression".to_string() - } - BitwiseOperationExpression::Not { .. } => { - "bitwise NOT operation expression".to_string() - } + Self::And { .. } => "bitwise AND operation expression".to_string(), + Self::Or { .. } => "bitwise OR operation expression".to_string(), + Self::Xor { .. } => "bitwise XOR operation expression".to_string(), + Self::LeftShift { .. } => "left shift operation expression".to_string(), + Self::RightShift { .. } => "right shift operation expression".to_string(), + Self::Not { .. } => "bitwise NOT operation expression".to_string(), } } } @@ -944,57 +897,57 @@ impl Node for BitwiseOperationExpression { impl Node for ComparisonOperationExpression { fn comments(&self) -> Option<&CommentGroup> { match &self { - ComparisonOperationExpression::Equal { comments, .. } - | ComparisonOperationExpression::NotEqual { comments, .. } - | ComparisonOperationExpression::Identical { comments, .. } - | ComparisonOperationExpression::NotIdentical { comments, .. } - | ComparisonOperationExpression::LessThan { comments, .. } - | ComparisonOperationExpression::LessThanOrEqual { comments, .. } - | ComparisonOperationExpression::GreaterThan { comments, .. } - | ComparisonOperationExpression::GreaterThanOrEqual { comments, .. } - | ComparisonOperationExpression::Spaceship { comments, .. } => Some(comments), + Self::Equal { comments, .. } + | Self::NotEqual { comments, .. } + | Self::Identical { comments, .. } + | Self::NotIdentical { comments, .. } + | Self::LessThan { comments, .. } + | Self::LessThanOrEqual { comments, .. } + | Self::GreaterThan { comments, .. } + | Self::GreaterThanOrEqual { comments, .. } + | Self::Spaceship { comments, .. } => Some(comments), } } fn initial_position(&self) -> usize { match &self { - ComparisonOperationExpression::Equal { left, .. } - | ComparisonOperationExpression::NotEqual { left, .. } - | ComparisonOperationExpression::Identical { left, .. } - | ComparisonOperationExpression::NotIdentical { left, .. } - | ComparisonOperationExpression::LessThan { left, .. } - | ComparisonOperationExpression::LessThanOrEqual { left, .. } - | ComparisonOperationExpression::GreaterThan { left, .. } - | ComparisonOperationExpression::GreaterThanOrEqual { left, .. } - | ComparisonOperationExpression::Spaceship { left, .. } => left.initial_position(), + Self::Equal { left, .. } + | Self::NotEqual { left, .. } + | Self::Identical { left, .. } + | Self::NotIdentical { left, .. } + | Self::LessThan { left, .. } + | Self::LessThanOrEqual { left, .. } + | Self::GreaterThan { left, .. } + | Self::GreaterThanOrEqual { left, .. } + | Self::Spaceship { left, .. } => left.initial_position(), } } fn final_position(&self) -> usize { match &self { - ComparisonOperationExpression::Equal { right, .. } - | ComparisonOperationExpression::NotEqual { right, .. } - | ComparisonOperationExpression::Identical { right, .. } - | ComparisonOperationExpression::NotIdentical { right, .. } - | ComparisonOperationExpression::LessThan { right, .. } - | ComparisonOperationExpression::LessThanOrEqual { right, .. } - | ComparisonOperationExpression::GreaterThan { right, .. } - | ComparisonOperationExpression::GreaterThanOrEqual { right, .. } - | ComparisonOperationExpression::Spaceship { right, .. } => right.final_position(), + Self::Equal { right, .. } + | Self::NotEqual { right, .. } + | Self::Identical { right, .. } + | Self::NotIdentical { right, .. } + | Self::LessThan { right, .. } + | Self::LessThanOrEqual { right, .. } + | Self::GreaterThan { right, .. } + | Self::GreaterThanOrEqual { right, .. } + | Self::Spaceship { right, .. } => right.final_position(), } } fn children(&self) -> Vec<&dyn Node> { match &self { - ComparisonOperationExpression::Equal { left, right, .. } - | ComparisonOperationExpression::NotEqual { left, right, .. } - | ComparisonOperationExpression::Identical { left, right, .. } - | ComparisonOperationExpression::NotIdentical { left, right, .. } - | ComparisonOperationExpression::LessThan { left, right, .. } - | ComparisonOperationExpression::LessThanOrEqual { left, right, .. } - | ComparisonOperationExpression::GreaterThan { left, right, .. } - | ComparisonOperationExpression::GreaterThanOrEqual { left, right, .. } - | ComparisonOperationExpression::Spaceship { left, right, .. } => { + Self::Equal { left, right, .. } + | Self::NotEqual { left, right, .. } + | Self::Identical { left, right, .. } + | Self::NotIdentical { left, right, .. } + | Self::LessThan { left, right, .. } + | Self::LessThanOrEqual { left, right, .. } + | Self::GreaterThan { left, right, .. } + | Self::GreaterThanOrEqual { left, right, .. } + | Self::Spaceship { left, right, .. } => { vec![left.as_ref(), right.as_ref()] } } @@ -1002,33 +955,21 @@ impl Node for ComparisonOperationExpression { fn get_description(&self) -> String { match &self { - ComparisonOperationExpression::Equal { .. } => { - "equal comparison operation expression".to_string() - } - ComparisonOperationExpression::NotEqual { .. } => { - "not equal comparison operation expression".to_string() - } - ComparisonOperationExpression::Identical { .. } => { - "identical comparison operation expression".to_string() - } - ComparisonOperationExpression::NotIdentical { .. } => { + Self::Equal { .. } => "equal comparison operation expression".to_string(), + Self::NotEqual { .. } => "not equal comparison operation expression".to_string(), + Self::Identical { .. } => "identical comparison operation expression".to_string(), + Self::NotIdentical { .. } => { "not identical comparison operation expression".to_string() } - ComparisonOperationExpression::LessThan { .. } => { - "less than comparison operation expression".to_string() - } - ComparisonOperationExpression::LessThanOrEqual { .. } => { + Self::LessThan { .. } => "less than comparison operation expression".to_string(), + Self::LessThanOrEqual { .. } => { "less than or equal comparison operation expression".to_string() } - ComparisonOperationExpression::GreaterThan { .. } => { - "greater than comparison operation expression".to_string() - } - ComparisonOperationExpression::GreaterThanOrEqual { .. } => { + Self::GreaterThan { .. } => "greater than comparison operation expression".to_string(), + Self::GreaterThanOrEqual { .. } => { "greater than or equal comparison operation expression".to_string() } - ComparisonOperationExpression::Spaceship { .. } => { - "spaceship comparison operation expression".to_string() - } + Self::Spaceship { .. } => "spaceship comparison operation expression".to_string(), } } } @@ -1036,47 +977,42 @@ impl Node for ComparisonOperationExpression { impl Node for LogicalOperationExpression { fn comments(&self) -> Option<&CommentGroup> { match &self { - LogicalOperationExpression::And { comments, .. } => Some(comments), - LogicalOperationExpression::Or { comments, .. } => Some(comments), - LogicalOperationExpression::Not { comments, .. } => Some(comments), + Self::And { comments, .. } => Some(comments), + Self::Or { comments, .. } => Some(comments), + Self::Not { comments, .. } => Some(comments), } } fn initial_position(&self) -> usize { match &self { - LogicalOperationExpression::And { left, .. } => left.initial_position(), - LogicalOperationExpression::Or { left, .. } => left.initial_position(), - LogicalOperationExpression::Not { bang, .. } => *bang, + Self::And { left, .. } => left.initial_position(), + Self::Or { left, .. } => left.initial_position(), + Self::Not { bang, .. } => *bang, } } fn final_position(&self) -> usize { match &self { - LogicalOperationExpression::And { right, .. } => right.final_position(), - LogicalOperationExpression::Or { right, .. } => right.final_position(), - LogicalOperationExpression::Not { right, .. } => right.final_position(), + Self::And { right, .. } => right.final_position(), + Self::Or { right, .. } => right.final_position(), + Self::Not { right, .. } => right.final_position(), } } fn children(&self) -> Vec<&dyn Node> { match &self { - LogicalOperationExpression::And { left, right, .. } - | LogicalOperationExpression::Or { left, right, .. } => { + Self::And { left, right, .. } | Self::Or { left, right, .. } => { vec![left.as_ref(), right.as_ref()] } - LogicalOperationExpression::Not { right, .. } => vec![right.as_ref()], + Self::Not { right, .. } => vec![right.as_ref()], } } fn get_description(&self) -> String { match &self { - LogicalOperationExpression::And { .. } => { - "logical AND operation expression".to_string() - } - LogicalOperationExpression::Or { .. } => "logical OR operation expression".to_string(), - LogicalOperationExpression::Not { .. } => { - "logical NOT operation expression".to_string() - } + Self::And { .. } => "logical AND operation expression".to_string(), + Self::Or { .. } => "logical OR operation expression".to_string(), + Self::Not { .. } => "logical NOT operation expression".to_string(), } } } @@ -1084,25 +1020,25 @@ impl Node for LogicalOperationExpression { impl Node for StringOperationExpression { fn comments(&self) -> Option<&CommentGroup> { match &self { - StringOperationExpression::Concat { comments, .. } => Some(comments), + Self::Concat { comments, .. } => Some(comments), } } fn initial_position(&self) -> usize { match &self { - StringOperationExpression::Concat { left, .. } => left.initial_position(), + Self::Concat { left, .. } => left.initial_position(), } } fn final_position(&self) -> usize { match &self { - StringOperationExpression::Concat { right, .. } => right.final_position(), + Self::Concat { right, .. } => right.final_position(), } } fn children(&self) -> Vec<&dyn Node> { match &self { - StringOperationExpression::Concat { left, right, .. } => { + Self::Concat { left, right, .. } => { vec![left.as_ref(), right.as_ref()] } } @@ -1110,9 +1046,7 @@ impl Node for StringOperationExpression { fn get_description(&self) -> String { match &self { - StringOperationExpression::Concat { .. } => { - "string concatenation operation expression".to_string() - } + Self::Concat { .. } => "string concatenation operation expression".to_string(), } } } @@ -1120,55 +1054,54 @@ impl Node for StringOperationExpression { impl Node for ArrayOperationExpression { fn comments(&self) -> Option<&CommentGroup> { match &self { - ArrayOperationExpression::Access { comments, .. } - | ArrayOperationExpression::Push { comments, .. } - | ArrayOperationExpression::Isset { comments, .. } - | ArrayOperationExpression::Unset { comments, .. } - | ArrayOperationExpression::In { comments, .. } => Some(comments), + Self::Access { comments, .. } + | Self::Push { comments, .. } + | Self::Isset { comments, .. } + | Self::Unset { comments, .. } + | Self::In { comments, .. } => Some(comments), } } fn initial_position(&self) -> usize { match &self { - ArrayOperationExpression::Access { array, .. } - | ArrayOperationExpression::Push { array, .. } => array.initial_position(), - ArrayOperationExpression::Isset { isset, .. } => isset.initial_position(), - ArrayOperationExpression::Unset { unset, .. } => unset.initial_position(), - ArrayOperationExpression::In { item, .. } => item.initial_position(), + Self::Access { array, .. } | Self::Push { array, .. } => array.initial_position(), + Self::Isset { isset, .. } => isset.initial_position(), + Self::Unset { unset, .. } => unset.initial_position(), + Self::In { item, .. } => item.initial_position(), } } fn final_position(&self) -> usize { match &self { - ArrayOperationExpression::Access { right_bracket, .. } - | ArrayOperationExpression::Push { right_bracket, .. } => right_bracket + 1, - ArrayOperationExpression::Isset { item, .. } - | ArrayOperationExpression::Unset { item, .. } => item.final_position(), - ArrayOperationExpression::In { array, .. } => array.final_position(), + Self::Access { right_bracket, .. } | Self::Push { right_bracket, .. } => { + right_bracket + 1 + } + Self::Isset { item, .. } | Self::Unset { item, .. } => item.final_position(), + Self::In { array, .. } => array.final_position(), } } fn children(&self) -> Vec<&dyn Node> { match &self { - ArrayOperationExpression::Access { array, index, .. } => { + Self::Access { array, index, .. } => { vec![array.as_ref(), index.as_ref()] } - ArrayOperationExpression::Push { array, .. } => { + Self::Push { array, .. } => { vec![array.as_ref()] } - ArrayOperationExpression::Isset { + Self::Isset { isset: keyword, item, .. } - | ArrayOperationExpression::Unset { + | Self::Unset { unset: keyword, item, .. } => { vec![keyword, item.as_ref()] } - ArrayOperationExpression::In { + Self::In { item, r#in, array, .. } => { vec![item.as_ref(), r#in, array.as_ref()] @@ -1178,17 +1111,11 @@ impl Node for ArrayOperationExpression { fn get_description(&self) -> String { match &self { - ArrayOperationExpression::Access { .. } => { - "array access operation expression".to_string() - } - ArrayOperationExpression::Push { .. } => "array push operation expression".to_string(), - ArrayOperationExpression::Isset { .. } => { - "array isset operation expression".to_string() - } - ArrayOperationExpression::Unset { .. } => { - "array unset operation expression".to_string() - } - ArrayOperationExpression::In { .. } => "array in operation expression".to_string(), + Self::Access { .. } => "array access operation expression".to_string(), + Self::Push { .. } => "array push operation expression".to_string(), + Self::Isset { .. } => "array isset operation expression".to_string(), + Self::Unset { .. } => "array unset operation expression".to_string(), + Self::In { .. } => "array in operation expression".to_string(), } } } @@ -1196,25 +1123,25 @@ impl Node for ArrayOperationExpression { impl Node for CoalesceOperationExpression { fn comments(&self) -> Option<&CommentGroup> { match &self { - CoalesceOperationExpression::Coalesce { comments, .. } => Some(comments), + Self::Coalesce { comments, .. } => Some(comments), } } fn initial_position(&self) -> usize { match &self { - CoalesceOperationExpression::Coalesce { left, .. } => left.initial_position(), + Self::Coalesce { left, .. } => left.initial_position(), } } fn final_position(&self) -> usize { match &self { - CoalesceOperationExpression::Coalesce { right, .. } => right.final_position(), + Self::Coalesce { right, .. } => right.final_position(), } } fn children(&self) -> Vec<&dyn Node> { match &self { - CoalesceOperationExpression::Coalesce { left, right, .. } => { + Self::Coalesce { left, right, .. } => { vec![left.as_ref(), right.as_ref()] } } @@ -1222,9 +1149,7 @@ impl Node for CoalesceOperationExpression { fn get_description(&self) -> String { match &self { - CoalesceOperationExpression::Coalesce { .. } => { - "coalesce operation expression".to_string() - } + Self::Coalesce { .. } => "coalesce operation expression".to_string(), } } } @@ -1232,48 +1157,42 @@ impl Node for CoalesceOperationExpression { impl Node for TernaryOperationExpression { fn comments(&self) -> Option<&CommentGroup> { match &self { - TernaryOperationExpression::Ternary { comments, .. } => Some(comments), - TernaryOperationExpression::ShortTernary { comments, .. } => Some(comments), - TernaryOperationExpression::ImplicitShortTernary { comments, .. } => Some(comments), + Self::Ternary { comments, .. } => Some(comments), + Self::ShortTernary { comments, .. } => Some(comments), + Self::ImplicitShortTernary { comments, .. } => Some(comments), } } fn initial_position(&self) -> usize { match &self { - TernaryOperationExpression::Ternary { condition, .. } => condition.initial_position(), - TernaryOperationExpression::ShortTernary { condition, .. } => { - condition.initial_position() - } - TernaryOperationExpression::ImplicitShortTernary { condition, .. } => { - condition.initial_position() - } + Self::Ternary { condition, .. } => condition.initial_position(), + Self::ShortTernary { condition, .. } => condition.initial_position(), + Self::ImplicitShortTernary { condition, .. } => condition.initial_position(), } } fn final_position(&self) -> usize { match &self { - TernaryOperationExpression::Ternary { if_false, .. } => if_false.final_position(), - TernaryOperationExpression::ShortTernary { if_false, .. } => if_false.final_position(), - TernaryOperationExpression::ImplicitShortTernary { if_false, .. } => { - if_false.final_position() - } + Self::Ternary { if_false, .. } => if_false.final_position(), + Self::ShortTernary { if_false, .. } => if_false.final_position(), + Self::ImplicitShortTernary { if_false, .. } => if_false.final_position(), } } fn children(&self) -> Vec<&dyn Node> { match &self { - TernaryOperationExpression::Ternary { + Self::Ternary { condition, if_true, if_false, .. } => vec![condition.as_ref(), if_true.as_ref(), if_false.as_ref()], - TernaryOperationExpression::ShortTernary { + Self::ShortTernary { condition, if_false, .. } => vec![condition.as_ref(), if_false.as_ref()], - TernaryOperationExpression::ImplicitShortTernary { + Self::ImplicitShortTernary { condition, if_false, .. @@ -1283,13 +1202,9 @@ impl Node for TernaryOperationExpression { fn get_description(&self) -> String { match &self { - TernaryOperationExpression::Ternary { .. } => { - "ternary operation expression".to_string() - } - TernaryOperationExpression::ShortTernary { .. } => { - "short ternary operation expression".to_string() - } - TernaryOperationExpression::ImplicitShortTernary { .. } => { + Self::Ternary { .. } => "ternary operation expression".to_string(), + Self::ShortTernary { .. } => "short ternary operation expression".to_string(), + Self::ImplicitShortTernary { .. } => { "implicit short ternary operation expression".to_string() } } @@ -1299,46 +1214,46 @@ impl Node for TernaryOperationExpression { impl Node for TypeOperationExpression { fn comments(&self) -> Option<&CommentGroup> { match &self { - TypeOperationExpression::Instanceof { comments, .. } => Some(comments), - TypeOperationExpression::Is { comments, .. } => Some(comments), - TypeOperationExpression::Into { comments, .. } => Some(comments), - TypeOperationExpression::As { comments, .. } => Some(comments), + Self::Instanceof { comments, .. } => Some(comments), + Self::Is { comments, .. } => Some(comments), + Self::Into { comments, .. } => Some(comments), + Self::As { comments, .. } => Some(comments), } } fn initial_position(&self) -> usize { match &self { - TypeOperationExpression::Instanceof { left, .. } => left.initial_position(), - TypeOperationExpression::Is { left, .. } => left.initial_position(), - TypeOperationExpression::Into { left, .. } => left.initial_position(), - TypeOperationExpression::As { left, .. } => left.initial_position(), + Self::Instanceof { left, .. } => left.initial_position(), + Self::Is { left, .. } => left.initial_position(), + Self::Into { left, .. } => left.initial_position(), + Self::As { left, .. } => left.initial_position(), } } fn final_position(&self) -> usize { match &self { - TypeOperationExpression::Instanceof { right, .. } => right.final_position(), - TypeOperationExpression::Is { right, .. } => right.final_position(), - TypeOperationExpression::Into { right, .. } => right.final_position(), - TypeOperationExpression::As { right, .. } => right.final_position(), + Self::Instanceof { right, .. } => right.final_position(), + Self::Is { right, .. } => right.final_position(), + Self::Into { right, .. } => right.final_position(), + Self::As { right, .. } => right.final_position(), } } fn children(&self) -> Vec<&dyn Node> { match &self { - TypeOperationExpression::Instanceof { + Self::Instanceof { left, instanceof, right, .. } => vec![left.as_ref(), instanceof, right], - TypeOperationExpression::Is { + Self::Is { left, is, right, .. } => vec![left.as_ref(), is, right], - TypeOperationExpression::Into { + Self::Into { left, into, right, .. } => vec![left.as_ref(), into, right], - TypeOperationExpression::As { + Self::As { left, r#as, right, .. } => vec![left.as_ref(), r#as, right], } @@ -1346,12 +1261,10 @@ impl Node for TypeOperationExpression { fn get_description(&self) -> String { match &self { - TypeOperationExpression::Instanceof { .. } => { - "instanceof type operation expression".to_string() - } - TypeOperationExpression::Is { .. } => "is type operation expression".to_string(), - TypeOperationExpression::Into { .. } => "into type operation expression".to_string(), - TypeOperationExpression::As { .. } => "as type operation expression".to_string(), + Self::Instanceof { .. } => "instanceof type operation expression".to_string(), + Self::Is { .. } => "is type operation expression".to_string(), + Self::Into { .. } => "into type operation expression".to_string(), + Self::As { .. } => "as type operation expression".to_string(), } } } @@ -1359,38 +1272,38 @@ impl Node for TypeOperationExpression { impl Node for GeneratorOperationExpression { fn comments(&self) -> Option<&CommentGroup> { match &self { - GeneratorOperationExpression::Yield { comments, .. } => Some(comments), - GeneratorOperationExpression::YieldValue { comments, .. } => Some(comments), - GeneratorOperationExpression::YieldKeyValue { comments, .. } => Some(comments), - GeneratorOperationExpression::YieldFrom { comments, .. } => Some(comments), + Self::Yield { comments, .. } => Some(comments), + Self::YieldValue { comments, .. } => Some(comments), + Self::YieldKeyValue { comments, .. } => Some(comments), + Self::YieldFrom { comments, .. } => Some(comments), } } fn initial_position(&self) -> usize { match &self { - GeneratorOperationExpression::Yield { r#yield, .. } - | GeneratorOperationExpression::YieldValue { r#yield, .. } - | GeneratorOperationExpression::YieldKeyValue { r#yield, .. } - | GeneratorOperationExpression::YieldFrom { r#yield, .. } => r#yield.initial_position(), + Self::Yield { r#yield, .. } + | Self::YieldValue { r#yield, .. } + | Self::YieldKeyValue { r#yield, .. } + | Self::YieldFrom { r#yield, .. } => r#yield.initial_position(), } } fn final_position(&self) -> usize { match &self { - GeneratorOperationExpression::Yield { r#yield, .. } => r#yield.final_position(), - GeneratorOperationExpression::YieldValue { value, .. } => value.final_position(), - GeneratorOperationExpression::YieldKeyValue { value, .. } => value.final_position(), - GeneratorOperationExpression::YieldFrom { value, .. } => value.final_position(), + Self::Yield { r#yield, .. } => r#yield.final_position(), + Self::YieldValue { value, .. } => value.final_position(), + Self::YieldKeyValue { value, .. } => value.final_position(), + Self::YieldFrom { value, .. } => value.final_position(), } } fn children(&self) -> Vec<&dyn Node> { match &self { - GeneratorOperationExpression::Yield { r#yield, .. } => vec![r#yield], - GeneratorOperationExpression::YieldValue { r#yield, value, .. } => { + Self::Yield { r#yield, .. } => vec![r#yield], + Self::YieldValue { r#yield, value, .. } => { vec![r#yield, value.as_ref()] } - GeneratorOperationExpression::YieldKeyValue { + Self::YieldKeyValue { r#yield, key, value, @@ -1398,7 +1311,7 @@ impl Node for GeneratorOperationExpression { } => { vec![r#yield, key.as_ref(), value.as_ref()] } - GeneratorOperationExpression::YieldFrom { + Self::YieldFrom { r#yield, from, value, @@ -1409,18 +1322,12 @@ impl Node for GeneratorOperationExpression { fn get_description(&self) -> String { match &self { - GeneratorOperationExpression::Yield { .. } => { - "yield generator operation expression".to_string() - } - GeneratorOperationExpression::YieldValue { .. } => { - "yield value generator operation expression".to_string() - } - GeneratorOperationExpression::YieldKeyValue { .. } => { + Self::Yield { .. } => "yield generator operation expression".to_string(), + Self::YieldValue { .. } => "yield value generator operation expression".to_string(), + Self::YieldKeyValue { .. } => { "yield key value generator operation expression".to_string() } - GeneratorOperationExpression::YieldFrom { .. } => { - "yield from generator operation expression".to_string() - } + Self::YieldFrom { .. } => "yield from generator operation expression".to_string(), } } } @@ -1428,33 +1335,31 @@ impl Node for GeneratorOperationExpression { impl Node for ExceptionOperationExpression { fn comments(&self) -> Option<&CommentGroup> { match &self { - ExceptionOperationExpression::Throw { comments, .. } => Some(comments), + Self::Throw { comments, .. } => Some(comments), } } fn initial_position(&self) -> usize { match &self { - ExceptionOperationExpression::Throw { throw, .. } => throw.initial_position(), + Self::Throw { throw, .. } => throw.initial_position(), } } fn final_position(&self) -> usize { match &self { - ExceptionOperationExpression::Throw { value, .. } => value.final_position(), + Self::Throw { value, .. } => value.final_position(), } } fn children(&self) -> Vec<&dyn Node> { match &self { - ExceptionOperationExpression::Throw { throw, value, .. } => vec![throw, value.as_ref()], + Self::Throw { throw, value, .. } => vec![throw, value.as_ref()], } } fn get_description(&self) -> String { match &self { - ExceptionOperationExpression::Throw { .. } => { - "throw exception operation expression".to_string() - } + Self::Throw { .. } => "throw exception operation expression".to_string(), } } } @@ -1462,60 +1367,48 @@ impl Node for ExceptionOperationExpression { impl Node for ObjectOperationExpression { fn comments(&self) -> Option<&CommentGroup> { match &self { - ObjectOperationExpression::Clone { comments, .. } => Some(comments), - ObjectOperationExpression::MethodCall { comments, .. } => Some(comments), - ObjectOperationExpression::NullsafeMethodCall { comments, .. } => Some(comments), - ObjectOperationExpression::MethodClosureCreation { comments, .. } => Some(comments), - ObjectOperationExpression::PropertyFetch { comments, .. } => Some(comments), - ObjectOperationExpression::NullsafePropertyFetch { comments, .. } => Some(comments), + Self::Clone { comments, .. } => Some(comments), + Self::MethodCall { comments, .. } => Some(comments), + Self::NullsafeMethodCall { comments, .. } => Some(comments), + Self::MethodClosureCreation { comments, .. } => Some(comments), + Self::PropertyFetch { comments, .. } => Some(comments), + Self::NullsafePropertyFetch { comments, .. } => Some(comments), } } fn initial_position(&self) -> usize { match &self { - ObjectOperationExpression::Clone { clone, .. } => clone.initial_position(), - ObjectOperationExpression::MethodCall { object, .. } => object.initial_position(), - ObjectOperationExpression::NullsafeMethodCall { object, .. } => { - object.initial_position() - } - ObjectOperationExpression::MethodClosureCreation { object, .. } => { - object.initial_position() - } - ObjectOperationExpression::PropertyFetch { object, .. } => object.initial_position(), - ObjectOperationExpression::NullsafePropertyFetch { object, .. } => { - object.initial_position() - } + Self::Clone { clone, .. } => clone.initial_position(), + Self::MethodCall { object, .. } => object.initial_position(), + Self::NullsafeMethodCall { object, .. } => object.initial_position(), + Self::MethodClosureCreation { object, .. } => object.initial_position(), + Self::PropertyFetch { object, .. } => object.initial_position(), + Self::NullsafePropertyFetch { object, .. } => object.initial_position(), } } fn final_position(&self) -> usize { match &self { - ObjectOperationExpression::Clone { object, .. } => object.final_position(), - ObjectOperationExpression::MethodCall { arguments, .. } => arguments.final_position(), - ObjectOperationExpression::NullsafeMethodCall { arguments, .. } => { - arguments.final_position() - } - ObjectOperationExpression::MethodClosureCreation { placeholder, .. } => { - placeholder.final_position() - } - ObjectOperationExpression::PropertyFetch { property, .. } => property.final_position(), - ObjectOperationExpression::NullsafePropertyFetch { property, .. } => { - property.final_position() - } + Self::Clone { object, .. } => object.final_position(), + Self::MethodCall { arguments, .. } => arguments.final_position(), + Self::NullsafeMethodCall { arguments, .. } => arguments.final_position(), + Self::MethodClosureCreation { placeholder, .. } => placeholder.final_position(), + Self::PropertyFetch { property, .. } => property.final_position(), + Self::NullsafePropertyFetch { property, .. } => property.final_position(), } } fn children(&self) -> Vec<&dyn Node> { match &self { - ObjectOperationExpression::Clone { clone, object, .. } => vec![clone, object.as_ref()], - ObjectOperationExpression::MethodCall { + Self::Clone { clone, object, .. } => vec![clone, object.as_ref()], + Self::MethodCall { object, method, generics, arguments, .. } - | ObjectOperationExpression::NullsafeMethodCall { + | Self::NullsafeMethodCall { object, method, generics, @@ -1531,7 +1424,7 @@ impl Node for ObjectOperationExpression { children } - ObjectOperationExpression::MethodClosureCreation { + Self::MethodClosureCreation { object, method, generics, @@ -1547,10 +1440,10 @@ impl Node for ObjectOperationExpression { children } - ObjectOperationExpression::PropertyFetch { + Self::PropertyFetch { object, property, .. } - | ObjectOperationExpression::NullsafePropertyFetch { + | Self::NullsafePropertyFetch { object, property, .. } => { vec![object.as_ref(), property] @@ -1560,22 +1453,16 @@ impl Node for ObjectOperationExpression { fn get_description(&self) -> String { match &self { - ObjectOperationExpression::Clone { .. } => { - "object clone operation expression".to_string() - } - ObjectOperationExpression::MethodCall { .. } => { - "object method call operation expression".to_string() - } - ObjectOperationExpression::NullsafeMethodCall { .. } => { + Self::Clone { .. } => "object clone operation expression".to_string(), + Self::MethodCall { .. } => "object method call operation expression".to_string(), + Self::NullsafeMethodCall { .. } => { "object nullsafe method call operation expression".to_string() } - ObjectOperationExpression::MethodClosureCreation { .. } => { + Self::MethodClosureCreation { .. } => { "object method closure creation operation expression".to_string() } - ObjectOperationExpression::PropertyFetch { .. } => { - "object property fetch operation expression".to_string() - } - ObjectOperationExpression::NullsafePropertyFetch { .. } => { + Self::PropertyFetch { .. } => "object property fetch operation expression".to_string(), + Self::NullsafePropertyFetch { .. } => { "object nullsafe property fetch operation expression".to_string() } } @@ -1585,48 +1472,36 @@ impl Node for ObjectOperationExpression { impl Node for ClassOperationInitializationClassExpression { fn comments(&self) -> Option<&CommentGroup> { match &self { - ClassOperationInitializationClassExpression::Identifier(_) => None, - ClassOperationInitializationClassExpression::Variable(_) => None, + Self::Identifier(_) => None, + Self::Variable(_) => None, } } fn initial_position(&self) -> usize { match &self { - ClassOperationInitializationClassExpression::Identifier(identifier) => { - identifier.initial_position() - } - ClassOperationInitializationClassExpression::Variable(variable) => { - variable.initial_position() - } + Self::Identifier(identifier) => identifier.initial_position(), + Self::Variable(variable) => variable.initial_position(), } } fn final_position(&self) -> usize { match &self { - ClassOperationInitializationClassExpression::Identifier(identifier) => { - identifier.final_position() - } - ClassOperationInitializationClassExpression::Variable(variable) => { - variable.final_position() - } + Self::Identifier(identifier) => identifier.final_position(), + Self::Variable(variable) => variable.final_position(), } } fn children(&self) -> Vec<&dyn Node> { match &self { - ClassOperationInitializationClassExpression::Identifier(identifier) => vec![identifier], - ClassOperationInitializationClassExpression::Variable(variable) => vec![variable], + Self::Identifier(identifier) => vec![identifier], + Self::Variable(variable) => vec![variable], } } fn get_description(&self) -> String { match &self { - ClassOperationInitializationClassExpression::Identifier(identifier) => { - identifier.get_description() - } - ClassOperationInitializationClassExpression::Variable(variable) => { - variable.get_description() - } + Self::Identifier(identifier) => identifier.get_description(), + Self::Variable(variable) => variable.get_description(), } } } @@ -1634,56 +1509,42 @@ impl Node for ClassOperationInitializationClassExpression { impl Node for ClassOperationExpression { fn comments(&self) -> Option<&CommentGroup> { match &self { - ClassOperationExpression::Initialization { comments, .. } => Some(comments), - ClassOperationExpression::AnonymousInitialization { comments, .. } => Some(comments), - ClassOperationExpression::StaticMethodCall { comments, .. } => Some(comments), - ClassOperationExpression::StaticMethodClosureCreation { comments, .. } => { - Some(comments) - } - ClassOperationExpression::StaticPropertyFetch { comments, .. } => Some(comments), - ClassOperationExpression::ConstantFetch { comments, .. } => Some(comments), + Self::Initialization { comments, .. } => Some(comments), + Self::AnonymousInitialization { comments, .. } => Some(comments), + Self::StaticMethodCall { comments, .. } => Some(comments), + Self::StaticMethodClosureCreation { comments, .. } => Some(comments), + Self::StaticPropertyFetch { comments, .. } => Some(comments), + Self::ConstantFetch { comments, .. } => Some(comments), } } fn initial_position(&self) -> usize { match &self { - ClassOperationExpression::Initialization { new, .. } + Self::Initialization { new, .. } | ClassOperationExpression::AnonymousInitialization { new, .. } => { new.initial_position() } - ClassOperationExpression::StaticMethodCall { class, .. } => class.initial_position(), - ClassOperationExpression::StaticMethodClosureCreation { class, .. } => { - class.initial_position() - } - ClassOperationExpression::StaticPropertyFetch { class, .. } => class.initial_position(), - ClassOperationExpression::ConstantFetch { class, .. } => class.initial_position(), + Self::StaticMethodCall { class, .. } => class.initial_position(), + Self::StaticMethodClosureCreation { class, .. } => class.initial_position(), + Self::StaticPropertyFetch { class, .. } => class.initial_position(), + Self::ConstantFetch { class, .. } => class.initial_position(), } } fn final_position(&self) -> usize { match &self { - ClassOperationExpression::Initialization { arguments, .. } => { - arguments.final_position() - } - ClassOperationExpression::AnonymousInitialization { class, .. } => { - class.final_position() - } - ClassOperationExpression::StaticMethodCall { arguments, .. } => { - arguments.final_position() - } - ClassOperationExpression::StaticMethodClosureCreation { placeholder, .. } => { - placeholder.final_position() - } - ClassOperationExpression::StaticPropertyFetch { property, .. } => { - property.final_position() - } - ClassOperationExpression::ConstantFetch { constant, .. } => constant.final_position(), + Self::Initialization { arguments, .. } => arguments.final_position(), + Self::AnonymousInitialization { class, .. } => class.final_position(), + Self::StaticMethodCall { arguments, .. } => arguments.final_position(), + Self::StaticMethodClosureCreation { placeholder, .. } => placeholder.final_position(), + Self::StaticPropertyFetch { property, .. } => property.final_position(), + Self::ConstantFetch { constant, .. } => constant.final_position(), } } fn children(&self) -> Vec<&dyn Node> { match &self { - ClassOperationExpression::Initialization { + Self::Initialization { new, class, generics, @@ -1699,10 +1560,10 @@ impl Node for ClassOperationExpression { children } - ClassOperationExpression::AnonymousInitialization { new, class, .. } => { + Self::AnonymousInitialization { new, class, .. } => { vec![new, class] } - ClassOperationExpression::StaticMethodCall { + Self::StaticMethodCall { class, method, generics, @@ -1718,7 +1579,7 @@ impl Node for ClassOperationExpression { children } - ClassOperationExpression::StaticMethodClosureCreation { + Self::StaticMethodClosureCreation { class, generics, method, @@ -1734,12 +1595,12 @@ impl Node for ClassOperationExpression { children } - ClassOperationExpression::StaticPropertyFetch { + Self::StaticPropertyFetch { class, property, .. } => { vec![class.as_ref(), property] } - ClassOperationExpression::ConstantFetch { + Self::ConstantFetch { class, constant, .. } => { vec![class.as_ref(), constant] @@ -1749,24 +1610,20 @@ impl Node for ClassOperationExpression { fn get_description(&self) -> String { match &self { - ClassOperationExpression::Initialization { .. } => { - "class initialization operation expression".to_string() - } - ClassOperationExpression::AnonymousInitialization { .. } => { + Self::Initialization { .. } => "class initialization operation expression".to_string(), + Self::AnonymousInitialization { .. } => { "class anonymous initialization operation expression".to_string() } - ClassOperationExpression::StaticMethodCall { .. } => { + Self::StaticMethodCall { .. } => { "class static method call operation expression".to_string() } - ClassOperationExpression::StaticMethodClosureCreation { .. } => { + Self::StaticMethodClosureCreation { .. } => { "class static method closure creation operation expression".to_string() } - ClassOperationExpression::StaticPropertyFetch { .. } => { + Self::StaticPropertyFetch { .. } => { "class static property fetch operation expression".to_string() } - ClassOperationExpression::ConstantFetch { .. } => { - "class constant fetch operation expression".to_string() - } + Self::ConstantFetch { .. } => "class constant fetch operation expression".to_string(), } } } @@ -1774,32 +1631,28 @@ impl Node for ClassOperationExpression { impl Node for FunctionOperationExpression { fn comments(&self) -> Option<&CommentGroup> { match &self { - FunctionOperationExpression::Call { comments, .. } => Some(comments), - FunctionOperationExpression::ClosureCreation { comments, .. } => Some(comments), + Self::Call { comments, .. } => Some(comments), + Self::ClosureCreation { comments, .. } => Some(comments), } } fn initial_position(&self) -> usize { match &self { - FunctionOperationExpression::Call { function, .. } => function.initial_position(), - FunctionOperationExpression::ClosureCreation { function, .. } => { - function.initial_position() - } + Self::Call { function, .. } => function.initial_position(), + Self::ClosureCreation { function, .. } => function.initial_position(), } } fn final_position(&self) -> usize { match &self { - FunctionOperationExpression::Call { arguments, .. } => arguments.final_position(), - FunctionOperationExpression::ClosureCreation { placeholder, .. } => { - placeholder.final_position() - } + Self::Call { arguments, .. } => arguments.final_position(), + Self::ClosureCreation { placeholder, .. } => placeholder.final_position(), } } fn children(&self) -> Vec<&dyn Node> { match &self { - FunctionOperationExpression::Call { + Self::Call { function, generics, arguments, @@ -1814,7 +1667,7 @@ impl Node for FunctionOperationExpression { children } - FunctionOperationExpression::ClosureCreation { + Self::ClosureCreation { function, generics, placeholder, @@ -1834,10 +1687,8 @@ impl Node for FunctionOperationExpression { fn get_description(&self) -> String { match &self { - FunctionOperationExpression::Call { .. } => { - "function call operation expression".to_string() - } - FunctionOperationExpression::ClosureCreation { .. } => { + Self::Call { .. } => "function call operation expression".to_string(), + Self::ClosureCreation { .. } => { "function closure creation operation expression".to_string() } } @@ -1847,43 +1698,41 @@ impl Node for FunctionOperationExpression { impl Node for AsyncOperationExpression { fn comments(&self) -> Option<&CommentGroup> { match &self { - AsyncOperationExpression::Await { comments, .. } => Some(comments), - AsyncOperationExpression::Async { comments, .. } => Some(comments), - AsyncOperationExpression::Concurrently { comments, .. } => Some(comments), + Self::Await { comments, .. } => Some(comments), + Self::Async { comments, .. } => Some(comments), + Self::Concurrently { comments, .. } => Some(comments), } } fn initial_position(&self) -> usize { match &self { - AsyncOperationExpression::Await { r#await, .. } => r#await.initial_position(), - AsyncOperationExpression::Async { r#async, .. } => r#async.initial_position(), - AsyncOperationExpression::Concurrently { concurrently, .. } => { - concurrently.initial_position() - } + Self::Await { r#await, .. } => r#await.initial_position(), + Self::Async { r#async, .. } => r#async.initial_position(), + Self::Concurrently { concurrently, .. } => concurrently.initial_position(), } } fn final_position(&self) -> usize { match &self { - AsyncOperationExpression::Await { expression, .. } => expression.final_position(), - AsyncOperationExpression::Async { expression, .. } => expression.final_position(), - AsyncOperationExpression::Concurrently { right_brace, .. } => right_brace + 1, + Self::Await { expression, .. } => expression.final_position(), + Self::Async { expression, .. } => expression.final_position(), + Self::Concurrently { right_brace, .. } => right_brace + 1, } } fn children(&self) -> Vec<&dyn Node> { match &self { - AsyncOperationExpression::Await { + Self::Await { r#await, expression, .. } => vec![r#await, expression.as_ref()], - AsyncOperationExpression::Async { + Self::Async { r#async, expression, .. } => vec![r#async, expression.as_ref()], - AsyncOperationExpression::Concurrently { + Self::Concurrently { concurrently, expressions, .. @@ -1900,13 +1749,9 @@ impl Node for AsyncOperationExpression { fn get_description(&self) -> String { match &self { - AsyncOperationExpression::Await { .. } => { - "async await operation expression".to_string() - } - AsyncOperationExpression::Async { .. } => "async operation expression".to_string(), - AsyncOperationExpression::Concurrently { .. } => { - "async concurrently operation expression".to_string() - } + Self::Await { .. } => "async await operation expression".to_string(), + Self::Async { .. } => "async operation expression".to_string(), + Self::Concurrently { .. } => "async concurrently operation expression".to_string(), } } } @@ -1914,66 +1759,62 @@ impl Node for AsyncOperationExpression { impl Node for RangeOperationExpression { fn comments(&self) -> Option<&CommentGroup> { match &self { - RangeOperationExpression::Between { comments, .. } => Some(comments), - RangeOperationExpression::BetweenInclusive { comments, .. } => Some(comments), - RangeOperationExpression::To { comments, .. } => Some(comments), - RangeOperationExpression::ToInclusive { comments, .. } => Some(comments), - RangeOperationExpression::From { comments, .. } => Some(comments), - RangeOperationExpression::Full { comments, .. } => Some(comments), + Self::Between { comments, .. } => Some(comments), + Self::BetweenInclusive { comments, .. } => Some(comments), + Self::To { comments, .. } => Some(comments), + Self::ToInclusive { comments, .. } => Some(comments), + Self::From { comments, .. } => Some(comments), + Self::Full { comments, .. } => Some(comments), } } fn initial_position(&self) -> usize { match &self { - RangeOperationExpression::Between { from, .. } => from.initial_position(), - RangeOperationExpression::BetweenInclusive { from, .. } => from.initial_position(), - RangeOperationExpression::To { double_dot, .. } => *double_dot, - RangeOperationExpression::ToInclusive { double_dot, .. } => *double_dot, - RangeOperationExpression::From { from, .. } => from.initial_position(), - RangeOperationExpression::Full { double_dot, .. } => *double_dot, + Self::Between { from, .. } => from.initial_position(), + Self::BetweenInclusive { from, .. } => from.initial_position(), + Self::To { double_dot, .. } => *double_dot, + Self::ToInclusive { double_dot, .. } => *double_dot, + Self::From { from, .. } => from.initial_position(), + Self::Full { double_dot, .. } => *double_dot, } } fn final_position(&self) -> usize { match &self { - RangeOperationExpression::Between { to, .. } => to.final_position(), - RangeOperationExpression::BetweenInclusive { to, .. } => to.final_position(), - RangeOperationExpression::To { to, .. } => to.final_position(), - RangeOperationExpression::ToInclusive { to, .. } => to.final_position(), - RangeOperationExpression::From { double_dot, .. } => *double_dot, - RangeOperationExpression::Full { double_dot, .. } => *double_dot, + Self::Between { to, .. } => to.final_position(), + Self::BetweenInclusive { to, .. } => to.final_position(), + Self::To { to, .. } => to.final_position(), + Self::ToInclusive { to, .. } => to.final_position(), + Self::From { double_dot, .. } => *double_dot, + Self::Full { double_dot, .. } => *double_dot, } } fn children(&self) -> Vec<&dyn Node> { match &self { - RangeOperationExpression::Between { from, to, .. } => { + Self::Between { from, to, .. } => { vec![from.as_ref(), to.as_ref()] } - RangeOperationExpression::BetweenInclusive { from, to, .. } => { + Self::BetweenInclusive { from, to, .. } => { vec![from.as_ref(), to.as_ref()] } - RangeOperationExpression::To { to, .. } => vec![to.as_ref()], - RangeOperationExpression::ToInclusive { to, .. } => vec![to.as_ref()], - RangeOperationExpression::From { from, .. } => vec![from.as_ref()], - RangeOperationExpression::Full { .. } => vec![], + Self::To { to, .. } => vec![to.as_ref()], + Self::ToInclusive { to, .. } => vec![to.as_ref()], + Self::From { from, .. } => vec![from.as_ref()], + Self::Full { .. } => vec![], } } fn get_description(&self) -> String { match &self { - RangeOperationExpression::Between { .. } => { - "range between operation expression".to_string() - } - RangeOperationExpression::BetweenInclusive { .. } => { + Self::Between { .. } => "range between operation expression".to_string(), + Self::BetweenInclusive { .. } => { "range between inclusive operation expression".to_string() } - RangeOperationExpression::To { .. } => "range to operation expression".to_string(), - RangeOperationExpression::ToInclusive { .. } => { - "range to inclusive operation expression".to_string() - } - RangeOperationExpression::From { .. } => "range from operation expression".to_string(), - RangeOperationExpression::Full { .. } => "range full operation expression".to_string(), + Self::To { .. } => "range to operation expression".to_string(), + Self::ToInclusive { .. } => "range to inclusive operation expression".to_string(), + Self::From { .. } => "range from operation expression".to_string(), + Self::Full { .. } => "range full operation expression".to_string(), } } } diff --git a/src/tree/statement/loop.rs b/src/tree/statement/loop.rs index 23f242b..6718512 100644 --- a/src/tree/statement/loop.rs +++ b/src/tree/statement/loop.rs @@ -124,28 +124,28 @@ pub struct ContinueStatement { impl ForeachIteratorStatement { pub fn expression(&self) -> &Expression { match &self { - ForeachIteratorStatement::Value { expression, .. } => expression, - ForeachIteratorStatement::ParenthesizedValue { expression, .. } => expression, - ForeachIteratorStatement::KeyAndValue { expression, .. } => expression, - ForeachIteratorStatement::ParenthesizedKeyAndValue { expression, .. } => expression, + Self::Value { expression, .. } => expression, + Self::ParenthesizedValue { expression, .. } => expression, + Self::KeyAndValue { expression, .. } => expression, + Self::ParenthesizedKeyAndValue { expression, .. } => expression, } } pub fn key(&self) -> Option<&Variable> { match &self { - ForeachIteratorStatement::Value { .. } => None, - ForeachIteratorStatement::ParenthesizedValue { .. } => None, - ForeachIteratorStatement::KeyAndValue { key, .. } => Some(key), - ForeachIteratorStatement::ParenthesizedKeyAndValue { key, .. } => Some(key), + Self::Value { .. } => None, + Self::ParenthesizedValue { .. } => None, + Self::KeyAndValue { key, .. } => Some(key), + Self::ParenthesizedKeyAndValue { key, .. } => Some(key), } } pub fn value(&self) -> &Variable { match &self { - ForeachIteratorStatement::Value { value, .. } => value, - ForeachIteratorStatement::ParenthesizedValue { value, .. } => value, - ForeachIteratorStatement::KeyAndValue { value, .. } => value, - ForeachIteratorStatement::ParenthesizedKeyAndValue { value, .. } => value, + Self::Value { value, .. } => value, + Self::ParenthesizedValue { value, .. } => value, + Self::KeyAndValue { value, .. } => value, + Self::ParenthesizedKeyAndValue { value, .. } => value, } } } @@ -179,14 +179,13 @@ impl Node for ForeachIteratorStatement { fn initial_position(&self) -> usize { match &self { - ForeachIteratorStatement::Value { expression, .. } - | ForeachIteratorStatement::KeyAndValue { expression, .. } => { + Self::Value { expression, .. } | Self::KeyAndValue { expression, .. } => { expression.initial_position() } - ForeachIteratorStatement::ParenthesizedValue { + Self::ParenthesizedValue { left_parenthesis, .. } - | ForeachIteratorStatement::ParenthesizedKeyAndValue { + | Self::ParenthesizedKeyAndValue { left_parenthesis, .. } => *left_parenthesis, } @@ -194,12 +193,11 @@ impl Node for ForeachIteratorStatement { fn final_position(&self) -> usize { match &self { - ForeachIteratorStatement::Value { value, .. } - | ForeachIteratorStatement::KeyAndValue { value, .. } => value.final_position(), - ForeachIteratorStatement::ParenthesizedValue { + Self::Value { value, .. } | Self::KeyAndValue { value, .. } => value.final_position(), + Self::ParenthesizedValue { right_parenthesis, .. } - | ForeachIteratorStatement::ParenthesizedKeyAndValue { + | Self::ParenthesizedKeyAndValue { right_parenthesis, .. } => right_parenthesis + 1, } @@ -207,13 +205,13 @@ impl Node for ForeachIteratorStatement { fn children(&self) -> Vec<&dyn Node> { match &self { - ForeachIteratorStatement::Value { + Self::Value { expression, r#as, value, .. } - | ForeachIteratorStatement::ParenthesizedValue { + | Self::ParenthesizedValue { expression, r#as, value, @@ -221,14 +219,14 @@ impl Node for ForeachIteratorStatement { } => { vec![expression, r#as, value] } - ForeachIteratorStatement::KeyAndValue { + Self::KeyAndValue { expression, r#as, key, value, .. } - | ForeachIteratorStatement::ParenthesizedKeyAndValue { + | Self::ParenthesizedKeyAndValue { expression, r#as, key, @@ -274,7 +272,7 @@ impl Node for ForIteratorStatement { fn initial_position(&self) -> usize { match &self { - ForIteratorStatement::Standalone { + Self::Standalone { initializations, initializations_semicolon, .. @@ -285,7 +283,7 @@ impl Node for ForIteratorStatement { *initializations_semicolon } } - ForIteratorStatement::Parenthesized { + Self::Parenthesized { left_parenthesis, .. } => *left_parenthesis, } @@ -293,7 +291,7 @@ impl Node for ForIteratorStatement { fn final_position(&self) -> usize { match &self { - ForIteratorStatement::Standalone { + Self::Standalone { conditions_semicolon, r#loop, .. @@ -304,7 +302,7 @@ impl Node for ForIteratorStatement { conditions_semicolon + 1 } } - ForIteratorStatement::Parenthesized { + Self::Parenthesized { right_parenthesis, .. } => right_parenthesis + 1, } @@ -312,13 +310,13 @@ impl Node for ForIteratorStatement { fn children(&self) -> Vec<&dyn Node> { match &self { - ForIteratorStatement::Standalone { + Self::Standalone { initializations, conditions, r#loop, .. } - | ForIteratorStatement::Parenthesized { + | Self::Parenthesized { initializations, conditions, r#loop, diff --git a/src/tree/statement/mod.rs b/src/tree/statement/mod.rs index e6e2169..cf32275 100644 --- a/src/tree/statement/mod.rs +++ b/src/tree/statement/mod.rs @@ -49,73 +49,73 @@ impl Node for Statement { fn initial_position(&self) -> usize { match &self { - Statement::DoWhile(statement) => statement.initial_position(), - Statement::While(statement) => statement.initial_position(), - Statement::For(statement) => statement.initial_position(), - Statement::Foreach(statement) => statement.initial_position(), - Statement::Break(statement) => statement.initial_position(), - Statement::Continue(statement) => statement.initial_position(), - Statement::If(statement) => statement.initial_position(), - Statement::Using(statement) => statement.initial_position(), - Statement::Try(statement) => statement.initial_position(), - Statement::Expression(statement) => statement.initial_position(), - Statement::Return(statement) => statement.initial_position(), - Statement::Block(statement) => statement.initial_position(), - Statement::Empty(position) => *position, + Self::DoWhile(statement) => statement.initial_position(), + Self::While(statement) => statement.initial_position(), + Self::For(statement) => statement.initial_position(), + Self::Foreach(statement) => statement.initial_position(), + Self::Break(statement) => statement.initial_position(), + Self::Continue(statement) => statement.initial_position(), + Self::If(statement) => statement.initial_position(), + Self::Using(statement) => statement.initial_position(), + Self::Try(statement) => statement.initial_position(), + Self::Expression(statement) => statement.initial_position(), + Self::Return(statement) => statement.initial_position(), + Self::Block(statement) => statement.initial_position(), + Self::Empty(position) => *position, } } fn final_position(&self) -> usize { match &self { - Statement::DoWhile(statement) => statement.final_position(), - Statement::While(statement) => statement.final_position(), - Statement::For(statement) => statement.final_position(), - Statement::Foreach(statement) => statement.final_position(), - Statement::Break(statement) => statement.final_position(), - Statement::Continue(statement) => statement.final_position(), - Statement::If(statement) => statement.final_position(), - Statement::Using(statement) => statement.final_position(), - Statement::Try(statement) => statement.final_position(), - Statement::Expression(statement) => statement.final_position(), - Statement::Return(statement) => statement.final_position(), - Statement::Block(statement) => statement.final_position(), - Statement::Empty(position) => *position + 1, + Self::DoWhile(statement) => statement.final_position(), + Self::While(statement) => statement.final_position(), + Self::For(statement) => statement.final_position(), + Self::Foreach(statement) => statement.final_position(), + Self::Break(statement) => statement.final_position(), + Self::Continue(statement) => statement.final_position(), + Self::If(statement) => statement.final_position(), + Self::Using(statement) => statement.final_position(), + Self::Try(statement) => statement.final_position(), + Self::Expression(statement) => statement.final_position(), + Self::Return(statement) => statement.final_position(), + Self::Block(statement) => statement.final_position(), + Self::Empty(position) => *position + 1, } } fn children(&self) -> Vec<&dyn Node> { match &self { - Statement::DoWhile(statement) => vec![statement.as_ref()], - Statement::While(statement) => vec![statement.as_ref()], - Statement::For(statement) => vec![statement.as_ref()], - Statement::Foreach(statement) => vec![statement.as_ref()], - Statement::Break(statement) => vec![statement.as_ref()], - Statement::Continue(statement) => vec![statement.as_ref()], - Statement::If(statement) => vec![statement.as_ref()], - Statement::Using(statement) => vec![statement.as_ref()], - Statement::Try(statement) => vec![statement.as_ref()], - Statement::Expression(statement) => vec![statement.as_ref()], - Statement::Return(statement) => vec![statement.as_ref()], - Statement::Block(statement) => vec![statement.as_ref()], - Statement::Empty(_) => vec![], + Self::DoWhile(statement) => vec![statement.as_ref()], + Self::While(statement) => vec![statement.as_ref()], + Self::For(statement) => vec![statement.as_ref()], + Self::Foreach(statement) => vec![statement.as_ref()], + Self::Break(statement) => vec![statement.as_ref()], + Self::Continue(statement) => vec![statement.as_ref()], + Self::If(statement) => vec![statement.as_ref()], + Self::Using(statement) => vec![statement.as_ref()], + Self::Try(statement) => vec![statement.as_ref()], + Self::Expression(statement) => vec![statement.as_ref()], + Self::Return(statement) => vec![statement.as_ref()], + Self::Block(statement) => vec![statement.as_ref()], + Self::Empty(_) => vec![], } } fn get_description(&self) -> String { match &self { - Statement::DoWhile(statement) => statement.get_description(), - Statement::While(statement) => statement.get_description(), - Statement::For(statement) => statement.get_description(), - Statement::Foreach(statement) => statement.get_description(), - Statement::Break(statement) => statement.get_description(), - Statement::Continue(statement) => statement.get_description(), - Statement::If(statement) => statement.get_description(), - Statement::Using(statement) => statement.get_description(), - Statement::Try(statement) => statement.get_description(), - Statement::Expression(statement) => statement.get_description(), - Statement::Return(statement) => statement.get_description(), - Statement::Block(statement) => statement.get_description(), - Statement::Empty(_) => "empty statement".to_string(), + Self::DoWhile(statement) => statement.get_description(), + Self::While(statement) => statement.get_description(), + Self::For(statement) => statement.get_description(), + Self::Foreach(statement) => statement.get_description(), + Self::Break(statement) => statement.get_description(), + Self::Continue(statement) => statement.get_description(), + Self::If(statement) => statement.get_description(), + Self::Using(statement) => statement.get_description(), + Self::Try(statement) => statement.get_description(), + Self::Expression(statement) => statement.get_description(), + Self::Return(statement) => statement.get_description(), + Self::Block(statement) => statement.get_description(), + Self::Empty(_) => "empty statement".to_string(), } } } diff --git a/src/tree/statement/return.rs b/src/tree/statement/return.rs index 0f4b060..eda50fb 100644 --- a/src/tree/statement/return.rs +++ b/src/tree/statement/return.rs @@ -25,28 +25,28 @@ pub enum ReturnStatement { impl Node for ReturnStatement { fn comments(&self) -> Option<&CommentGroup> { match &self { - ReturnStatement::Explicit { comments, .. } => Some(comments), - ReturnStatement::Implicit { comments, .. } => Some(comments), + Self::Explicit { comments, .. } => Some(comments), + Self::Implicit { comments, .. } => Some(comments), } } fn initial_position(&self) -> usize { match &self { - ReturnStatement::Explicit { r#return, .. } => r#return.initial_position(), - ReturnStatement::Implicit { expression, .. } => expression.initial_position(), + Self::Explicit { r#return, .. } => r#return.initial_position(), + Self::Implicit { expression, .. } => expression.initial_position(), } } fn final_position(&self) -> usize { match &self { - ReturnStatement::Explicit { semicolon, .. } => semicolon + 1, - ReturnStatement::Implicit { expression, .. } => expression.final_position(), + Self::Explicit { semicolon, .. } => semicolon + 1, + Self::Implicit { expression, .. } => expression.final_position(), } } fn children(&self) -> Vec<&dyn Node> { match &self { - ReturnStatement::Explicit { + Self::Explicit { r#return, expression, .. @@ -57,14 +57,14 @@ impl Node for ReturnStatement { vec![r#return] } } - ReturnStatement::Implicit { expression, .. } => vec![expression], + Self::Implicit { expression, .. } => vec![expression], } } fn get_description(&self) -> String { match &self { - ReturnStatement::Explicit { .. } => "explicit return statement".to_string(), - ReturnStatement::Implicit { .. } => "implicit return statement".to_string(), + Self::Explicit { .. } => "explicit return statement".to_string(), + Self::Implicit { .. } => "implicit return statement".to_string(), } } } diff --git a/src/tree/statement/try.rs b/src/tree/statement/try.rs index 06a9b31..8ecbfeb 100644 --- a/src/tree/statement/try.rs +++ b/src/tree/statement/try.rs @@ -137,24 +137,22 @@ impl Node for TryCatchTypeStatement { fn initial_position(&self) -> usize { match &self { - TryCatchTypeStatement::Identifier(identifier) => identifier.initial_position(), - TryCatchTypeStatement::Union(identifiers) => identifiers[0].initial_position(), + Self::Identifier(identifier) => identifier.initial_position(), + Self::Union(identifiers) => identifiers[0].initial_position(), } } fn final_position(&self) -> usize { match &self { - TryCatchTypeStatement::Identifier(identifier) => identifier.final_position(), - TryCatchTypeStatement::Union(identifiers) => { - identifiers[identifiers.len() - 1].final_position() - } + Self::Identifier(identifier) => identifier.final_position(), + Self::Union(identifiers) => identifiers[identifiers.len() - 1].final_position(), } } fn children(&self) -> Vec<&dyn Node> { match &self { - TryCatchTypeStatement::Identifier(identifier) => vec![identifier], - TryCatchTypeStatement::Union(identifiers) => identifiers + Self::Identifier(identifier) => vec![identifier], + Self::Union(identifiers) => identifiers .iter() .map(|identifier| identifier as &dyn Node) .collect(),