cl-ast: Remove tail from let (it caused more problems that it could've solved)

This commit is contained in:
John 2024-07-31 03:19:20 -05:00
parent de63a8c123
commit 8675f91aca
8 changed files with 7 additions and 25 deletions

View File

@ -402,7 +402,6 @@ pub struct Let {
pub name: Sym, pub name: Sym,
pub ty: Option<Box<Ty>>, pub ty: Option<Box<Ty>>,
pub init: Option<Box<Expr>>, pub init: Option<Box<Expr>>,
pub tail: Option<Box<Expr>>,
} }
/// An [Assign]ment expression: [`Expr`] ([`ModifyKind`] [`Expr`])\+ /// An [Assign]ment expression: [`Expr`] ([`ModifyKind`] [`Expr`])\+

View File

@ -443,7 +443,7 @@ mod display {
impl Display for Let { impl Display for Let {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { 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}")?; write!(f, "let {mutable}{name}")?;
if let Some(value) = ty { if let Some(value) = ty {
write!(f, ": {value}")?; write!(f, ": {value}")?;
@ -451,9 +451,6 @@ mod display {
if let Some(value) = init { if let Some(value) = init {
write!(f, " = {value}")?; write!(f, " = {value}")?;
} }
if let Some(value) = tail {
write!(f, ";\n{value}")?;
}
Ok(()) Ok(())
} }
} }

View File

@ -227,13 +227,12 @@ pub trait Fold {
s s
} }
fn fold_let(&mut self, l: Let) -> Let { fn fold_let(&mut self, l: Let) -> Let {
let Let { mutable, name, ty, init, tail } = l; let Let { mutable, name, ty, init } = l;
Let { Let {
mutable: self.fold_mutability(mutable), mutable: self.fold_mutability(mutable),
name: self.fold_sym(name), name: self.fold_sym(name),
ty: ty.map(|t| Box::new(self.fold_ty(*t))), ty: ty.map(|t| Box::new(self.fold_ty(*t))),
init: init.map(|e| Box::new(self.fold_expr(*e))), 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 { fn fold_expr(&mut self, e: Expr) -> Expr {

View File

@ -192,7 +192,7 @@ pub trait Visit<'a>: Sized {
} }
fn visit_semi(&mut self, _s: &'a Semi) {} fn visit_semi(&mut self, _s: &'a Semi) {}
fn visit_let(&mut self, l: &'a Let) { 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_mutability(mutable);
self.visit_sym(name); self.visit_sym(name);
if let Some(ty) = ty { if let Some(ty) = ty {
@ -201,9 +201,6 @@ pub trait Visit<'a>: Sized {
if let Some(init) = init { if let Some(init) = init {
self.visit_expr(init) self.visit_expr(init)
} }
if let Some(tail) = tail {
self.visit_expr(tail)
}
} }
fn visit_expr(&mut self, e: &'a Expr) { fn visit_expr(&mut self, e: &'a Expr) {
let Expr { extents, kind } = e; let Expr { extents, kind } = e;

View File

@ -116,10 +116,9 @@ impl Interpret for Stmt {
} }
impl Interpret for Let { impl Interpret for Let {
fn interpret(&self, env: &mut Environment) -> IResult<ConValue> { 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()?; let init = init.as_ref().map(|i| i.interpret(env)).transpose()?;
env.insert(*name, init); env.insert(*name, init);
tail.as_ref().map(|e| e.interpret(env)).transpose()?;
Ok(ConValue::Empty) Ok(ConValue::Empty)
} }
} }

View File

@ -916,11 +916,6 @@ impl Parse<'_> for Let {
} else { } else {
None None
}, },
tail: if p.match_type(TokenKind::Semi, Parsing::Let).is_ok() {
Some(Expr::parse(p)?.into())
} else {
None
},
}) })
} }
} }

View File

@ -371,13 +371,12 @@ pub mod yamlify {
} }
impl Yamlify for Let { impl Yamlify for Let {
fn yaml(&self, y: &mut Yamler) { fn yaml(&self, y: &mut Yamler) {
let Self { mutable, name, ty, init, tail } = self; let Self { mutable, name, ty, init } = self;
y.key("Let") y.key("Let")
.pair("name", name) .pair("name", name)
.yaml(mutable) .yaml(mutable)
.pair("ty", ty) .pair("ty", ty)
.pair("init", init) .pair("init", init);
.pair("tail", tail);
} }
} }
impl Yamlify for Expr { impl Yamlify for Expr {

View File

@ -146,7 +146,7 @@ impl<'a> Visit<'a> for Populator<'_, 'a> {
} }
fn visit_let(&mut self, l: &'a cl_ast::Let) { 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); let mut entry = self.new_entry(NodeKind::Local);
entry.inner.set_source(Source::Local(l)); entry.inner.set_source(Source::Local(l));
@ -159,9 +159,6 @@ impl<'a> Visit<'a> for Populator<'_, 'a> {
if let Some(init) = init { if let Some(init) = init {
entry.visit_expr(init) entry.visit_expr(init)
} }
if let Some(tail) = tail {
entry.visit_expr(tail)
}
let child = entry.inner.id(); let child = entry.inner.id();
self.inner.add_child(*name, child); self.inner.add_child(*name, child);