diff options
| author | Patrick Walton <[email protected]> | 2010-11-24 17:15:54 -0800 |
|---|---|---|
| committer | Patrick Walton <[email protected]> | 2010-11-24 17:17:42 -0800 |
| commit | 98e8c2ef21f6aab3dd3d4d328a1c8baf1f074ee4 (patch) | |
| tree | d787591f3025c242b3dade19d8a1b2297bd243f0 /src/comp/front | |
| parent | Sketch out type-directed structural drop and copy, including vector types. (diff) | |
| download | rust-98e8c2ef21f6aab3dd3d4d328a1c8baf1f074ee4.tar.xz rust-98e8c2ef21f6aab3dd3d4d328a1c8baf1f074ee4.zip | |
rustc: Parse type-parametric tags
Diffstat (limited to 'src/comp/front')
| -rw-r--r-- | src/comp/front/ast.rs | 2 | ||||
| -rw-r--r-- | src/comp/front/parser.rs | 21 |
2 files changed, 14 insertions, 9 deletions
diff --git a/src/comp/front/ast.rs b/src/comp/front/ast.rs index 3bc2fe16..800d9794 100644 --- a/src/comp/front/ast.rs +++ b/src/comp/front/ast.rs @@ -171,7 +171,7 @@ tag item_ { 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); + item_tag(ident, vec[variant], vec[ty_param], def_id); } diff --git a/src/comp/front/parser.rs b/src/comp/front/parser.rs index 66529c69..3c640f4a 100644 --- a/src/comp/front/parser.rs +++ b/src/comp/front/parser.rs @@ -1039,17 +1039,21 @@ impure fn parse_block(parser p) -> ast.block { ret spanned(stmts.span, stmts.span, b); } -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); - +impure fn parse_ty_params(parser p) -> vec[ast.ty_param] { let vec[ast.ty_param] ty_params = vec(); if (p.peek() == token.LBRACKET) { - auto pg = parse_ident; // FIXME: pass as lval directly + auto f = parse_ident; // FIXME: pass as lval directly ty_params = parse_seq[ast.ty_param](token.LBRACKET, token.RBRACKET, - some(token.COMMA), pg, p).node; + some(token.COMMA), f, p).node; } + ret ty_params; +} + +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); + auto ty_params = parse_ty_params(p); auto pf = parse_arg; let util.common.spanned[vec[ast.arg]] inputs = @@ -1120,6 +1124,7 @@ impure fn parse_item_tag(parser p) -> tup(ast.ident, @ast.item) { auto lo = p.get_span(); expect(p, token.TAG); auto id = parse_ident(p); + auto ty_params = parse_ty_params(p); let vec[ast.variant] variants = vec(); expect(p, token.LBRACE); @@ -1158,7 +1163,7 @@ impure fn parse_item_tag(parser p) -> tup(ast.ident, @ast.item) { p.bump(); auto hi = p.get_span(); - auto item = ast.item_tag(id, variants, p.next_def_id()); + auto item = ast.item_tag(id, variants, ty_params, p.next_def_id()); ret tup(id, @spanned(lo, hi, item)); } |