diff options
| author | Tim Chevalier <chevalier@alum.wellesley.edu> | 2012-09-07 17:07:32 -0700 |
|---|---|---|
| committer | Tim Chevalier <chevalier@alum.wellesley.edu> | 2012-09-07 17:09:07 -0700 |
| commit | 53ce42dc4f4fceaf6881a3026f3dbc8fd81ae626 (patch) | |
| tree | fe06630b44b10afc5708cbebdacb9f8471580ab3 /src/libsyntax/parse | |
| parent | e9f5a099dfcb42c7f2bb38974b57bbde7042ee9c (diff) | |
| download | rust-53ce42dc4f4fceaf6881a3026f3dbc8fd81ae626.tar.gz rust-53ce42dc4f4fceaf6881a3026f3dbc8fd81ae626.zip | |
Implement &-patterns
Closes #2855
Diffstat (limited to 'src/libsyntax/parse')
| -rw-r--r-- | src/libsyntax/parse/parser.rs | 23 |
1 files changed, 21 insertions, 2 deletions
diff --git a/src/libsyntax/parse/parser.rs b/src/libsyntax/parse/parser.rs index 175247bfaf3..a21d9de7567 100644 --- a/src/libsyntax/parse/parser.rs +++ b/src/libsyntax/parse/parser.rs @@ -42,8 +42,8 @@ use ast::{_mod, add, alt_check, alt_exhaustive, arg, arm, attribute, mac_invoc_tt, mac_var, matcher, match_nonterminal, match_seq, match_tok, method, mode, module_ns, mt, mul, mutability, named_field, neg, noreturn, not, pat, pat_box, pat_enum, - pat_ident, pat_lit, pat_range, pat_rec, pat_struct, pat_tup, - pat_uniq, pat_wild, path, private, proto, proto_bare, + pat_ident, pat_lit, pat_range, pat_rec, pat_region, pat_struct, + pat_tup, pat_uniq, pat_wild, path, private, proto, proto_bare, proto_block, proto_box, proto_uniq, provided, public, pure_fn, purity, re_anon, re_named, region, rem, required, ret_style, return_val, self_ty, shl, shr, stmt, stmt_decl, stmt_expr, @@ -1844,6 +1844,25 @@ struct parser { }; } + token::BINOP(token::AND) => { + let lo = self.span.lo; + self.bump(); + let sub = self.parse_pat(refutable); + hi = sub.span.hi; + // HACK: parse &"..." as a literal of a borrowed str + pat = match sub.node { + pat_lit(e@@{ + node: expr_lit(@{node: lit_str(_), span: _}), _ + }) => { + let vst = @{id: self.get_id(), callee_id: self.get_id(), + node: expr_vstore(e, + vstore_slice(self.region_from_name(None))), + span: mk_sp(lo, hi)}; + pat_lit(vst) + } + _ => pat_region(sub) + }; + } token::LBRACE => { self.bump(); let (fields, etc) = self.parse_pat_fields(refutable); |
