diff options
| author | Marijn Haverbeke <marijnh@gmail.com> | 2011-12-08 11:56:16 +0100 |
|---|---|---|
| committer | Marijn Haverbeke <marijnh@gmail.com> | 2011-12-08 12:03:48 +0100 |
| commit | 9a269a3aa8fe8140ad3f2fc2cfdfd68d6b40ec86 (patch) | |
| tree | efb59785d520476c50204eadce27bfb9128ca512 /src/comp/syntax/fold.rs | |
| parent | 8c966b7b18a5529c33dd9766460880bd681ab102 (diff) | |
| download | rust-9a269a3aa8fe8140ad3f2fc2cfdfd68d6b40ec86.tar.gz rust-9a269a3aa8fe8140ad3f2fc2cfdfd68d6b40ec86.zip | |
Allow binding of nested patterns
See src/test/run-pass/nested-patterns.rs for some examples. The syntax is
boundvar@subpattern
Which will match the subpattern as usual, but also bind boundvar to the
whole matched value.
Closes #838
Diffstat (limited to 'src/comp/syntax/fold.rs')
| -rw-r--r-- | src/comp/syntax/fold.rs | 4 |
1 files changed, 3 insertions, 1 deletions
diff --git a/src/comp/syntax/fold.rs b/src/comp/syntax/fold.rs index 0e76e9a15d1..ce82c4d7c3b 100644 --- a/src/comp/syntax/fold.rs +++ b/src/comp/syntax/fold.rs @@ -270,7 +270,9 @@ 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) { pat_bind(fld.fold_ident(ident)) } + pat_bind(ident, sub) { + pat_bind(fld.fold_ident(ident), option::map(fld.fold_pat, sub)) + } pat_lit(_) { p } pat_tag(pth, pats) { pat_tag(fld.fold_path(pth), vec::map(fld.fold_pat, pats)) |
