Fixed tests w/ respect to binop
There's a few unnecessary conversions of &str 's to Rc<String> and back
This commit is contained in:
parent
cfd6df7ba5
commit
b3fff100d2
@ -10,8 +10,8 @@ pub struct BinOp {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl BinOp {
|
impl BinOp {
|
||||||
pub fn from_sigil(sigil: Rc<String>) -> BinOp {
|
pub fn from_sigil(sigil: &str) -> BinOp {
|
||||||
BinOp { sigil }
|
BinOp { sigil: Rc::new(sigil.to_string()) }
|
||||||
}
|
}
|
||||||
pub fn sigil(&self) -> &Rc<String> {
|
pub fn sigil(&self) -> &Rc<String> {
|
||||||
&self.sigil
|
&self.sigil
|
||||||
@ -35,8 +35,8 @@ pub struct PrefixOp {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl PrefixOp {
|
impl PrefixOp {
|
||||||
pub fn from_sigil(sigil: Rc<String>) -> PrefixOp {
|
pub fn from_sigil(sigil: &str) -> PrefixOp {
|
||||||
PrefixOp { sigil }
|
PrefixOp { sigil: Rc::new(sigil.to_string()) }
|
||||||
}
|
}
|
||||||
pub fn sigil(&self) -> &Rc<String> {
|
pub fn sigil(&self) -> &Rc<String> {
|
||||||
&self.sigil
|
&self.sigil
|
||||||
|
@ -545,7 +545,7 @@ impl Parser {
|
|||||||
_ => unreachable!(),
|
_ => unreachable!(),
|
||||||
};
|
};
|
||||||
let rhs = self.precedence_expr(new_precedence)?;
|
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);
|
lhs = Expression(ExpressionType::BinExp(operation, bx!(lhs), bx!(rhs)), None);
|
||||||
}
|
}
|
||||||
self.parse_level -= 1;
|
self.parse_level -= 1;
|
||||||
@ -561,7 +561,7 @@ impl Parser {
|
|||||||
};
|
};
|
||||||
let expr = self.primary()?;
|
let expr = self.primary()?;
|
||||||
Ok(Expression(
|
Ok(Expression(
|
||||||
ExpressionType::PrefixExp(PrefixOp::from_sigil(sigil), bx!(expr)),
|
ExpressionType::PrefixExp(PrefixOp::from_sigil(sigil.as_str()), bx!(expr)),
|
||||||
None))
|
None))
|
||||||
},
|
},
|
||||||
_ => self.primary()
|
_ => self.primary()
|
||||||
@ -849,13 +849,10 @@ mod parse_tests {
|
|||||||
($string:expr) => { assert!(parse(tokenize($string)).0.is_err()) }
|
($string:expr) => { assert!(parse(tokenize($string)).0.is_err()) }
|
||||||
}
|
}
|
||||||
macro_rules! binexp {
|
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 {
|
macro_rules! prefexp {
|
||||||
($op:expr, $lhs:expr) => { PrefixExp(op!($op), bx!(Expression($lhs, None))) }
|
($op:expr, $lhs:expr) => { PrefixExp(PrefixOp::from_sigil($op), bx!(Expression($lhs, None))) }
|
||||||
}
|
|
||||||
macro_rules! op {
|
|
||||||
($op:expr) => { BinOp::from_sigil($op.to_string()) }
|
|
||||||
}
|
}
|
||||||
macro_rules! val {
|
macro_rules! val {
|
||||||
($var:expr) => { Value(Rc::new($var.to_string()), vec![]) }
|
($var:expr) => { Value(Rc::new($var.to_string()), vec![]) }
|
||||||
|
Loading…
Reference in New Issue
Block a user