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/parse | |
| 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/parse')
| -rw-r--r-- | src/comp/syntax/parse/parser.rs | 11 |
1 files changed, 6 insertions, 5 deletions
diff --git a/src/comp/syntax/parse/parser.rs b/src/comp/syntax/parse/parser.rs index 2bf7865bf81..5748637fde4 100644 --- a/src/comp/syntax/parse/parser.rs +++ b/src/comp/syntax/parse/parser.rs @@ -1429,10 +1429,9 @@ fn parse_pat(p: parser) -> @ast::pat { if p.get_bad_expr_words().contains_key(fieldname) { p.fatal("found " + fieldname + " in binding position"); } - subpat = - @{id: p.get_id(), - node: ast::pat_bind(fieldname), - span: ast_util::mk_sp(lo, hi)}; + subpat = @{id: p.get_id(), + node: ast::pat_bind(fieldname, none), + span: ast_util::mk_sp(lo, hi)}; } fields += [{ident: fieldname, pat: subpat}]; } @@ -1479,7 +1478,9 @@ fn parse_pat(p: parser) -> @ast::pat { _ { true } } { hi = p.get_hi_pos(); - pat = ast::pat_bind(parse_value_ident(p)); + let name = parse_value_ident(p); + let sub = eat(p, token::AT) ? some(parse_pat(p)) : none; + pat = ast::pat_bind(name, sub); } else { let tag_path = parse_path_and_ty_param_substs(p); hi = tag_path.span.hi; |
