aboutsummaryrefslogtreecommitdiff
path: root/src/comp/front
diff options
context:
space:
mode:
authorGraydon Hoare <[email protected]>2010-12-09 14:37:50 -0800
committerGraydon Hoare <[email protected]>2010-12-09 14:37:50 -0800
commit876282791e36c482676aeeaee722f5038126e175 (patch)
tree6455132ac599209d9263440a5fcb7b8fe30b252b /src/comp/front
parentActually un-XFAIL drop-on-ret.rs. (diff)
downloadrust-876282791e36c482676aeeaee722f5038126e175.tar.xz
rust-876282791e36c482676aeeaee722f5038126e175.zip
First sketch of support for const items, not including most of trans.
Diffstat (limited to 'src/comp/front')
-rw-r--r--src/comp/front/ast.rs1
-rw-r--r--src/comp/front/parser.rs22
2 files changed, 23 insertions, 0 deletions
diff --git a/src/comp/front/ast.rs b/src/comp/front/ast.rs
index a37fd191..553a49f6 100644
--- a/src/comp/front/ast.rs
+++ b/src/comp/front/ast.rs
@@ -204,6 +204,7 @@ type variant = rec(str name, vec[variant_arg] args, def_id id, ann ann);
type item = spanned[item_];
tag item_ {
+ item_const(ident, @ty, @expr, def_id, ann);
item_fn(ident, _fn, vec[ty_param], def_id, ann);
item_mod(ident, _mod, def_id);
item_ty(ident, @ty, vec[ty_param], def_id, ann);
diff --git a/src/comp/front/parser.rs b/src/comp/front/parser.rs
index 093d4b7c..8cf088e4 100644
--- a/src/comp/front/parser.rs
+++ b/src/comp/front/parser.rs
@@ -1229,6 +1229,9 @@ impure fn parse_mod_items(parser p, token.token term) -> ast._mod {
// Index the item.
alt (item.node) {
+ case (ast.item_const(?id, _, _, _, _)) {
+ index.insert(id, ast.mie_item(u));
+ }
case (ast.item_fn(?id, _, _, _, _)) {
index.insert(id, ast.mie_item(u));
}
@@ -1254,6 +1257,19 @@ impure fn parse_mod_items(parser p, token.token term) -> ast._mod {
ret rec(items=items, index=index);
}
+impure fn parse_item_const(parser p) -> @ast.item {
+ auto lo = p.get_span();
+ expect(p, token.CONST);
+ auto ty = parse_ty(p);
+ auto id = parse_ident(p);
+ expect(p, token.EQ);
+ auto e = parse_expr(p);
+ auto hi = p.get_span();
+ expect(p, token.SEMI);
+ auto item = ast.item_const(id, ty, e, p.next_def_id(), ast.ann_none);
+ ret @spanned(lo, hi, item);
+}
+
impure fn parse_item_mod(parser p) -> @ast.item {
auto lo = p.get_span();
expect(p, token.MOD);
@@ -1369,6 +1385,12 @@ impure fn parse_item(parser p) -> @ast.item {
let ast.layer lyr = parse_layer(p);
alt (p.peek()) {
+ case (token.CONST) {
+ check (eff == ast.eff_pure);
+ check (lyr == ast.layer_value);
+ ret parse_item_const(p);
+ }
+
case (token.FN) {
check (lyr == ast.layer_value);
ret parse_item_fn(p, eff);