improve Precedence error message

This commit is contained in:
Folkert 2020-03-31 23:11:35 +02:00
parent d213c7316b
commit 11c8e2bfaa
8 changed files with 257 additions and 40 deletions

View file

@ -1,5 +1,6 @@
use self::BinOp::*;
use std::cmp::Ordering;
use std::fmt;
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
pub enum CalledVia {
@ -109,3 +110,29 @@ impl Ord for BinOp {
self.precedence().cmp(&other.precedence())
}
}
impl std::fmt::Display for BinOp {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
let as_str = match self {
Caret => "^",
Star => "*",
Slash => "/",
DoubleSlash => "//",
Percent => "%",
DoublePercent => "%%",
Plus => "+",
Minus => "-",
Equals => "==",
NotEquals => "!=",
LessThan => "<",
GreaterThan => ">",
LessThanOrEq => "<=",
GreaterThanOrEq => ">=",
And => "&&",
Or => "||",
Pizza => "|>",
};
write!(f, "({})", as_str)
}
}