doughlang: Expressions in patterns

ast:
- Document operators
- Parameterize Pat with Annotation
- Consolidate Path and Lit into "Value" (Expr)
- Consolidate NamedRecord/Namedtuple into PatOp::TypePrefixed
- Allow Pat<Pat,*> patterns
- Additional helper functions on Expr and Pat

lexer:
- Support inner-doc comment syntax `//!`
  - Cleans up `///` or `//!` prefix

parser:
- Make Parse::Prec `Default`
- Allow expression elision after `..`/`..=`
- Fix Parser::consume not updating elide_do state
- Add token splitting, to make `&&Expr` and `&&Pat` easier
- error: Embed Pat precedence in ParseError
This commit is contained in:
2026-01-05 15:17:22 -05:00
parent d6104b6a0b
commit e4c008bd4b
16 changed files with 700 additions and 322 deletions

View File

@@ -45,7 +45,7 @@ pub trait Fold<A: Annotation> {
}
/// Consumes a [`Pat`], possibly transforms it, and produces a replacement [`Pat`]
fn fold_pat(&mut self, pat: Pat) -> Result<Pat, Self::Error> {
fn fold_pat(&mut self, pat: Pat<A>) -> Result<Pat<A>, Self::Error> {
pat.children(self)
}
@@ -138,7 +138,7 @@ impl<A: Annotation> Foldable<A> for Use {
}
}
impl<A: Annotation> Foldable<A> for Pat {
impl<A: Annotation> Foldable<A> for Pat<A> {
fn fold_in<F: Fold<A> + ?Sized>(self, folder: &mut F) -> Result<Self, F::Error> {
folder.fold_pat(self)
}
@@ -149,14 +149,7 @@ impl<A: Annotation> Foldable<A> for Pat {
Self::Never => Self::Never,
Self::MetId(name) => Self::MetId(name.fold_in(folder)?),
Self::Name(name) => Self::Name(name.fold_in(folder)?),
Self::Path(path) => Self::Path(path.fold_in(folder)?),
Self::NamedRecord(path, pat) => {
Self::NamedRecord(path.fold_in(folder)?, pat.fold_in(folder)?)
}
Self::NamedTuple(path, pat) => {
Self::NamedTuple(path.fold_in(folder)?, pat.fold_in(folder)?)
}
Self::Lit(literal) => Self::Lit(literal.fold_in(folder)?),
Self::Value(expr) => Self::Value(expr.fold_in(folder)?),
Self::Op(op, pats) => Self::Op(op, pats.fold_in(folder)?),
})
}