cl-ast: Move loop expression into unary exprs (with lowest priority)
This commit is contained in:
@@ -392,8 +392,6 @@ pub enum ExprKind {
|
||||
Group(Group),
|
||||
/// A [Tuple] expression: `(` [`Expr`] (`,` [`Expr`])+ `)`
|
||||
Tuple(Tuple),
|
||||
/// A [Loop] expression: `loop` [`Block`]
|
||||
Loop(Loop),
|
||||
/// A [While] expression: `while` [`Expr`] [`Block`] [`Else`]?
|
||||
While(While),
|
||||
/// An [If] expression: `if` [`Expr`] [`Block`] [`Else`]?
|
||||
@@ -482,6 +480,8 @@ pub enum UnaryKind {
|
||||
Deref,
|
||||
Neg,
|
||||
Not,
|
||||
/// A Loop expression: `loop` [`Block`]
|
||||
Loop,
|
||||
/// Unused
|
||||
At,
|
||||
/// Unused
|
||||
@@ -570,12 +570,6 @@ pub struct Tuple {
|
||||
pub exprs: Vec<Expr>,
|
||||
}
|
||||
|
||||
/// A [Loop] expression: `loop` [`Block`]
|
||||
#[derive(Clone, Debug, PartialEq, Eq, Hash)]
|
||||
pub struct Loop {
|
||||
pub body: Box<Expr>,
|
||||
}
|
||||
|
||||
/// A [While] expression: `while` [`Expr`] [`Block`] [`Else`]?
|
||||
#[derive(Clone, Debug, PartialEq, Eq, Hash)]
|
||||
pub struct While {
|
||||
|
||||
@@ -448,7 +448,6 @@ mod display {
|
||||
ExprKind::Block(v) => v.fmt(f),
|
||||
ExprKind::Group(v) => v.fmt(f),
|
||||
ExprKind::Tuple(v) => v.fmt(f),
|
||||
ExprKind::Loop(v) => v.fmt(f),
|
||||
ExprKind::While(v) => v.fmt(f),
|
||||
ExprKind::If(v) => v.fmt(f),
|
||||
ExprKind::For(v) => v.fmt(f),
|
||||
@@ -542,6 +541,7 @@ mod display {
|
||||
impl Display for UnaryKind {
|
||||
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
||||
match self {
|
||||
UnaryKind::Loop => "loop ",
|
||||
UnaryKind::Deref => "*",
|
||||
UnaryKind::Neg => "-",
|
||||
UnaryKind::Not => "!",
|
||||
@@ -644,13 +644,6 @@ mod display {
|
||||
}
|
||||
}
|
||||
|
||||
impl Display for Loop {
|
||||
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
||||
let Self { body } = self;
|
||||
write!(f, "loop {body}")
|
||||
}
|
||||
}
|
||||
|
||||
impl Display for While {
|
||||
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
||||
let Self { cond, pass, fail } = self;
|
||||
@@ -786,7 +779,6 @@ mod convert {
|
||||
Block => ExprKind::Block,
|
||||
Group => ExprKind::Group,
|
||||
Tuple => ExprKind::Tuple,
|
||||
Loop => ExprKind::Loop,
|
||||
While => ExprKind::While,
|
||||
If => ExprKind::If,
|
||||
For => ExprKind::For,
|
||||
|
||||
@@ -339,10 +339,6 @@ pub trait Fold {
|
||||
let Tuple { exprs } = t;
|
||||
Tuple { exprs: exprs.into_iter().map(|e| self.fold_expr(e)).collect() }
|
||||
}
|
||||
fn fold_loop(&mut self, l: Loop) -> Loop {
|
||||
let Loop { body } = l;
|
||||
Loop { body: Box::new(self.fold_expr(*body)) }
|
||||
}
|
||||
fn fold_while(&mut self, w: While) -> While {
|
||||
let While { cond, pass, fail } = w;
|
||||
While {
|
||||
@@ -552,7 +548,6 @@ pub fn or_fold_expr_kind<F: Fold + ?Sized>(folder: &mut F, kind: ExprKind) -> Ex
|
||||
ExprKind::Block(b) => ExprKind::Block(folder.fold_block(b)),
|
||||
ExprKind::Group(g) => ExprKind::Group(folder.fold_group(g)),
|
||||
ExprKind::Tuple(t) => ExprKind::Tuple(folder.fold_tuple(t)),
|
||||
ExprKind::Loop(l) => ExprKind::Loop(folder.fold_loop(l)),
|
||||
ExprKind::While(w) => ExprKind::While(folder.fold_while(w)),
|
||||
ExprKind::If(i) => ExprKind::If(folder.fold_if(i)),
|
||||
ExprKind::For(f) => ExprKind::For(folder.fold_for(f)),
|
||||
|
||||
@@ -297,10 +297,6 @@ pub trait Visit<'a>: Sized {
|
||||
let Tuple { exprs } = t;
|
||||
exprs.iter().for_each(|e| self.visit_expr(e))
|
||||
}
|
||||
fn visit_loop(&mut self, l: &'a Loop) {
|
||||
let Loop { body } = l;
|
||||
self.visit_expr(body)
|
||||
}
|
||||
fn visit_while(&mut self, w: &'a While) {
|
||||
let While { cond, pass, fail } = w;
|
||||
self.visit_expr(cond);
|
||||
@@ -476,7 +472,6 @@ pub fn or_visit_expr_kind<'a, V: Visit<'a>>(visitor: &mut V, e: &'a ExprKind) {
|
||||
ExprKind::Block(b) => visitor.visit_block(b),
|
||||
ExprKind::Group(g) => visitor.visit_group(g),
|
||||
ExprKind::Tuple(t) => visitor.visit_tuple(t),
|
||||
ExprKind::Loop(l) => visitor.visit_loop(l),
|
||||
ExprKind::While(w) => visitor.visit_while(w),
|
||||
ExprKind::If(i) => visitor.visit_if(i),
|
||||
ExprKind::For(f) => visitor.visit_for(f),
|
||||
|
||||
@@ -26,8 +26,8 @@ fn desugar_while(extents: Span, kind: ExprKind) -> ExprKind {
|
||||
let break_expr = Expr { extents: fail_span, kind: ExprKind::Break(Break { body }) };
|
||||
|
||||
let loop_body = If { cond, pass, fail: Else { body: Some(Box::new(break_expr)) } };
|
||||
let loop_body = Expr { extents, kind: ExprKind::If(loop_body) };
|
||||
ExprKind::Loop(Loop { body: Box::new(loop_body) })
|
||||
let loop_body = ExprKind::If(loop_body);
|
||||
ExprKind::Unary(Unary { kind: UnaryKind::Loop, tail: Box::new(loop_body) })
|
||||
}
|
||||
_ => kind,
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user