Tidy up structural types for rec, tup AST and typeck nodes.
This commit is contained in:
parent
567a45cc70
commit
45043374ff
5 changed files with 117 additions and 117 deletions
|
|
@ -109,11 +109,14 @@ tag decl_ {
|
|||
|
||||
type arm = rec(@pat pat, block block);
|
||||
|
||||
type elt = rec(mutability mut, @expr expr);
|
||||
type field = rec(mutability mut, ident ident, @expr expr);
|
||||
|
||||
type expr = spanned[expr_];
|
||||
tag expr_ {
|
||||
expr_vec(vec[@expr], ann);
|
||||
expr_tup(vec[tup(mutability, @expr)], ann);
|
||||
expr_rec(vec[tup(ident,@expr)], ann);
|
||||
expr_tup(vec[elt], ann);
|
||||
expr_rec(vec[field], ann);
|
||||
expr_call(@expr, vec[@expr], ann);
|
||||
expr_binary(binop, @expr, @expr, ann);
|
||||
expr_unary(unop, @expr, ann);
|
||||
|
|
@ -143,6 +146,7 @@ tag lit_ {
|
|||
|
||||
// NB: If you change this, you'll probably want to change the corresponding
|
||||
// type structure in middle/typeck.rs as well.
|
||||
type ty_field = rec(ident ident, @ty ty);
|
||||
type ty = spanned[ty_];
|
||||
tag ty_ {
|
||||
ty_nil;
|
||||
|
|
@ -155,7 +159,7 @@ tag ty_ {
|
|||
ty_box(@ty);
|
||||
ty_vec(@ty);
|
||||
ty_tup(vec[@ty]);
|
||||
ty_rec(vec[tup(ident,@ty)]);
|
||||
ty_rec(vec[ty_field]);
|
||||
ty_fn(vec[rec(mode mode, @ty ty)], @ty); // TODO: effect
|
||||
ty_path(path, option.t[def]);
|
||||
ty_mutable(@ty);
|
||||
|
|
|
|||
|
|
@ -189,17 +189,17 @@ impure fn parse_ty(parser p) -> @ast.ty {
|
|||
|
||||
case (token.REC) {
|
||||
p.bump();
|
||||
impure fn parse_field(parser p) -> tup(ast.ident, @ast.ty) {
|
||||
impure fn parse_field(parser p) -> ast.ty_field {
|
||||
auto ty = parse_ty(p);
|
||||
auto id = parse_ident(p);
|
||||
ret tup(id,ty);
|
||||
ret rec(ident=id, ty=ty);
|
||||
}
|
||||
auto f = parse_field; // FIXME: trans_const_lval bug
|
||||
auto elems =
|
||||
parse_seq[tup(ast.ident, @ast.ty)](token.LPAREN,
|
||||
token.RPAREN,
|
||||
some(token.COMMA),
|
||||
f, p);
|
||||
parse_seq[ast.ty_field](token.LPAREN,
|
||||
token.RPAREN,
|
||||
some(token.COMMA),
|
||||
f, p);
|
||||
hi = p.get_span();
|
||||
t = ast.ty_rec(elems.node);
|
||||
}
|
||||
|
|
@ -352,17 +352,12 @@ impure fn parse_name(parser p, ast.ident id) -> ast.name {
|
|||
ret spanned(lo, tys.span, rec(ident=id, types=tys.node));
|
||||
}
|
||||
|
||||
impure fn parse_possibly_mutable_expr(parser p)
|
||||
-> tup(ast.mutability, @ast.expr) {
|
||||
auto mut;
|
||||
impure fn parse_mutabliity(parser p) -> ast.mutability {
|
||||
if (p.peek() == token.MUTABLE) {
|
||||
p.bump();
|
||||
mut = ast.mut;
|
||||
} else {
|
||||
mut = ast.imm;
|
||||
ret ast.mut;
|
||||
}
|
||||
|
||||
ret tup(mut, parse_expr(p));
|
||||
ret ast.imm;
|
||||
}
|
||||
|
||||
impure fn parse_bottom_expr(parser p) -> @ast.expr {
|
||||
|
|
@ -415,13 +410,17 @@ impure fn parse_bottom_expr(parser p) -> @ast.expr {
|
|||
|
||||
case (token.TUP) {
|
||||
p.bump();
|
||||
auto pf = parse_possibly_mutable_expr;
|
||||
impure fn parse_elt(parser p) -> ast.elt {
|
||||
auto m = parse_mutabliity(p);
|
||||
auto e = parse_expr(p);
|
||||
ret rec(mut=m, expr=e);
|
||||
}
|
||||
auto pf = parse_elt;
|
||||
auto es =
|
||||
parse_seq[tup(ast.mutability, @ast.expr)]
|
||||
(token.LPAREN,
|
||||
token.RPAREN,
|
||||
some(token.COMMA),
|
||||
pf, p);
|
||||
parse_seq[ast.elt](token.LPAREN,
|
||||
token.RPAREN,
|
||||
some(token.COMMA),
|
||||
pf, p);
|
||||
hi = es.span;
|
||||
ex = ast.expr_tup(es.node, ast.ann_none);
|
||||
}
|
||||
|
|
@ -439,21 +438,21 @@ impure fn parse_bottom_expr(parser p) -> @ast.expr {
|
|||
|
||||
case (token.REC) {
|
||||
p.bump();
|
||||
impure fn parse_entry(parser p) ->
|
||||
tup(ast.ident, @ast.expr) {
|
||||
impure fn parse_field(parser p) -> ast.field {
|
||||
auto m = parse_mutabliity(p);
|
||||
auto i = parse_ident(p);
|
||||
expect(p, token.EQ);
|
||||
auto e = parse_expr(p);
|
||||
ret tup(i, e);
|
||||
ret rec(mut=m, ident=i, expr=e);
|
||||
}
|
||||
auto pf = parse_entry;
|
||||
auto es =
|
||||
parse_seq[tup(ast.ident, @ast.expr)](token.LPAREN,
|
||||
token.RPAREN,
|
||||
some(token.COMMA),
|
||||
pf, p);
|
||||
hi = es.span;
|
||||
ex = ast.expr_rec(es.node, ast.ann_none);
|
||||
auto pf = parse_field;
|
||||
auto fs =
|
||||
parse_seq[ast.field](token.LPAREN,
|
||||
token.RPAREN,
|
||||
some(token.COMMA),
|
||||
pf, p);
|
||||
hi = fs.span;
|
||||
ex = ast.expr_rec(fs.node, ast.ann_none);
|
||||
}
|
||||
|
||||
case (_) {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue