Skip to content

Commit

Permalink
chore: Node get_description() tweaks (#36)
Browse files Browse the repository at this point in the history
  • Loading branch information
KennedyTedesco committed Jan 18, 2023
1 parent 26e15c2 commit fe5bc47
Show file tree
Hide file tree
Showing 16 changed files with 448 additions and 39 deletions.
11 changes: 9 additions & 2 deletions src/tree/definition/class.rs
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,7 @@ impl Node for ClassDefinitionMember {
}

fn children(&self) -> Vec<&dyn Node> {
match self {
match &self {
Self::Constant(constant) => vec![constant],
Self::Property(property) => vec![property],
Self::AbstractMethod(method) => vec![method],
Expand All @@ -235,6 +235,13 @@ impl Node for ClassDefinitionMember {
}

fn get_description(&self) -> String {
"class member definition".to_string()
match &self {
Self::Constant(constant) => constant.get_description(),
Self::Property(property) => property.get_description(),
Self::AbstractMethod(method) => method.get_description(),
Self::AbstractConstructor(constructor) => constructor.get_description(),
Self::ConcreteMethod(method) => method.get_description(),
Self::ConcreteConstructor(constructor) => constructor.get_description(),
}
}
}
19 changes: 15 additions & 4 deletions src/tree/definition/enum.rs
Original file line number Diff line number Diff line change
Expand Up @@ -129,14 +129,17 @@ impl Node for EnumDefinition {
}

fn children(&self) -> Vec<&dyn Node> {
match self {
match &self {
EnumDefinition::Backed(definition) => vec![definition],
EnumDefinition::Unit(definition) => vec![definition],
}
}

fn get_description(&self) -> String {
"enum definition".to_string()
match &self {
EnumDefinition::Backed(definition) => definition.get_description(),
EnumDefinition::Unit(definition) => definition.get_description(),
}
}
}

Expand Down Expand Up @@ -261,7 +264,11 @@ impl Node for UnitEnumMemberDefinition {
}

fn get_description(&self) -> String {
"unit enum member definition".to_string()
match self {
Self::Case(case) => case.get_description(),
Self::Method(method) => method.get_description(),
Self::Constant(constant) => constant.get_description(),
}
}
}

Expand Down Expand Up @@ -400,7 +407,11 @@ impl Node for BackedEnumMemberDefinition {
}

fn get_description(&self) -> String {
"backed enum member definition".to_string()
match &self {
Self::Case(case) => case.get_description(),
Self::Method(method) => method.get_description(),
Self::Constant(constant) => constant.get_description(),
}
}
}

Expand Down
8 changes: 6 additions & 2 deletions src/tree/definition/interface.rs
Original file line number Diff line number Diff line change
Expand Up @@ -165,14 +165,18 @@ impl Node for InterfaceDefinitionMember {
}

fn children(&self) -> Vec<&dyn Node> {
match self {
match &self {
Self::Constant(constant) => vec![constant],
Self::Constructor(constructor) => vec![constructor],
Self::Method(method) => vec![method],
}
}

fn get_description(&self) -> String {
"interface member definition".to_string()
match &self {
Self::Constant(constant) => constant.get_description(),
Self::Constructor(constructor) => constructor.get_description(),
Self::Method(method) => method.get_description(),
}
}
}
13 changes: 11 additions & 2 deletions src/tree/definition/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ impl Node for Definition {
}

fn children(&self) -> Vec<&dyn Node> {
match self {
match &self {
Definition::Namespace(definition) => vec![definition.as_ref()],
Definition::Use(definition) => vec![definition.as_ref()],
Definition::TypeAlias(definition) => vec![definition.as_ref()],
Expand All @@ -104,6 +104,15 @@ impl Node for Definition {
}

fn get_description(&self) -> String {
"definition".to_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(),
}
}
}
10 changes: 9 additions & 1 deletion src/tree/definition/modifier.rs
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,15 @@ impl Node for ModifierDefinition {
}

fn get_description(&self) -> String {
"modifier definition".to_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(),
}
}
}

Expand Down
7 changes: 6 additions & 1 deletion src/tree/definition/property.rs
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,11 @@ impl Node for PropertyEntryDefinition {
}

fn get_description(&self) -> String {
"property entry definition".to_string()
match &self {
PropertyEntryDefinition::Uninitialized { .. } => {
"uninitialized property entry".to_string()
}
PropertyEntryDefinition::Initialized { .. } => "initialized property entry".to_string(),
}
}
}
27 changes: 26 additions & 1 deletion src/tree/definition/type.rs
Original file line number Diff line number Diff line change
Expand Up @@ -349,7 +349,32 @@ impl Node for TypeDefinition {
}

fn get_description(&self) -> String {
"type definition".to_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(),
}
}
}

Expand Down
6 changes: 5 additions & 1 deletion src/tree/definition/use.rs
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,11 @@ impl Node for UseDefinition {
}

fn get_description(&self) -> String {
"use definition".to_string()
match &self {
UseDefinition::Default { .. } => "use definition".to_string(),
UseDefinition::Function { .. } => "use function definition".to_string(),
UseDefinition::Constant { .. } => "use constant definition".to_string(),
}
}
}

Expand Down
9 changes: 8 additions & 1 deletion src/tree/expression/argument.rs
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,14 @@ impl Node for ArgumentExpression {
}

fn get_description(&self) -> String {
"argument expression".to_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(),
}
}
}

Expand Down
9 changes: 8 additions & 1 deletion src/tree/expression/class.rs
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,14 @@ impl Node for AnonymousClassExpressionMember {
}

fn get_description(&self) -> String {
"anonymous class expression member".to_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()
}
}
}
}

Expand Down
9 changes: 8 additions & 1 deletion src/tree/expression/literal.rs
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,14 @@ impl Node for Literal {
}

fn get_description(&self) -> String {
"literal expression".to_string()
match &self {
Literal::String(literal) => literal.get_description(),
Literal::Integer(literal) => literal.get_description(),
Literal::Float(literal) => literal.get_description(),
Literal::Null(literal) => literal.get_description(),
Literal::True(literal) => literal.get_description(),
Literal::False(literal) => literal.get_description(),
}
}
}

Expand Down
10 changes: 9 additions & 1 deletion src/tree/expression/magic_constant.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,14 @@ impl Node for MagicConstant {
}

fn get_description(&self) -> String {
"magic constant expression".to_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(),
}
}
}
32 changes: 31 additions & 1 deletion src/tree/expression/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -393,6 +393,36 @@ impl Node for Expression {
}

fn get_description(&self) -> String {
"expression".to_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(),
}
}
}
Loading

0 comments on commit fe5bc47

Please sign in to comment.