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

@@ -214,7 +214,7 @@ pub trait Visit<'a>: Sized {
fn visit_pattern(&mut self, p: &'a Pattern) {
match p {
Pattern::Path(path) => self.visit_path(path),
Pattern::Name(name) => self.visit_sym(name),
Pattern::Literal(literal) => self.visit_literal(literal),
Pattern::Ref(mutability, pattern) => {
self.visit_mutability(mutability);
@@ -347,7 +347,7 @@ pub trait Visit<'a>: Sized {
}
fn visit_for(&mut self, f: &'a For) {
let For { bind, cond, pass, fail } = f;
self.visit_sym(bind);
self.visit_pattern(bind);
self.visit_expr(cond);
self.visit_block(pass);
self.visit_else(fail);