Make Expr Debug more compact and less ambiguous
This commit is contained in:
parent
94198d126f
commit
4be5283204
1 changed files with 97 additions and 1 deletions
|
|
@ -1,3 +1,5 @@
|
|||
use std::fmt::{self, write};
|
||||
|
||||
use crate::span::{HasSpan, Span};
|
||||
|
||||
use super::{Call, Field, FuncDef, Lit, Space, TableConstr, TableDestr, Var};
|
||||
|
|
@ -24,7 +26,7 @@ pub enum BinOp {
|
|||
Or,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone)]
|
||||
#[derive(Clone)]
|
||||
pub enum Expr {
|
||||
Lit(Lit),
|
||||
Call(Call),
|
||||
|
|
@ -79,6 +81,100 @@ pub enum Expr {
|
|||
},
|
||||
}
|
||||
|
||||
impl fmt::Debug for Expr {
|
||||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||
match self {
|
||||
Self::Lit(lit) => {
|
||||
f.write_str("Expr::Lit(")?;
|
||||
lit.fmt(f)?;
|
||||
f.write_str(")")
|
||||
}
|
||||
Self::Call(call) => {
|
||||
f.write_str("Expr::Call(")?;
|
||||
call.fmt(f)?;
|
||||
f.write_str(")")
|
||||
}
|
||||
Self::Field(field) => {
|
||||
f.write_str("Expr::Field(")?;
|
||||
field.fmt(f)?;
|
||||
f.write_str(")")
|
||||
}
|
||||
Self::Var(var) => {
|
||||
f.write_str("Expr::Var(")?;
|
||||
var.fmt(f)?;
|
||||
f.write_str(")")
|
||||
}
|
||||
Self::TableConstr(constr) => {
|
||||
f.write_str("Expr::TableConstr(")?;
|
||||
constr.fmt(f)?;
|
||||
f.write_str(")")
|
||||
}
|
||||
Self::TableDestr(destr) => {
|
||||
f.write_str("Expr::TableDestr(")?;
|
||||
destr.fmt(f)?;
|
||||
f.write_str(")")
|
||||
}
|
||||
Self::FuncDef(def) => {
|
||||
f.write_str("Expr::FuncDef(")?;
|
||||
def.fmt(f)?;
|
||||
f.write_str(")")
|
||||
}
|
||||
Self::Paren {
|
||||
s0,
|
||||
inner,
|
||||
s1,
|
||||
span,
|
||||
} => f
|
||||
.debug_struct("Expr::Paren")
|
||||
.field("s0", s0)
|
||||
.field("inner", inner)
|
||||
.field("s1", s1)
|
||||
.field("span", span)
|
||||
.finish(),
|
||||
Self::Neg {
|
||||
minus,
|
||||
s0,
|
||||
expr,
|
||||
span,
|
||||
} => f
|
||||
.debug_struct("Expr::Neg")
|
||||
.field("minus", minus)
|
||||
.field("s0", s0)
|
||||
.field("expr", expr)
|
||||
.field("span", span)
|
||||
.finish(),
|
||||
Self::Not {
|
||||
not,
|
||||
s0,
|
||||
expr,
|
||||
span,
|
||||
} => f
|
||||
.debug_struct("Expr::Not")
|
||||
.field("not", not)
|
||||
.field("s0", s0)
|
||||
.field("expr", expr)
|
||||
.field("span", span)
|
||||
.finish(),
|
||||
Self::BinOp {
|
||||
left,
|
||||
s0,
|
||||
op,
|
||||
s1,
|
||||
right,
|
||||
span,
|
||||
} => f
|
||||
.debug_struct("Expr::BinOp")
|
||||
.field("left", left)
|
||||
.field("s0", s0)
|
||||
.field("op", op)
|
||||
.field("s1", s1)
|
||||
.field("right", right)
|
||||
.field("span", span)
|
||||
.finish(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl HasSpan for Expr {
|
||||
fn span(&self) -> Span {
|
||||
match self {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue