diff options
| author | Patrick Walton <pcwalton@mimiga.net> | 2010-11-24 16:52:49 -0800 |
|---|---|---|
| committer | Patrick Walton <pcwalton@mimiga.net> | 2010-11-24 16:52:49 -0800 |
| commit | c1916adc7e16bd7ecd3ca8dbbe985ec75d0c825a (patch) | |
| tree | d69d2e25a0a016c8c798d9a416b628d9f907a2d1 /src/comp/front | |
| parent | 80d099c59ab1a9ce4ef24087c2c17c42b686e66c (diff) | |
| download | rust-c1916adc7e16bd7ecd3ca8dbbe985ec75d0c825a.tar.gz rust-c1916adc7e16bd7ecd3ca8dbbe985ec75d0c825a.zip | |
rustc: Parse type-parametric functions
Diffstat (limited to 'src/comp/front')
| -rw-r--r-- | src/comp/front/ast.rs | 3 | ||||
| -rw-r--r-- | src/comp/front/parser.rs | 12 |
2 files changed, 12 insertions, 3 deletions
diff --git a/src/comp/front/ast.rs b/src/comp/front/ast.rs index cc0f296127e..3bc2fe167ec 100644 --- a/src/comp/front/ast.rs +++ b/src/comp/front/ast.rs @@ -7,6 +7,7 @@ import util.common.spanned; import util.common.ty_mach; type ident = str; +type ty_param = ident; type name_ = rec(ident ident, vec[@ty] types); type name = spanned[name_]; @@ -167,7 +168,7 @@ type variant = rec(str name, vec[@ty] args); type item = spanned[item_]; tag item_ { - item_fn(ident, _fn, def_id, ann); + item_fn(ident, _fn, vec[ty_param], def_id, ann); item_mod(ident, _mod, def_id); item_ty(ident, @ty, def_id, ann); item_tag(ident, vec[variant], def_id); diff --git a/src/comp/front/parser.rs b/src/comp/front/parser.rs index 598b04af82e..66529c69c15 100644 --- a/src/comp/front/parser.rs +++ b/src/comp/front/parser.rs @@ -1020,7 +1020,7 @@ impure fn parse_block(parser p) -> ast.block { } case (ast.decl_item(?it)) { alt (it.node) { - case (ast.item_fn(?i, _, _, _)) { + case (ast.item_fn(?i, _, _, _, _)) { index.insert(i, u-1u); } case (ast.item_mod(?i, _, _)) { @@ -1043,6 +1043,14 @@ impure fn parse_item_fn(parser p) -> tup(ast.ident, @ast.item) { auto lo = p.get_span(); expect(p, token.FN); auto id = parse_ident(p); + + let vec[ast.ty_param] ty_params = vec(); + if (p.peek() == token.LBRACKET) { + auto pg = parse_ident; // FIXME: pass as lval directly + ty_params = parse_seq[ast.ty_param](token.LBRACKET, token.RBRACKET, + some(token.COMMA), pg, p).node; + } + auto pf = parse_arg; let util.common.spanned[vec[ast.arg]] inputs = // FIXME: passing parse_arg as an lval doesn't work at the @@ -1067,7 +1075,7 @@ impure fn parse_item_fn(parser p) -> tup(ast.ident, @ast.item) { output = output, body = body); - auto item = ast.item_fn(id, f, p.next_def_id(), ast.ann_none); + auto item = ast.item_fn(id, f, ty_params, p.next_def_id(), ast.ann_none); ret tup(id, @spanned(lo, body.span, item)); } |
