aboutsummaryrefslogtreecommitdiff
path: root/src/comp/front/parser.rs
diff options
context:
space:
mode:
authorGraydon Hoare <[email protected]>2011-02-14 15:52:38 -0800
committerGraydon Hoare <[email protected]>2011-02-14 15:52:38 -0800
commit59bce06a967b3806c3d874b8956857f0f01287e1 (patch)
tree4f81bc5cf6e0fa94ba9c08000e98264904a3dc53 /src/comp/front/parser.rs
parentTeach typeck about generic tags. (diff)
downloadrust-59bce06a967b3806c3d874b8956857f0f01287e1.tar.xz
rust-59bce06a967b3806c3d874b8956857f0f01287e1.zip
Expand expr_rec to take its optional trailing 'with' parameter.
Diffstat (limited to 'src/comp/front/parser.rs')
-rw-r--r--src/comp/front/parser.rs41
1 files changed, 32 insertions, 9 deletions
diff --git a/src/comp/front/parser.rs b/src/comp/front/parser.rs
index 87bbe57f..2f037dfb 100644
--- a/src/comp/front/parser.rs
+++ b/src/comp/front/parser.rs
@@ -529,14 +529,37 @@ impure fn parse_bottom_expr(parser p) -> @ast.expr {
case (token.REC) {
p.bump();
- 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);
+ expect(p, token.LPAREN);
+ auto fields = vec(parse_field(p));
+
+ auto more = true;
+ auto base = none[@ast.expr];
+ while (more) {
+ alt (p.peek()) {
+ case (token.RPAREN) {
+ hi = p.get_span();
+ p.bump();
+ more = false;
+ }
+ case (token.WITH) {
+ p.bump();
+ base = some[@ast.expr](parse_expr(p));
+ hi = p.get_span();
+ expect(p, token.RPAREN);
+ more = false;
+ }
+ case (token.COMMA) {
+ p.bump();
+ fields += parse_field(p);
+ }
+ case (?t) {
+ unexpected(p, t);
+ }
+ }
+
+ }
+
+ ex = ast.expr_rec(fields, base, ast.ann_none);
}
case (token.BIND) {
@@ -1370,7 +1393,7 @@ fn stmt_ends_with_semi(@ast.stmt stmt) -> bool {
alt (e.node) {
case (ast.expr_vec(_,_)) { ret true; }
case (ast.expr_tup(_,_)) { ret true; }
- case (ast.expr_rec(_,_)) { ret true; }
+ case (ast.expr_rec(_,_,_)) { ret true; }
case (ast.expr_call(_,_,_)) { ret true; }
case (ast.expr_binary(_,_,_,_)) { ret true; }
case (ast.expr_unary(_,_,_)) { ret true; }