libsyntax: Implement [int*3] syntax for fixed length vector types
This commit is contained in:
parent
36883186ab
commit
80b6850e34
@ -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),
|
||||
|
5
src/test/run-pass/vec-fixed-length.rs
Normal file
5
src/test/run-pass/vec-fixed-length.rs
Normal file
@ -0,0 +1,5 @@
|
||||
fn main() {
|
||||
let x: [int*4] = [1, 2, 3, 4];
|
||||
io::println(fmt!("%d", x[0]));
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user