ast: rename Let to Bind

This commit is contained in:
2025-10-20 00:39:56 -04:00
parent 458e95a8ed
commit 0015ac5f1b
3 changed files with 31 additions and 28 deletions

View File

@@ -106,15 +106,18 @@ pub enum Ty {
Fn(Vec<Ty>),
}
/// A `let` binding
/// A pattern binding
/// ```ignore
/// let Pat (= Expr)?
/// let Pat (= Expr (else Expr)?)?
/// const Pat (= Expr (else Expr)?)?
/// static Pat (= Expr (else Expr)?)?
/// Pat => Expr // in match
/// ``````
#[derive(Clone, Debug, PartialEq, Eq)]
pub struct Let<A: Annotation = Span>(pub LetKind, pub Pat, pub Vec<Anno<Expr<A>, A>>);
pub struct Bind<A: Annotation = Span>(pub BindKind, pub Pat, pub Vec<Anno<Expr<A>, A>>);
#[derive(Clone, Debug, PartialEq, Eq)]
pub enum LetKind {
pub enum BindKind {
/// A `let Pat (= Expr (else Expr)?)?` binding
Let,
/// A `const Pat = Expr` binding
@@ -174,8 +177,8 @@ pub enum Expr<A: Annotation = Span> {
MetId(String),
/// A literal bool, string, char, or int
Lit(Literal),
/// let Pat<NoTopAlt> = expr
Let(Box<Let<A>>),
/// (let | const | static) Pat<NoTopAlt> (= expr (else expr)?)?
Bind(Box<Bind<A>>),
/// (struct | enum | type) Pat<NoTopAlt>
Struct(Box<Typedef>),
/// `| Pat<Tuple> | Expr` | `|| Expr` | `fn Ident? (Pat,*) Expr`
@@ -336,11 +339,11 @@ impl<A: Annotation> Display for Fn<A> {
}
}
impl<A: Annotation> Display for Let<A> {
impl<A: Annotation> Display for Bind<A> {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
let Self(op, pat, exprs) = self;
if let LetKind::Match = op {
if let BindKind::Match = op {
return f.delimit(fmt!("{pat} => "), "").list(exprs, ",!? ");
}
@@ -353,7 +356,7 @@ impl<A: Annotation> Display for Let<A> {
}
}
impl Display for LetKind {
impl Display for BindKind {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
f.write_str(match self {
Self::Let => "let",
@@ -404,7 +407,7 @@ impl<A: Annotation> Display for Expr<A> {
Self::Id(id) => id.fmt(f),
Self::MetId(id) => write!(f, "`{id}"),
Self::Lit(literal) => literal.fmt(f),
Self::Let(v) => v.fmt(f),
Self::Bind(v) => v.fmt(f),
Self::Struct(v) => v.fmt(f),
Self::Make(v) => v.fmt(f),
Self::Mod(v) => v.fmt(f),