From 3f127e397fdba5b982603aaab034f6e9aa0992bb Mon Sep 17 00:00:00 2001 From: Marijn Haverbeke Date: Mon, 15 Aug 2011 13:15:19 +0200 Subject: Add tuple patterns --- src/comp/syntax/parse/parser.rs | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) (limited to 'src/comp/syntax/parse') diff --git a/src/comp/syntax/parse/parser.rs b/src/comp/syntax/parse/parser.rs index 8f7dbd184c3..f28ea683cf9 100644 --- a/src/comp/syntax/parse/parser.rs +++ b/src/comp/syntax/parse/parser.rs @@ -1454,6 +1454,24 @@ fn parse_pat(p: &parser) -> @ast::pat { p.bump(); pat = ast::pat_rec(fields, etc); } + token::LPAREN. { + p.bump(); + if p.peek() == token::RPAREN { + hi = p.get_hi_pos(); + p.bump(); + pat = ast::pat_lit(@{node: ast::lit_nil, span: {lo: lo, hi: hi}}); + } else { + let fields = ~[parse_pat(p)]; + while p.peek() == token::COMMA { + p.bump(); + fields += ~[parse_pat(p)]; + } + if ivec::len(fields) == 1u { expect(p, token::COMMA); } + hi = p.get_hi_pos(); + expect(p, token::RPAREN); + pat = ast::pat_tup(fields); + } + } tok { if !is_ident(tok) || is_word(p, "true") || is_word(p, "false") { let lit = parse_lit(p); -- cgit 1.4.1-3-g733a5