diff options
| author | Lindsey Kuper <[email protected]> | 2011-04-07 13:49:27 -0700 |
|---|---|---|
| committer | Graydon Hoare <[email protected]> | 2011-04-07 14:26:34 -0700 |
| commit | 1092bbfff0cf932ef14e5b92cd54133571ca4727 (patch) | |
| tree | a771667972fb8f75d393372032d5f05c03b3b68d /src/comp/front | |
| parent | Add a very basic crate-dump utility (diff) | |
| download | rust-1092bbfff0cf932ef14e5b92cd54133571ca4727.tar.xz rust-1092bbfff0cf932ef14e5b92cd54133571ca4727.zip | |
Support for self-calls that take arguments.
Nicer parsing of self-calls (expr_self_method nodes inside expr_call
nodes, rather than a separate expr_call_self) makes typechecking
tractable. We can now write self-calls that take arguments and return
values (see: test/run-pass/obj-self-*.rs).
Diffstat (limited to 'src/comp/front')
| -rw-r--r-- | src/comp/front/ast.rs | 2 | ||||
| -rw-r--r-- | src/comp/front/parser.rs | 13 |
2 files changed, 11 insertions, 4 deletions
diff --git a/src/comp/front/ast.rs b/src/comp/front/ast.rs index cf4145a5..4f7a2538 100644 --- a/src/comp/front/ast.rs +++ b/src/comp/front/ast.rs @@ -258,7 +258,7 @@ tag expr_ { expr_tup(vec[elt], ann); expr_rec(vec[field], option.t[@expr], ann); expr_call(@expr, vec[@expr], ann); - expr_call_self(ident, vec[@expr], ann); + expr_self_method(ident, ann); expr_bind(@expr, vec[option.t[@expr]], ann); expr_spawn(spawn_dom, option.t[str], @expr, vec[@expr], ann); expr_binary(binop, @expr, @expr, ann); diff --git a/src/comp/front/parser.rs b/src/comp/front/parser.rs index 7d1323cb..5ed7dd27 100644 --- a/src/comp/front/parser.rs +++ b/src/comp/front/parser.rs @@ -893,14 +893,14 @@ impure fn parse_bottom_expr(parser p) -> @ast.expr { p.bump(); expect(p, token.DOT); // The rest is a call expression. - auto e = parse_ident(p); + let @ast.expr f = parse_self_method(p); auto pf = parse_expr; auto es = parse_seq[@ast.expr](token.LPAREN, token.RPAREN, some(token.COMMA), pf, p); hi = es.span; - ex = ast.expr_call_self(e, es.node, ast.ann_none); + ex = ast.expr_call(f, es.node, ast.ann_none); } case (_) { @@ -966,6 +966,13 @@ impure fn extend_expr_by_ident(parser p, span lo, span hi, ret @spanned(lo, hi, e_); } +impure fn parse_self_method(parser p) -> @ast.expr { + auto lo = p.get_span(); + let ast.ident f_name = parse_ident(p); + auto hi = p.get_span(); + ret @spanned(lo, hi, ast.expr_self_method(f_name, ast.ann_none)); +} + impure fn parse_dot_or_call_expr(parser p) -> @ast.expr { auto lo = p.get_span(); auto e = parse_bottom_expr(p); @@ -1634,7 +1641,7 @@ fn stmt_ends_with_semi(@ast.stmt stmt) -> bool { case (ast.expr_tup(_,_)) { ret true; } case (ast.expr_rec(_,_,_)) { ret true; } case (ast.expr_call(_,_,_)) { ret true; } - case (ast.expr_call_self(_,_,_)){ ret true; } + case (ast.expr_self_method(_,_)){ ret false; } case (ast.expr_binary(_,_,_,_)) { ret true; } case (ast.expr_unary(_,_,_)) { ret true; } case (ast.expr_lit(_,_)) { ret true; } |