Skip to content

Commit

Permalink
remove any
Browse files Browse the repository at this point in the history
  • Loading branch information
DaviRain-Su committed Oct 10, 2023
1 parent 9ab0620 commit 2ed5449
Show file tree
Hide file tree
Showing 30 changed files with 8 additions and 222 deletions.
5 changes: 0 additions & 5 deletions src/ast/expression/array_literal.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ use crate::ast::expression::Expression;
use crate::ast::NodeInterface;
use crate::error::Error;
use crate::token::Token;
use std::any::Any;
use std::fmt::{Display, Formatter};

#[derive(Debug, Clone, Hash, Eq, PartialEq, Ord, PartialOrd)]
Expand Down Expand Up @@ -32,10 +31,6 @@ impl NodeInterface for ArrayLiteral {
fn token_literal(&self) -> String {
self.token.literal().into()
}

fn as_any(&self) -> &dyn Any {
self
}
}

impl Display for ArrayLiteral {
Expand Down
5 changes: 0 additions & 5 deletions src/ast/expression/boolean.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ use crate::ast::NodeInterface;
use crate::error::Error;
use crate::token::Token;
use log::trace;
use std::any::Any;
use std::fmt::{Display, Formatter};

#[derive(Debug, Clone, Hash, Eq, PartialEq, Ord, PartialOrd)]
Expand Down Expand Up @@ -36,10 +35,6 @@ impl NodeInterface for Boolean {
fn token_literal(&self) -> String {
self.token.literal().into()
}

fn as_any(&self) -> &dyn Any {
self
}
}

impl TryFrom<Expression> for Boolean {
Expand Down
5 changes: 0 additions & 5 deletions src/ast/expression/call_expression.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ use crate::ast::expression::Expression;
use crate::ast::NodeInterface;
use crate::error::Error;
use crate::token::Token;
use std::any::Any;
use std::fmt::{Display, Formatter};

#[derive(Debug, Clone, Hash, Eq, PartialEq, Ord, PartialOrd)]
Expand Down Expand Up @@ -54,10 +53,6 @@ impl NodeInterface for Call {
fn token_literal(&self) -> String {
self.token.literal().into()
}

fn as_any(&self) -> &dyn Any {
self
}
}

impl TryFrom<Expression> for Call {
Expand Down
5 changes: 0 additions & 5 deletions src/ast/expression/function_literal.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ use crate::ast::statement::block_statement::BlockStatement;
use crate::ast::{Identifier, NodeInterface};
use crate::error::Error;
use crate::token::Token;
use std::any::Any;
use std::fmt::{Display, Formatter};

#[derive(Debug, Clone, Hash, Eq, PartialEq, Ord, PartialOrd)]
Expand Down Expand Up @@ -56,10 +55,6 @@ impl NodeInterface for FunctionLiteral {
fn token_literal(&self) -> String {
self.token.literal().into()
}

fn as_any(&self) -> &dyn Any {
self
}
}

impl TryFrom<Expression> for FunctionLiteral {
Expand Down
5 changes: 0 additions & 5 deletions src/ast/expression/hash_literal.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ use crate::ast::expression::Expression;
use crate::ast::NodeInterface;
use crate::error::Error;
use crate::token::Token;
use std::any::Any;
use std::collections::BTreeMap;
use std::fmt::{Display, Formatter};
use std::hash::Hash;
Expand Down Expand Up @@ -50,10 +49,6 @@ impl NodeInterface for HashLiteral {
fn token_literal(&self) -> String {
self.token.literal().into()
}

fn as_any(&self) -> &dyn Any {
self
}
}

impl TryFrom<Expression> for HashLiteral {
Expand Down
5 changes: 0 additions & 5 deletions src/ast/expression/if_expression.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ use crate::ast::statement::block_statement::BlockStatement;
use crate::ast::NodeInterface;
use crate::error::Error;
use crate::token::Token;
use std::any::Any;
use std::fmt::{Display, Formatter};

#[derive(Debug, Clone, Hash, Eq, PartialEq, Ord, PartialOrd)]
Expand Down Expand Up @@ -79,10 +78,6 @@ impl NodeInterface for If {
fn token_literal(&self) -> String {
self.token.literal().into()
}

fn as_any(&self) -> &dyn Any {
self
}
}

impl TryFrom<Expression> for If {
Expand Down
5 changes: 0 additions & 5 deletions src/ast/expression/index_expression.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ use crate::ast::Identifier;
use crate::ast::NodeInterface;
use crate::error::Error;
use crate::token::Token;
use std::any::Any;
use std::fmt::{Display, Formatter};

#[derive(Debug, Clone, Hash, Eq, PartialEq, Ord, PartialOrd)]
Expand Down Expand Up @@ -39,10 +38,6 @@ impl NodeInterface for Index {
fn token_literal(&self) -> String {
self.token.literal().into()
}

fn as_any(&self) -> &dyn Any {
self
}
}

impl Display for Index {
Expand Down
5 changes: 0 additions & 5 deletions src/ast/expression/infix_expression.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ use crate::ast::statement::expression_statement::ExpressionStatement;
use crate::ast::NodeInterface;
use crate::error::Error;
use crate::token::Token;
use std::any::Any;
use std::fmt::{Display, Formatter};

#[derive(Debug, Clone, Hash, Eq, PartialEq, Ord, PartialOrd)]
Expand Down Expand Up @@ -63,10 +62,6 @@ impl NodeInterface for Infix {
fn token_literal(&self) -> String {
self.token.literal().into()
}

fn as_any(&self) -> &dyn Any {
self
}
}

impl TryFrom<ExpressionStatement> for Infix {
Expand Down
5 changes: 0 additions & 5 deletions src/ast/expression/integer_literal.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ use crate::ast::statement::expression_statement::ExpressionStatement;
use crate::ast::{Identifier, NodeInterface};
use crate::error::Error;
use crate::token::Token;
use std::any::Any;
use std::fmt::{Debug, Display, Formatter};

#[derive(Debug, Default, Clone, Hash, Eq, PartialEq, Ord, PartialOrd)]
Expand Down Expand Up @@ -43,10 +42,6 @@ impl NodeInterface for IntegerLiteral {
fn token_literal(&self) -> String {
format!("{}", self.value)
}

fn as_any(&self) -> &dyn Any {
self
}
}

impl TryFrom<ExpressionStatement> for IntegerLiteral {
Expand Down
8 changes: 2 additions & 6 deletions src/ast/expression/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ use crate::ast::expression::infix_expression::Infix;
use crate::ast::expression::integer_literal::IntegerLiteral;
use crate::ast::expression::prefix_expression::Prefix;
use crate::ast::expression::string_literal::StringLiteral;
use crate::ast::{Identifier, NodeInterface};
use std::any::Any;
use crate::ast::Identifier;
use crate::ast::NodeInterface;
use std::fmt::{Display, Formatter};

pub mod array_literal;
Expand Down Expand Up @@ -77,10 +77,6 @@ impl NodeInterface for Expression {
Self::HashLiteral(hash_literal) => hash_literal.token_literal(),
}
}

fn as_any(&self) -> &dyn Any {
self
}
}

impl From<Prefix> for Expression {
Expand Down
5 changes: 0 additions & 5 deletions src/ast/expression/prefix_expression.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ use crate::ast::statement::expression_statement::ExpressionStatement;
use crate::ast::NodeInterface;
use crate::error::Error;
use crate::token::Token;
use std::any::Any;
use std::fmt::{Display, Formatter};

#[derive(Debug, Clone, Hash, Eq, PartialEq, Ord, PartialOrd)]
Expand Down Expand Up @@ -56,10 +55,6 @@ impl NodeInterface for Prefix {
fn token_literal(&self) -> String {
self.right.token_literal()
}

fn as_any(&self) -> &dyn Any {
self
}
}

impl TryFrom<ExpressionStatement> for Prefix {
Expand Down
5 changes: 0 additions & 5 deletions src/ast/expression/string_literal.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ use crate::ast::expression::Expression;
use crate::ast::NodeInterface;
use crate::error::Error;
use crate::token::Token;
use std::any::Any;
use std::fmt::{Display, Formatter};

#[derive(Debug, Clone, Hash, Eq, PartialEq, Ord, PartialOrd)]
Expand Down Expand Up @@ -31,10 +30,6 @@ impl NodeInterface for StringLiteral {
fn token_literal(&self) -> String {
self.token.literal().into()
}

fn as_any(&self) -> &dyn Any {
self
}
}

impl TryFrom<Expression> for StringLiteral {
Expand Down
11 changes: 0 additions & 11 deletions src/ast/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ use crate::ast::statement::Statement;
use crate::object::Object;
use crate::token::Token;
use log::trace;
use std::any::Any;
use std::fmt::{Debug, Display, Formatter};

#[derive(Debug, Clone, PartialOrd, PartialEq, Eq, Ord, Hash)]
Expand Down Expand Up @@ -60,8 +59,6 @@ pub trait NodeInterface: Debug + Display {
/// 必须提供 TokenLiteral()方法,该方法返回与其
/// 关联的词法单元的字面量
fn token_literal(&self) -> String;

fn as_any(&self) -> &dyn Any;
}

/// 这个 Program 节点将成为语法分析器生成的每个 AST 的根节点。每个有效的
Expand Down Expand Up @@ -111,10 +108,6 @@ impl NodeInterface for Program {
fn token_literal(&self) -> String {
self.token_literal()
}

fn as_any(&self) -> &dyn Any {
self
}
}

#[derive(Debug, Default, Clone, Hash, Eq, PartialEq, Ord, PartialOrd)]
Expand Down Expand Up @@ -157,10 +150,6 @@ impl NodeInterface for Identifier {
fn token_literal(&self) -> String {
self.token.literal().into()
}

fn as_any(&self) -> &dyn Any {
self
}
}

impl TryFrom<Expression> for Identifier {
Expand Down
5 changes: 0 additions & 5 deletions src/ast/statement/block_statement.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
use crate::ast::statement::Statement;
use crate::ast::NodeInterface;
use crate::token::Token;
use std::any::Any;
use std::fmt::{Debug, Display, Formatter};

#[derive(Debug, Clone, Default, Hash, Eq, PartialEq, Ord, PartialOrd)]
Expand All @@ -23,8 +22,4 @@ impl NodeInterface for BlockStatement {
fn token_literal(&self) -> String {
self.token.literal().into()
}

fn as_any(&self) -> &dyn Any {
self
}
}
5 changes: 0 additions & 5 deletions src/ast/statement/expression_statement.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ use crate::ast::statement::Statement;
use crate::ast::NodeInterface;
use crate::error::Error;
use crate::token::Token;
use std::any::Any;
use std::fmt::{Display, Formatter};

/// expression statement
Expand Down Expand Up @@ -44,10 +43,6 @@ impl NodeInterface for ExpressionStatement {
fn token_literal(&self) -> String {
self.expression.token_literal()
}

fn as_any(&self) -> &dyn Any {
self
}
}

impl TryFrom<Statement> for ExpressionStatement {
Expand Down
5 changes: 0 additions & 5 deletions src/ast/statement/let_statement.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ use crate::ast::statement::Statement;
use crate::ast::{Identifier, NodeInterface};
use crate::error::Error;
use crate::token::Token;
use std::any::Any;
use std::fmt::{Display, Formatter};

/// let statement
Expand Down Expand Up @@ -38,10 +37,6 @@ impl NodeInterface for LetStatement {
fn token_literal(&self) -> String {
self.token.literal().into()
}

fn as_any(&self) -> &dyn Any {
self
}
}

impl Display for LetStatement {
Expand Down
5 changes: 0 additions & 5 deletions src/ast/statement/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ use crate::ast::statement::expression_statement::ExpressionStatement;
use crate::ast::statement::let_statement::LetStatement;
use crate::ast::statement::return_statement::ReturnStatement;
use crate::ast::NodeInterface;
use std::any::Any;
use std::fmt::{Debug, Display, Formatter};

use super::Node;
Expand All @@ -30,10 +29,6 @@ impl NodeInterface for Statement {
Self::BlockStatement(block) => block.token_literal(),
}
}

fn as_any(&self) -> &dyn Any {
self
}
}

impl Display for Statement {
Expand Down
5 changes: 0 additions & 5 deletions src/ast/statement/return_statement.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ use crate::ast::statement::Statement;
use crate::ast::NodeInterface;
use crate::error::Error;
use crate::token::Token;
use std::any::Any;
use std::fmt::{Display, Formatter};

/// return statement
Expand Down Expand Up @@ -42,10 +41,6 @@ impl NodeInterface for ReturnStatement {
fn token_literal(&self) -> String {
self.token.literal().into()
}

fn as_any(&self) -> &dyn Any {
self
}
}

impl TryFrom<Statement> for ReturnStatement {
Expand Down
3 changes: 2 additions & 1 deletion src/evaluator/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@ use crate::ast::expression::if_expression::If;
use crate::ast::expression::Expression;
use crate::ast::statement::block_statement::BlockStatement;
use crate::ast::statement::Statement;
use crate::ast::{Identifier, Node, NodeInterface, Program};
use crate::ast::NodeInterface;
use crate::ast::{Identifier, Node, Program};
use crate::error::Error;
use crate::evaluator::builtins::lookup_builtin;
use crate::object::array::Array;
Expand Down
Loading

0 comments on commit 2ed5449

Please sign in to comment.