提交 596face2 编写于 作者: G Graydon Hoare

Parse (and generally ignore) constraints and constrained types.

上级 95c0cefd
......@@ -231,8 +231,17 @@
ty_path(path, option.t[def]);
ty_mutable(@ty);
ty_type;
ty_constr(@ty, vec[@constr]);
}
tag constr_arg_ {
carg_base;
carg_ident(ident);
}
type constr_arg = spanned[constr_arg_];
type constr_ = rec(path path, vec[@constr_arg] args);
type constr = spanned[constr_];
type arg = rec(mode mode, @ty ty, ident ident, def_id id);
type fn_decl = rec(effect effect,
vec[arg] inputs,
......
......@@ -199,6 +199,10 @@ fn spanned[T](&span lo, &span hi, &T node) -> ast.spanned[T] {
auto inputs = parse_seq[rec(ast.mode mode, @ast.ty ty)](token.LPAREN,
token.RPAREN, some(token.COMMA), f, p);
// FIXME: dropping constrs on the floor at the moment.
// pick them up when they're used by typestate pass.
parse_constrs(p);
let @ast.ty output;
if (p.peek() == token.RARROW) {
p.bump();
......@@ -254,6 +258,62 @@ fn spanned[T](&span lo, &span hi, &T node) -> ast.spanned[T] {
ret rec(ident=id, ty=ty);
}
impure fn parse_constr_arg(parser p) -> @ast.constr_arg {
auto lo = p.get_span();
auto carg = ast.carg_base;
if (p.peek() == token.BINOP(token.STAR)) {
p.bump();
} else {
carg = ast.carg_ident(parse_ident(p));
}
ret @spanned(lo, lo, carg);
}
impure fn parse_ty_constr(parser p) -> @ast.constr {
auto lo = p.get_span();
auto path = parse_path(p, GREEDY);
auto pf = parse_constr_arg;
auto args = parse_seq[@ast.constr_arg](token.LPAREN,
token.RPAREN,
some(token.COMMA), pf, p);
auto hi = args.span;
ret @spanned(lo, hi, rec(path=path, args=args.node));
}
impure fn parse_constrs(parser p) -> common.spanned[vec[@ast.constr]] {
auto lo = p.get_span();
auto hi = lo;
let vec[@ast.constr] constrs = vec();
if (p.peek() == token.COLON) {
p.bump();
let bool more = true;
while (more) {
alt (p.peek()) {
case (token.IDENT(_)) {
auto constr = parse_ty_constr(p);
hi = constr.span;
append[@ast.constr](constrs, constr);
if (p.peek() == token.COMMA) {
p.bump();
more = false;
}
}
case (_) { more = false; }
}
}
}
ret spanned(lo, hi, constrs);
}
impure fn parse_ty_constrs(@ast.ty t, parser p) -> @ast.ty {
if (p.peek() == token.COLON) {
auto constrs = parse_constrs(p);
ret @spanned(t.span, constrs.span,
ast.ty_constr(t, constrs.node));
}
ret t;
}
impure fn parse_ty(parser p) -> @ast.ty {
auto lo = p.get_span();
auto hi = lo;
......@@ -368,7 +428,8 @@ fn spanned[T](&span lo, &span hi, &T node) -> ast.spanned[T] {
fail;
}
}
ret @spanned(lo, hi, t);
ret parse_ty_constrs(@spanned(lo, hi, t), p);
}
impure fn parse_arg(parser p) -> ast.arg {
......@@ -1676,6 +1737,11 @@ fn stmt_ends_with_semi(@ast.stmt stmt) -> bool {
pf, p);
let @ast.ty output;
// FIXME: dropping constrs on the floor at the moment.
// pick them up when they're used by typestate pass.
parse_constrs(p);
if (p.peek() == token.RARROW) {
p.bump();
output = parse_ty(p);
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册