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:
@@ -248,7 +248,7 @@ pub trait Fold {
|
||||
|
||||
fn fold_pattern(&mut self, p: Pattern) -> Pattern {
|
||||
match p {
|
||||
Pattern::Path(path) => Pattern::Path(self.fold_path(path)),
|
||||
Pattern::Name(sym) => Pattern::Name(self.fold_sym(sym)),
|
||||
Pattern::Literal(literal) => Pattern::Literal(self.fold_literal(literal)),
|
||||
Pattern::Ref(mutability, pattern) => Pattern::Ref(
|
||||
self.fold_mutability(mutability),
|
||||
@@ -285,7 +285,7 @@ pub trait Fold {
|
||||
let MatchArm(pat, expr) = a;
|
||||
MatchArm(self.fold_pattern(pat), self.fold_expr(expr))
|
||||
}
|
||||
|
||||
|
||||
fn fold_assign(&mut self, a: Assign) -> Assign {
|
||||
let Assign { parts } = a;
|
||||
let (head, tail) = *parts;
|
||||
@@ -400,7 +400,7 @@ pub trait Fold {
|
||||
fn fold_for(&mut self, f: For) -> For {
|
||||
let For { bind, cond, pass, fail } = f;
|
||||
For {
|
||||
bind: self.fold_sym(bind),
|
||||
bind: self.fold_pattern(bind),
|
||||
cond: Box::new(self.fold_expr(*cond)),
|
||||
pass: Box::new(self.fold_block(*pass)),
|
||||
fail: self.fold_else(fail),
|
||||
|
||||
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user