libsyntax: Implement the new box syntax for unique pointers.

This commit is contained in:
Patrick Walton 2013-12-12 10:42:03 -08:00
parent a87786e3e9
commit 775ccadd25
3 changed files with 33 additions and 7 deletions

View File

@ -2326,6 +2326,22 @@ pub fn parse_prefix_expr(&self) -> @Expr {
_ => self.mk_unary(UnUniq, e) _ => self.mk_unary(UnUniq, e)
}; };
} }
token::IDENT(_, _) if self.is_keyword(keywords::Box) => {
self.bump();
let subexpression = self.parse_prefix_expr();
hi = subexpression.span.hi;
// HACK: turn `box [...]` into a boxed-evec
ex = match subexpression.node {
ExprVec(..) |
ExprLit(@codemap::Spanned {
node: lit_str(..),
span: _
}) |
ExprRepeat(..) => ExprVstore(subexpression, ExprVstoreUniq),
_ => self.mk_unary(UnUniq, subexpression)
};
}
_ => return self.parse_dot_or_call_expr() _ => return self.parse_dot_or_call_expr()
} }
return self.mk_expr(lo, hi, ex); return self.mk_expr(lo, hi, ex);

View File

@ -465,15 +465,17 @@ pub mod keywords {
(45, While, "while"); (45, While, "while");
(46, Continue, "continue"); (46, Continue, "continue");
(47, Proc, "proc"); (47, Proc, "proc");
(48, Box, "box");
'reserved: 'reserved:
(48, Alignof, "alignof"); (49, Alignof, "alignof");
(49, Be, "be"); (50, Be, "be");
(50, Offsetof, "offsetof"); (51, Offsetof, "offsetof");
(51, Pure, "pure"); (52, Pure, "pure");
(52, Sizeof, "sizeof"); (53, Sizeof, "sizeof");
(53, Typeof, "typeof"); (54, Typeof, "typeof");
(54, Yield, "yield"); (55, Unsized, "unsized");
(56, Yield, "yield");
} }
} }

View File

@ -0,0 +1,8 @@
/* Any copyright is dedicated to the Public Domain.
* http://creativecommons.org/publicdomain/zero/1.0/ */
fn main() {
let x: ~int = box 3;
println!("{}", *x);
}