conlang: Patterns...2!

- Deny arbitrary paths in patterns (only one non-keyword identifier allowed!)
- Allow patterns in for-loop binders (literally useless atm, but it's a step toward making patterns the only way to bind names.)

Next: Functions, Tuple Struct Patterns... And solving the stupid syntactic ambiguity of structors.
This commit is contained in:
2025-02-22 01:00:29 -06:00
parent b115fea71b
commit 5d2c714bc1
8 changed files with 85 additions and 113 deletions

View File

@@ -418,12 +418,12 @@ pub struct Let {
/// A [Pattern] meta-expression (any [`ExprKind`] that fits pattern rules)
#[derive(Clone, Debug, PartialEq, Eq, Hash)]
pub enum Pattern {
Path(Path),
Name(Sym),
Literal(Literal),
Ref(Mutability, Box<Pattern>),
Tuple(Vec<Pattern>),
Array(Vec<Pattern>),
Struct(Path, Vec<(Path, Option<Pattern>)>),
Struct(Path, Vec<(Sym, Option<Pattern>)>),
}
/// A `match` expression: `match` `{` ([MatchArm] `,`)* [MatchArm]? `}`
@@ -620,7 +620,7 @@ pub struct If {
/// A [For] expression: `for` Pattern `in` [`Expr`] [`Block`] [`Else`]?
#[derive(Clone, Debug, PartialEq, Eq, Hash)]
pub struct For {
pub bind: Sym, // TODO: Patterns?
pub bind: Pattern,
pub cond: Box<Expr>,
pub pass: Box<Block>,
pub fail: Else,