libsyntax: Accept static instead of const for globals

This commit is contained in:
Patrick Walton 2013-03-19 14:46:27 -07:00
parent 2e7ec80bcc
commit 049e1f9a1f
3 changed files with 24 additions and 6 deletions

View File

@ -3477,7 +3477,12 @@ pub impl Parser {
fn parse_item_foreign_const(&self, vis: ast::visibility,
+attrs: ~[attribute]) -> @foreign_item {
let lo = self.span.lo;
self.expect_keyword(&~"const");
// XXX: Obsolete; remove after snap.
if !self.eat_keyword(&~"const") {
self.expect_keyword(&~"static");
}
let ident = self.parse_ident();
self.expect(&token::COLON);
let ty = self.parse_ty(false);
@ -3506,7 +3511,7 @@ pub impl Parser {
fn parse_foreign_item(&self, +attrs: ~[attribute]) -> @foreign_item {
let vis = self.parse_visibility();
if self.is_keyword(&~"const") {
if self.is_keyword(&~"const") || self.is_keyword(&~"static") {
self.parse_item_foreign_const(vis, attrs)
} else {
self.parse_item_foreign_fn(attrs)
@ -3864,13 +3869,18 @@ pub impl Parser {
visibility = inherited;
}
if items_allowed && self.eat_keyword(&~"const") {
if items_allowed &&
(self.is_keyword(&~"const") ||
(self.is_keyword(&~"static") &&
!self.token_is_keyword(&~"fn", &self.look_ahead(1)))) {
// CONST ITEM
self.bump();
let (ident, item_, extra_attrs) = self.parse_item_const();
return iovi_item(self.mk_item(lo, self.last_span.hi, ident, item_,
visibility,
maybe_append(attrs, extra_attrs)));
} else if foreign_items_allowed && self.is_keyword(&~"const") {
} else if foreign_items_allowed &&
(self.is_keyword(&~"const") || self.is_keyword(&~"static")) {
// FOREIGN CONST ITEM
let item = self.parse_item_foreign_const(visibility, attrs);
return iovi_foreign_item(item);

View File

@ -452,7 +452,7 @@ pub fn print_foreign_item(s: @ps, item: @ast::foreign_item) {
end(s); // end the outer fn box
}
ast::foreign_item_const(t) => {
head(s, ~"const");
head(s, ~"static");
print_ident(s, item.ident);
word_space(s, ~":");
print_type(s, t);
@ -471,7 +471,7 @@ pub fn print_item(s: @ps, &&item: @ast::item) {
(s.ann.pre)(ann_node);
match /*bad*/ copy item.node {
ast::item_const(ty, expr) => {
head(s, visibility_qualified(item.vis, ~"const"));
head(s, visibility_qualified(item.vis, ~"static"));
print_ident(s, item.ident);
word_space(s, ~":");
print_type(s, ty);

View File

@ -0,0 +1,8 @@
use core::io::println;
static FOO: int = 3;
fn main() {
println(fmt!("%d", FOO));
}