aboutsummaryrefslogtreecommitdiff
path: root/src/comp/front/parser.rs
diff options
context:
space:
mode:
authorGraydon Hoare <[email protected]>2010-12-14 17:42:12 -0800
committerGraydon Hoare <[email protected]>2010-12-14 17:42:12 -0800
commitb1e0c60d6dee3832358be1b4b8303fe6ade6be4c (patch)
tree0a28b1b0489af217b9ad5e33eb1fc3025658972a /src/comp/front/parser.rs
parentTeach resolve about obj items. (diff)
downloadrust-b1e0c60d6dee3832358be1b4b8303fe6ade6be4c.tar.xz
rust-b1e0c60d6dee3832358be1b4b8303fe6ade6be4c.zip
Add ty_obj to ast and parser.
Diffstat (limited to 'src/comp/front/parser.rs')
-rw-r--r--src/comp/front/parser.rs43
1 files changed, 36 insertions, 7 deletions
diff --git a/src/comp/front/parser.rs b/src/comp/front/parser.rs
index 84a5c305..3eacb5f9 100644
--- a/src/comp/front/parser.rs
+++ b/src/comp/front/parser.rs
@@ -102,7 +102,7 @@ impure fn parse_ident(parser p) -> ast.ident {
}
}
-impure fn parse_ty_fn(parser p) -> ast.ty_ {
+impure fn parse_ty_fn(parser p, ast.span lo) -> ast.ty_ {
impure fn parse_fn_input_ty(parser p) -> rec(ast.mode mode, @ast.ty ty) {
auto mode;
if (p.peek() == token.BINOP(token.AND)) {
@@ -124,8 +124,6 @@ impure fn parse_ty_fn(parser p) -> ast.ty_ {
auto lo = p.get_span();
- expect(p, token.FN);
-
auto f = parse_fn_input_ty; // FIXME: trans_const_lval bug
auto inputs = parse_seq[rec(ast.mode mode, @ast.ty ty)](token.LPAREN,
token.RPAREN, some(token.COMMA), f, p);
@@ -141,6 +139,31 @@ impure fn parse_ty_fn(parser p) -> ast.ty_ {
ret ast.ty_fn(inputs.node, output);
}
+impure fn parse_ty_obj(parser p, &mutable ast.span hi) -> ast.ty_ {
+ expect(p, token.OBJ);
+ impure fn parse_method_sig(parser p) -> ast.ty_method {
+ auto flo = p.get_span();
+ expect(p, token.FN);
+ auto ident = parse_ident(p);
+ auto f = parse_ty_fn(p, flo);
+ expect(p, token.SEMI);
+ alt (f) {
+ case (ast.ty_fn(?inputs, ?output)) {
+ ret rec(ident=ident, inputs=inputs, output=output);
+ }
+ }
+ fail;
+ }
+ auto f = parse_method_sig;
+ auto meths =
+ parse_seq[ast.ty_method](token.LBRACE,
+ token.RBRACE,
+ none[token.token],
+ f, p);
+ hi = meths.span;
+ ret ast.ty_obj(meths.node);
+}
+
impure fn parse_ty_field(parser p) -> ast.ty_field {
auto ty = parse_ty(p);
auto id = parse_ident(p);
@@ -196,7 +219,7 @@ impure fn parse_ty(parser p) -> @ast.ty {
auto elems = parse_seq[@ast.ty] (token.LPAREN,
token.RPAREN,
some(token.COMMA), f, p);
- hi = p.get_span();
+ hi = elems.span;
t = ast.ty_tup(elems.node);
}
@@ -208,19 +231,21 @@ impure fn parse_ty(parser p) -> @ast.ty {
token.RPAREN,
some(token.COMMA),
f, p);
- hi = p.get_span();
+ hi = elems.span;
t = ast.ty_rec(elems.node);
}
case (token.MUTABLE) {
p.bump();
auto t0 = parse_ty(p);
- hi = p.get_span();
+ hi = t0.span;
t = ast.ty_mutable(t0);
}
case (token.FN) {
- t = parse_ty_fn(p);
+ auto flo = p.get_span();
+ p.bump();
+ t = parse_ty_fn(p, flo);
alt (t) {
case (ast.ty_fn(_, ?out)) {
hi = out.span;
@@ -228,6 +253,10 @@ impure fn parse_ty(parser p) -> @ast.ty {
}
}
+ case (token.OBJ) {
+ t = parse_ty_obj(p, hi);
+ }
+
case (token.IDENT(_)) {
let ast.path pth = vec();
let bool more = true;