From 80b6850e34957d95b7606da01d229dc1e3e6e5b5 Mon Sep 17 00:00:00 2001 From: Patrick Walton Date: Mon, 13 Aug 2012 19:59:32 -0700 Subject: libsyntax: Implement [int*3] syntax for fixed length vector types --- src/libsyntax/parse/parser.rs | 30 +++++++++++++++++++++++++++++- 1 file changed, 29 insertions(+), 1 deletion(-) (limited to 'src/libsyntax/parse') diff --git a/src/libsyntax/parse/parser.rs b/src/libsyntax/parse/parser.rs index 30f7243d762..bc69edda1a2 100644 --- a/src/libsyntax/parse/parser.rs +++ b/src/libsyntax/parse/parser.rs @@ -472,7 +472,19 @@ class parser { ty_rec(elems) } else if self.token == token::LBRACKET { self.expect(token::LBRACKET); - let t = ty_vec(self.parse_mt()); + let mut t = ty_vec(self.parse_mt()); + + // Parse the `* 3` in `[ int * 3 ]` + match self.maybe_parse_fixed_vstore_with_star() { + none => {} + some(suffix) => { + t = ty_fixed_length(@{ + id: self.get_id(), + node: t, + span: mk_sp(lo, self.last_span.hi) + }, suffix) + } + } self.expect(token::RBRACKET); t } else if self.token == token::BINOP(token::AND) { @@ -609,6 +621,22 @@ class parser { } } + fn maybe_parse_fixed_vstore_with_star() -> option> { + if self.eat(token::BINOP(token::STAR)) { + match copy self.token { + token::UNDERSCORE => { + self.bump(); some(none) + } + token::LIT_INT_UNSUFFIXED(i) if i >= 0i64 => { + self.bump(); some(some(i as uint)) + } + _ => none + } + } else { + none + } + } + fn lit_from_token(tok: token::token) -> lit_ { match tok { token::LIT_INT(i, it) => lit_int(i, it), -- cgit 1.4.1-3-g733a5