Skip to content

Commit

Permalink
use derive_more
Browse files Browse the repository at this point in the history
  • Loading branch information
DaviRain-Su committed May 31, 2024
1 parent da9e740 commit 4827c18
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 76 deletions.
41 changes: 38 additions & 3 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -26,3 +26,4 @@ tracing-subscriber = { version = "0.3.18", features = [
] }
tracing-bunyan-formatter = "0.3.9"
tracing-log = "0.2.0"
derive_more = "0.99.17"
75 changes: 2 additions & 73 deletions src/ast/expression/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ use crate::ast::expression::prefix::Prefix;
use crate::ast::expression::string::StringLiteral;
use crate::ast::Identifier;
use crate::ast::NodeInterface;
use derive_more::From;
use std::fmt::{Display, Formatter};

pub mod array;
Expand All @@ -25,7 +26,7 @@ pub mod integer;
pub mod prefix;
pub mod string;

#[derive(Debug, Clone, Hash, Eq, PartialEq, Ord, PartialOrd)]
#[derive(Debug, Clone, Hash, Eq, PartialEq, Ord, PartialOrd, From)]
pub enum Expression {
Prefix(Prefix),
Infix(Infix),
Expand Down Expand Up @@ -78,75 +79,3 @@ impl NodeInterface for Expression {
}
}
}

impl From<Prefix> for Expression {
fn from(value: Prefix) -> Self {
Self::Prefix(value)
}
}

impl From<IntegerLiteral> for Expression {
fn from(value: IntegerLiteral) -> Self {
Self::IntegerLiteral(value)
}
}

impl From<Identifier> for Expression {
fn from(value: Identifier) -> Self {
Self::Identifier(value)
}
}

impl From<Infix> for Expression {
fn from(value: Infix) -> Self {
Self::Infix(value)
}
}

impl From<Boolean> for Expression {
fn from(value: Boolean) -> Self {
Self::Boolean(value)
}
}

impl From<If> for Expression {
fn from(value: If) -> Self {
Self::If(value)
}
}

impl From<FunctionLiteral> for Expression {
fn from(value: FunctionLiteral) -> Self {
Self::FunctionLiteral(value)
}
}

impl From<Call> for Expression {
fn from(value: Call) -> Self {
Self::Call(value)
}
}

impl From<StringLiteral> for Expression {
fn from(value: StringLiteral) -> Self {
Self::StringLiteral(value)
}
}

impl From<ArrayLiteral> for Expression {
fn from(value: ArrayLiteral) -> Self {
Self::ArrayLiteral(value)
}
}

impl From<Index> for Expression {
fn from(value: Index) -> Self {
Self::Index(value)
}
}

impl From<HashLiteral> for Expression {
fn from(value: HashLiteral) -> Self {
Self::HashLiteral(value)
}
}

0 comments on commit 4827c18

Please sign in to comment.