diff --git a/Cargo.lock b/Cargo.lock index 696b033..81a1aff 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -54,6 +54,12 @@ dependencies = [ "bitflags", ] +[[package]] +name = "convert_case" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6245d59a3e82a7fc217c5828a6692dbc6dfb63a0c8c90495621f7b9d79704a0e" + [[package]] name = "deranged" version = "0.3.11" @@ -63,6 +69,19 @@ dependencies = [ "powerfmt", ] +[[package]] +name = "derive_more" +version = "0.99.17" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4fb810d30a7c1953f91334de7244731fc3f3c10d7fe163338a35b9f640960321" +dependencies = [ + "convert_case", + "proc-macro2", + "quote", + "rustc_version 0.4.0", + "syn 1.0.107", +] + [[package]] name = "gethostname" version = "0.2.3" @@ -208,7 +227,7 @@ checksum = "f842b1982eb6c2fe34036a4fbfb06dd185a3f5c8edfaacdf7d1ea10b07de6252" dependencies = [ "lock_api", "parking_lot_core", - "rustc_version", + "rustc_version 0.2.3", ] [[package]] @@ -221,7 +240,7 @@ dependencies = [ "cloudabi", "libc", "redox_syscall", - "rustc_version", + "rustc_version 0.2.3", "smallvec 0.6.14", "winapi", ] @@ -292,7 +311,16 @@ version = "0.2.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "138e3e0acb6c9fb258b19b67cb8abd63c00679d2851805ea151465464fe9030a" dependencies = [ - "semver", + "semver 0.9.0", +] + +[[package]] +name = "rustc_version" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bfa0f585226d2e68097d4f95d113b15b83a82e819ab25717ec0590d9584ef366" +dependencies = [ + "semver 1.0.23", ] [[package]] @@ -316,6 +344,12 @@ dependencies = [ "semver-parser", ] +[[package]] +name = "semver" +version = "1.0.23" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "61697e0a1c7e512e84a621326239844a24d8207b4669b41bc18b32ea5cbf988b" + [[package]] name = "semver-parser" version = "0.7.0" @@ -382,6 +416,7 @@ name = "star-kirby-lang" version = "0.1.1" dependencies = [ "anyhow", + "derive_more", "global", "lazy_static", "nom", diff --git a/Cargo.toml b/Cargo.toml index c7998fd..2efa7d1 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -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" diff --git a/src/ast/expression/mod.rs b/src/ast/expression/mod.rs index f2807f3..88c803e 100644 --- a/src/ast/expression/mod.rs +++ b/src/ast/expression/mod.rs @@ -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; @@ -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), @@ -78,75 +79,3 @@ impl NodeInterface for Expression { } } } - -impl From for Expression { - fn from(value: Prefix) -> Self { - Self::Prefix(value) - } -} - -impl From for Expression { - fn from(value: IntegerLiteral) -> Self { - Self::IntegerLiteral(value) - } -} - -impl From for Expression { - fn from(value: Identifier) -> Self { - Self::Identifier(value) - } -} - -impl From for Expression { - fn from(value: Infix) -> Self { - Self::Infix(value) - } -} - -impl From for Expression { - fn from(value: Boolean) -> Self { - Self::Boolean(value) - } -} - -impl From for Expression { - fn from(value: If) -> Self { - Self::If(value) - } -} - -impl From for Expression { - fn from(value: FunctionLiteral) -> Self { - Self::FunctionLiteral(value) - } -} - -impl From for Expression { - fn from(value: Call) -> Self { - Self::Call(value) - } -} - -impl From for Expression { - fn from(value: StringLiteral) -> Self { - Self::StringLiteral(value) - } -} - -impl From for Expression { - fn from(value: ArrayLiteral) -> Self { - Self::ArrayLiteral(value) - } -} - -impl From for Expression { - fn from(value: Index) -> Self { - Self::Index(value) - } -} - -impl From for Expression { - fn from(value: HashLiteral) -> Self { - Self::HashLiteral(value) - } -}