|
|
@ -31,14 +31,16 @@ impl Unknowns for Exprs { |
|
|
|
|
|
|
|
|
|
|
|
fn write_separated_exprs(es: &Exprs, f: &mut fmt::Formatter, sep: &str) -> fmt::Result { |
|
|
|
fn write_separated_exprs(es: &Exprs, f: &mut fmt::Formatter, sep: &str) -> fmt::Result { |
|
|
|
let mut is_first = true; |
|
|
|
let mut is_first = true; |
|
|
|
|
|
|
|
write!(f, "(")?; |
|
|
|
for e in es { |
|
|
|
for e in es { |
|
|
|
if is_first { |
|
|
|
if is_first { |
|
|
|
is_first = false; |
|
|
|
is_first = false; |
|
|
|
} else { |
|
|
|
} else { |
|
|
|
write!(f, "{}", sep)? |
|
|
|
write!(f, "{}", sep)? |
|
|
|
} |
|
|
|
} |
|
|
|
write!(f, "({})", e)? |
|
|
|
write!(f, "{}", e)? |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
write!(f, ")")?; |
|
|
|
Ok(()) |
|
|
|
Ok(()) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
@ -451,7 +453,7 @@ impl fmt::Display for Expr { |
|
|
|
Const(c) => write!(f, "{}", c), |
|
|
|
Const(c) => write!(f, "{}", c), |
|
|
|
Sum(es) => write_separated_exprs(es, f, " + "), |
|
|
|
Sum(es) => write_separated_exprs(es, f, " + "), |
|
|
|
Product(es) => write_separated_exprs(es, f, " * "), |
|
|
|
Product(es) => write_separated_exprs(es, f, " * "), |
|
|
|
Div(num, den) => write!(f, "({}) / ({})", num, den), |
|
|
|
Div(num, den) => write!(f, "({} / {})", num, den), |
|
|
|
Neg(e) => write!(f, "-({})", e), |
|
|
|
Neg(e) => write!(f, "-({})", e), |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|