diff options
| author | Marijn Haverbeke <marijnh@gmail.com> | 2011-08-15 13:15:19 +0200 |
|---|---|---|
| committer | Marijn Haverbeke <marijnh@gmail.com> | 2011-08-15 13:20:16 +0200 |
| commit | 3f127e397fdba5b982603aaab034f6e9aa0992bb (patch) | |
| tree | 07fc3b6fb6fc599b2ce38fa481c507ea612f9471 /src/comp/syntax/parse | |
| parent | 1ee24d31e139683a93c6afa93689f5a4122341be (diff) | |
| download | rust-3f127e397fdba5b982603aaab034f6e9aa0992bb.tar.gz rust-3f127e397fdba5b982603aaab034f6e9aa0992bb.zip | |
Add tuple patterns
Diffstat (limited to 'src/comp/syntax/parse')
| -rw-r--r-- | src/comp/syntax/parse/parser.rs | 18 |
1 files changed, 18 insertions, 0 deletions
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); |
