cl-ast: Remove tail from let (it caused more problems that it could've solved)
This commit is contained in:
parent
de63a8c123
commit
8675f91aca
@ -402,7 +402,6 @@ pub struct Let {
|
||||
pub name: Sym,
|
||||
pub ty: Option<Box<Ty>>,
|
||||
pub init: Option<Box<Expr>>,
|
||||
pub tail: Option<Box<Expr>>,
|
||||
}
|
||||
|
||||
/// An [Assign]ment expression: [`Expr`] ([`ModifyKind`] [`Expr`])\+
|
||||
|
@ -443,7 +443,7 @@ mod display {
|
||||
|
||||
impl Display for Let {
|
||||
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
||||
let Self { mutable, name, ty, init, tail } = self;
|
||||
let Self { mutable, name, ty, init } = self;
|
||||
write!(f, "let {mutable}{name}")?;
|
||||
if let Some(value) = ty {
|
||||
write!(f, ": {value}")?;
|
||||
@ -451,9 +451,6 @@ mod display {
|
||||
if let Some(value) = init {
|
||||
write!(f, " = {value}")?;
|
||||
}
|
||||
if let Some(value) = tail {
|
||||
write!(f, ";\n{value}")?;
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
@ -227,13 +227,12 @@ pub trait Fold {
|
||||
s
|
||||
}
|
||||
fn fold_let(&mut self, l: Let) -> Let {
|
||||
let Let { mutable, name, ty, init, tail } = l;
|
||||
let Let { mutable, name, ty, init } = l;
|
||||
Let {
|
||||
mutable: self.fold_mutability(mutable),
|
||||
name: self.fold_sym(name),
|
||||
ty: ty.map(|t| Box::new(self.fold_ty(*t))),
|
||||
init: init.map(|e| Box::new(self.fold_expr(*e))),
|
||||
tail: tail.map(|e| Box::new(self.fold_expr(*e))),
|
||||
}
|
||||
}
|
||||
fn fold_expr(&mut self, e: Expr) -> Expr {
|
||||
|
@ -192,7 +192,7 @@ pub trait Visit<'a>: Sized {
|
||||
}
|
||||
fn visit_semi(&mut self, _s: &'a Semi) {}
|
||||
fn visit_let(&mut self, l: &'a Let) {
|
||||
let Let { mutable, name, ty, init, tail } = l;
|
||||
let Let { mutable, name, ty, init } = l;
|
||||
self.visit_mutability(mutable);
|
||||
self.visit_sym(name);
|
||||
if let Some(ty) = ty {
|
||||
@ -201,9 +201,6 @@ pub trait Visit<'a>: Sized {
|
||||
if let Some(init) = init {
|
||||
self.visit_expr(init)
|
||||
}
|
||||
if let Some(tail) = tail {
|
||||
self.visit_expr(tail)
|
||||
}
|
||||
}
|
||||
fn visit_expr(&mut self, e: &'a Expr) {
|
||||
let Expr { extents, kind } = e;
|
||||
|
@ -116,10 +116,9 @@ impl Interpret for Stmt {
|
||||
}
|
||||
impl Interpret for Let {
|
||||
fn interpret(&self, env: &mut Environment) -> IResult<ConValue> {
|
||||
let Let { mutable: _, name, ty: _, init, tail } = self;
|
||||
let Let { mutable: _, name, ty: _, init } = self;
|
||||
let init = init.as_ref().map(|i| i.interpret(env)).transpose()?;
|
||||
env.insert(*name, init);
|
||||
tail.as_ref().map(|e| e.interpret(env)).transpose()?;
|
||||
Ok(ConValue::Empty)
|
||||
}
|
||||
}
|
||||
|
@ -916,11 +916,6 @@ impl Parse<'_> for Let {
|
||||
} else {
|
||||
None
|
||||
},
|
||||
tail: if p.match_type(TokenKind::Semi, Parsing::Let).is_ok() {
|
||||
Some(Expr::parse(p)?.into())
|
||||
} else {
|
||||
None
|
||||
},
|
||||
})
|
||||
}
|
||||
}
|
||||
|
@ -371,13 +371,12 @@ pub mod yamlify {
|
||||
}
|
||||
impl Yamlify for Let {
|
||||
fn yaml(&self, y: &mut Yamler) {
|
||||
let Self { mutable, name, ty, init, tail } = self;
|
||||
let Self { mutable, name, ty, init } = self;
|
||||
y.key("Let")
|
||||
.pair("name", name)
|
||||
.yaml(mutable)
|
||||
.pair("ty", ty)
|
||||
.pair("init", init)
|
||||
.pair("tail", tail);
|
||||
.pair("init", init);
|
||||
}
|
||||
}
|
||||
impl Yamlify for Expr {
|
||||
|
@ -146,7 +146,7 @@ impl<'a> Visit<'a> for Populator<'_, 'a> {
|
||||
}
|
||||
|
||||
fn visit_let(&mut self, l: &'a cl_ast::Let) {
|
||||
let cl_ast::Let { mutable, name, ty, init, tail } = l;
|
||||
let cl_ast::Let { mutable, name, ty, init } = l;
|
||||
let mut entry = self.new_entry(NodeKind::Local);
|
||||
|
||||
entry.inner.set_source(Source::Local(l));
|
||||
@ -159,9 +159,6 @@ impl<'a> Visit<'a> for Populator<'_, 'a> {
|
||||
if let Some(init) = init {
|
||||
entry.visit_expr(init)
|
||||
}
|
||||
if let Some(tail) = tail {
|
||||
entry.visit_expr(tail)
|
||||
}
|
||||
|
||||
let child = entry.inner.id();
|
||||
self.inner.add_child(*name, child);
|
||||
|
Loading…
Reference in New Issue
Block a user