Allow omission of the '.' after nullary tag patterns
This commit allows patterns like:
alt x { some(_) { ... } none { } }
without the '.' after none. The parser suspends judgment about
whether a bare ident is a tag or a new bound variable; instead,
the resolver disambiguates.
This means that any code after resolution that pattern-matches on
patterns needs to call pat_util::normalize_pat, which consults
an environment to do this disambiguation.
In addition, local variables are no longer allowed to shadow
tag names, so this required changing some code (e.g. renaming
variables named "mut", and renaming ast::sub to subtract).
The parser currently accepts patterns with and without the '.'.
Once the compiler and libraries are changed, it will no longer
accept the '.'.
This commit is contained in:
@@ -10,6 +10,7 @@ export make_fold;
|
||||
export noop_fold_crate;
|
||||
export noop_fold_item;
|
||||
export noop_fold_expr;
|
||||
export noop_fold_pat;
|
||||
export noop_fold_mod;
|
||||
export noop_fold_ty;
|
||||
|
||||
@@ -273,8 +274,8 @@ fn noop_fold_arm(a: arm, fld: ast_fold) -> arm {
|
||||
fn noop_fold_pat(p: pat_, fld: ast_fold) -> pat_ {
|
||||
ret alt p {
|
||||
pat_wild. { p }
|
||||
pat_bind(ident, sub) {
|
||||
pat_bind(fld.fold_ident(ident), option::map(sub, fld.fold_pat))
|
||||
pat_ident(pth, sub) {
|
||||
pat_ident(fld.fold_path(pth), option::map(sub, fld.fold_pat))
|
||||
}
|
||||
pat_lit(_) { p }
|
||||
pat_tag(pth, pats) {
|
||||
@@ -317,8 +318,8 @@ fn noop_fold_expr(e: expr_, fld: ast_fold) -> expr_ {
|
||||
let fold_mac = bind fold_mac_(_, fld);
|
||||
|
||||
ret alt e {
|
||||
expr_vec(exprs, mut) {
|
||||
expr_vec(fld.map_exprs(fld.fold_expr, exprs), mut)
|
||||
expr_vec(exprs, mutt) {
|
||||
expr_vec(fld.map_exprs(fld.fold_expr, exprs), mutt)
|
||||
}
|
||||
expr_rec(fields, maybe_expr) {
|
||||
expr_rec(vec::map(fields, fold_field),
|
||||
@@ -390,8 +391,7 @@ fn noop_fold_expr(e: expr_, fld: ast_fold) -> expr_ {
|
||||
}
|
||||
expr_path(pth) { expr_path(fld.fold_path(pth)) }
|
||||
expr_fail(e) { expr_fail(option::map(e, fld.fold_expr)) }
|
||||
expr_break. { e }
|
||||
expr_cont. { e }
|
||||
expr_break. | expr_cont. { e }
|
||||
expr_ret(e) { expr_ret(option::map(e, fld.fold_expr)) }
|
||||
expr_be(e) { expr_be(fld.fold_expr(e)) }
|
||||
expr_log(i, lv, e) { expr_log(i, fld.fold_expr(lv),
|
||||
|
||||
Reference in New Issue
Block a user