From 6e105bac55dfa21225772fc20f21a6af00adcada Mon Sep 17 00:00:00 2001 From: greg Date: Sat, 24 Feb 2018 17:50:57 -0800 Subject: [PATCH] Fixed tests w/ respect to binop There's a few unnecessary conversions of &str 's to Rc and back --- src/schala_lang/builtin.rs | 8 ++++---- src/schala_lang/parsing.rs | 11 ++++------- 2 files changed, 8 insertions(+), 11 deletions(-) diff --git a/src/schala_lang/builtin.rs b/src/schala_lang/builtin.rs index ba4f133..634e48f 100644 --- a/src/schala_lang/builtin.rs +++ b/src/schala_lang/builtin.rs @@ -10,8 +10,8 @@ pub struct BinOp { } impl BinOp { - pub fn from_sigil(sigil: Rc) -> BinOp { - BinOp { sigil } + pub fn from_sigil(sigil: &str) -> BinOp { + BinOp { sigil: Rc::new(sigil.to_string()) } } pub fn sigil(&self) -> &Rc { &self.sigil @@ -35,8 +35,8 @@ pub struct PrefixOp { } impl PrefixOp { - pub fn from_sigil(sigil: Rc) -> PrefixOp { - PrefixOp { sigil } + pub fn from_sigil(sigil: &str) -> PrefixOp { + PrefixOp { sigil: Rc::new(sigil.to_string()) } } pub fn sigil(&self) -> &Rc { &self.sigil diff --git a/src/schala_lang/parsing.rs b/src/schala_lang/parsing.rs index 3ba13e7..d16378f 100644 --- a/src/schala_lang/parsing.rs +++ b/src/schala_lang/parsing.rs @@ -545,7 +545,7 @@ impl Parser { _ => unreachable!(), }; let rhs = self.precedence_expr(new_precedence)?; - let operation = BinOp::from_sigil(sigil); + let operation = BinOp::from_sigil(sigil.as_ref()); lhs = Expression(ExpressionType::BinExp(operation, bx!(lhs), bx!(rhs)), None); } self.parse_level -= 1; @@ -561,7 +561,7 @@ impl Parser { }; let expr = self.primary()?; Ok(Expression( - ExpressionType::PrefixExp(PrefixOp::from_sigil(sigil), bx!(expr)), + ExpressionType::PrefixExp(PrefixOp::from_sigil(sigil.as_str()), bx!(expr)), None)) }, _ => self.primary() @@ -849,13 +849,10 @@ mod parse_tests { ($string:expr) => { assert!(parse(tokenize($string)).0.is_err()) } } macro_rules! binexp { - ($op:expr, $lhs:expr, $rhs:expr) => { BinExp(op!($op), bx!(Expression($lhs, None)), bx!(Expression($rhs, None))) } + ($op:expr, $lhs:expr, $rhs:expr) => { BinExp(BinOp::from_sigil($op), bx!(Expression($lhs, None)), bx!(Expression($rhs, None))) } } macro_rules! prefexp { - ($op:expr, $lhs:expr) => { PrefixExp(op!($op), bx!(Expression($lhs, None))) } - } - macro_rules! op { - ($op:expr) => { BinOp::from_sigil($op.to_string()) } + ($op:expr, $lhs:expr) => { PrefixExp(PrefixOp::from_sigil($op), bx!(Expression($lhs, None))) } } macro_rules! val { ($var:expr) => { Value(Rc::new($var.to_string()), vec![]) }