mirror of
https://github.com/roc-lang/roc.git
synced 2025-09-28 22:34:45 +00:00
improve Precedence error message
This commit is contained in:
parent
d213c7316b
commit
11c8e2bfaa
8 changed files with 257 additions and 40 deletions
|
@ -165,7 +165,7 @@ pub enum Expr<'a> {
|
|||
MalformedClosure,
|
||||
// Both operators were non-associative, e.g. (True == False == False).
|
||||
// We should tell the author to disambiguate by grouping them with parens.
|
||||
PrecedenceConflict(Loc<BinOp>, Loc<BinOp>, &'a Loc<Expr<'a>>),
|
||||
PrecedenceConflict(Region, Loc<BinOp>, Loc<BinOp>, &'a Loc<Expr<'a>>),
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, PartialEq)]
|
||||
|
|
|
@ -323,7 +323,7 @@ fn expr_to_pattern<'a>(arena: &'a Bump, expr: &Expr<'a>) -> Result<Pattern<'a>,
|
|||
| Expr::If(_, _, _)
|
||||
| Expr::When(_, _)
|
||||
| Expr::MalformedClosure
|
||||
| Expr::PrecedenceConflict(_, _, _)
|
||||
| Expr::PrecedenceConflict(_, _, _, _)
|
||||
| Expr::Record {
|
||||
update: Some(_), ..
|
||||
}
|
||||
|
|
|
@ -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)
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue