about summary refs log tree commit diff
path: root/src/comp/syntax/print
diff options
context:
space:
mode:
authorMarijn Haverbeke <marijnh@gmail.com>2011-12-08 11:56:16 +0100
committerMarijn Haverbeke <marijnh@gmail.com>2011-12-08 12:03:48 +0100
commit9a269a3aa8fe8140ad3f2fc2cfdfd68d6b40ec86 (patch)
treeefb59785d520476c50204eadce27bfb9128ca512 /src/comp/syntax/print
parent8c966b7b18a5529c33dd9766460880bd681ab102 (diff)
downloadrust-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/print')
-rw-r--r--src/comp/syntax/print/pprust.rs8
1 files changed, 7 insertions, 1 deletions
diff --git a/src/comp/syntax/print/pprust.rs b/src/comp/syntax/print/pprust.rs
index 2bb8463e2b9..ff28edd057a 100644
--- a/src/comp/syntax/print/pprust.rs
+++ b/src/comp/syntax/print/pprust.rs
@@ -1062,7 +1062,13 @@ fn print_pat(s: ps, &&pat: @ast::pat) {
     s.ann.pre(ann_node);
     alt pat.node {
       ast::pat_wild. { word(s.s, "_"); }
-      ast::pat_bind(id) { word(s.s, id); }
+      ast::pat_bind(id, sub) {
+        word(s.s, id);
+        alt sub {
+          some(p) { word(s.s, "@"); print_pat(s, p); }
+          _ {}
+        }
+      }
       ast::pat_tag(path, args) {
         print_path(s, path, true);
         if vec::len(args) > 0u {