libsyntax: Implement [int*3] syntax for fixed length vector types

This commit is contained in:
Patrick Walton 2012-08-13 19:59:32 -07:00
parent 36883186ab
commit 80b6850e34
2 changed files with 34 additions and 1 deletions

View File

@ -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<option<uint>> {
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),

View File

@ -0,0 +1,5 @@
fn main() {
let x: [int*4] = [1, 2, 3, 4];
io::println(fmt!("%d", x[0]));
}