From b5befbb1e4b96013421458769fa95c5b53fbc03e Mon Sep 17 00:00:00 2001 From: nic-gaffney Date: Mon, 10 Apr 2023 23:15:02 -0500 Subject: Stole the old code and refactored it for the new shit, gonna go and change some shit up in the future --- crates/sloth/src/parser/ast.rs | 14 +++++--------- crates/sloth/src/parser/expr.rs | 7 ++++--- 2 files changed, 9 insertions(+), 12 deletions(-) diff --git a/crates/sloth/src/parser/ast.rs b/crates/sloth/src/parser/ast.rs index d472269..c008905 100644 --- a/crates/sloth/src/parser/ast.rs +++ b/crates/sloth/src/parser/ast.rs @@ -1,6 +1,5 @@ use crate::lexer::{Token, TokenType}; -#[derive(Debug)] -#[derive(PartialEq)] +#[derive(Debug, PartialEq)] pub enum BinaryOp { Add, Con, @@ -25,16 +24,14 @@ pub enum BinaryOp { LogAnd, LogOr, } -#[derive(Debug)] -#[derive(PartialEq)] +#[derive(Debug, PartialEq)] pub enum UnaryOp { Not, Neg, BWComp, } -#[derive(Debug)] -#[derive(PartialEq)] +#[derive(Debug, PartialEq)] pub enum Literal { Integer(i128), Float(f64), @@ -44,13 +41,12 @@ pub enum Literal { Regex(String), List(Vec), // TODO: holy shit we forgor listys } -#[derive(Debug)] -#[derive(PartialEq)] +#[derive(Debug, PartialEq)] pub enum Expr { Grouping(Box), BinaryOp { op: BinaryOp, - lhs: Box, + lhs: Box, rhs: Box, }, UnaryOp { diff --git a/crates/sloth/src/parser/expr.rs b/crates/sloth/src/parser/expr.rs index 84aab31..7cce919 100644 --- a/crates/sloth/src/parser/expr.rs +++ b/crates/sloth/src/parser/expr.rs @@ -146,9 +146,10 @@ impl<'a> AstParser<'a> { #[cfg(test)] mod tests { use itertools::Itertools; - use super::{AstParser, BinaryOp, Expr, Literal}; - use crate::{lexer::{Lexer}, parser::ast::UnaryOp}; + use super::{AstParser, BinaryOp, Expr, Literal}; + use crate::lexer::Lexer; + use crate::parser::ast::UnaryOp; #[test] fn basic_expression_a() { @@ -204,4 +205,4 @@ mod tests { assert_eq!(expected_ast, generated_ast); } -} \ No newline at end of file +} -- cgit v1.2.3