Skip to content

Commit

Permalink
chore: code style (#37)
Browse files Browse the repository at this point in the history
* chore: from `self` to `&self`

* chore: from `Name::Member` to `Self::Member`
  • Loading branch information
KennedyTedesco committed Jan 19, 2023
1 parent fe5bc47 commit bab4e9b
Show file tree
Hide file tree
Showing 22 changed files with 1,092 additions and 1,276 deletions.
2 changes: 1 addition & 1 deletion src/lexer/token.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 => "!=",
Expand Down
2 changes: 1 addition & 1 deletion src/parser/internal/expression/precedence.rs
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ impl Precedence {
}

pub fn associativity(&self) -> Option<Associativity> {
Some(match self {
Some(match &self {
Self::TypeCheck
| Self::ArrayContains
| Self::MulDivMod
Expand Down
6 changes: 3 additions & 3 deletions src/tree/definition/class.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
Expand All @@ -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(),
Expand All @@ -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(),
Expand Down
38 changes: 19 additions & 19 deletions src/tree/definition/enum.rs
Original file line number Diff line number Diff line change
Expand Up @@ -115,30 +115,30 @@ impl Node for EnumDefinition {
}

fn initial_position(&self) -> usize {
match self {
EnumDefinition::Backed(definition) => definition.initial_position(),
EnumDefinition::Unit(definition) => definition.initial_position(),
match &self {
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(),
match &self {
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(),
}
}
}
Expand Down Expand Up @@ -240,31 +240,31 @@ 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(),
}
}

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(),
}
}

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],
}
}

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(),
Expand Down Expand Up @@ -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],
}
}
Expand Down Expand Up @@ -383,15 +383,15 @@ 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(),
}
}

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(),
Expand Down
4 changes: 2 additions & 2 deletions src/tree/definition/interface.rs
Original file line number Diff line number Diff line change
Expand Up @@ -149,15 +149,15 @@ 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(),
}
}

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(),
Expand Down
68 changes: 34 additions & 34 deletions src/tree/definition/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -65,54 +65,54 @@ 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(),
match &self {
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(),
match &self {
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(),
}
}
}
78 changes: 39 additions & 39 deletions src/tree/definition/modifier.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,64 +53,64 @@ 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(),
match &self {
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(),
match &self {
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],
match &self {
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(),
}
}
}

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),
match &self {
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),
}
}
}
Loading

0 comments on commit bab4e9b

Please sign in to comment.