aboutsummaryrefslogtreecommitdiff
path: root/src/comp
diff options
context:
space:
mode:
authorGraydon Hoare <[email protected]>2011-03-04 14:15:19 -0800
committerGraydon Hoare <[email protected]>2011-03-04 14:19:48 -0800
commit596face2745ccc11a959a530807ea3e36e9d1354 (patch)
tree3f448581a2d193a759e7c07b1245dab6fbf655f7 /src/comp
parentBuild empty wrappers. This lets us compile hello world, but so far it (diff)
downloadrust-596face2745ccc11a959a530807ea3e36e9d1354.tar.xz
rust-596face2745ccc11a959a530807ea3e36e9d1354.zip
Parse (and generally ignore) constraints and constrained types.
Diffstat (limited to 'src/comp')
-rw-r--r--src/comp/front/ast.rs9
-rw-r--r--src/comp/front/parser.rs68
2 files changed, 76 insertions, 1 deletions
diff --git a/src/comp/front/ast.rs b/src/comp/front/ast.rs
index e9dee7ec..a8bf4b00 100644
--- a/src/comp/front/ast.rs
+++ b/src/comp/front/ast.rs
@@ -231,8 +231,17 @@ tag ty_ {
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,
diff --git a/src/comp/front/parser.rs b/src/comp/front/parser.rs
index f80c3bd5..934764e6 100644
--- a/src/comp/front/parser.rs
+++ b/src/comp/front/parser.rs
@@ -199,6 +199,10 @@ impure fn parse_ty_fn(ast.proto proto, parser p,
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 @@ impure fn parse_ty_field(parser p) -> ast.ty_field {
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 @@ impure fn parse_ty(parser p) -> @ast.ty {
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 @@ impure fn parse_fn_decl(parser p, ast.effect eff) -> ast.fn_decl {
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);