Skip to content

Commit efda5dd

Browse files
committed
---
yaml --- r: 1239 b: refs/heads/master c: f3c3fc0 h: refs/heads/master i: 1237: e8d81a4 1235: e434b79 1231: acdc02b v: v3
1 parent 167acfe commit efda5dd

File tree

8 files changed

+171
-99
lines changed

8 files changed

+171
-99
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
---
2-
refs/heads/master: 3722326cd7dddf367edee4adf44fc3da89955428
2+
refs/heads/master: f3c3fc03537d9aca36b0ce5956ab8d5b760784b4

trunk/src/comp/front/ast.rs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,8 @@ import util.common.ty_mach;
88

99
type ident = str;
1010

11-
type name_ = rec(ident ident, vec[@ty] types);
12-
type name = spanned[name_];
13-
type path = vec[name];
11+
type path_ = rec(vec[ident] idents, vec[@ty] types);
12+
type path = spanned[path_];
1413

1514
type crate_num = int;
1615
type def_num = int;
@@ -158,7 +157,7 @@ tag expr_ {
158157
expr_assign_op(binop, @expr /* TODO: @expr|is_lval */, @expr, ann);
159158
expr_field(@expr, ident, ann);
160159
expr_index(@expr, @expr, ann);
161-
expr_name(name, option.t[def], ann);
160+
expr_path(path, option.t[def], ann);
162161
}
163162

164163
type lit = spanned[lit_];

trunk/src/comp/front/parser.rs

Lines changed: 68 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -283,26 +283,7 @@ impure fn parse_ty(parser p) -> @ast.ty {
283283
}
284284

285285
case (token.IDENT(_)) {
286-
let ast.path pth = vec();
287-
let bool more = true;
288-
while (more) {
289-
alt (p.peek()) {
290-
case (token.IDENT(?i)) {
291-
auto n = parse_name(p, i);
292-
hi = n.span;
293-
pth += n;
294-
if (p.peek() == token.DOT) {
295-
p.bump();
296-
} else {
297-
more = false;
298-
}
299-
}
300-
case (_) {
301-
more = false;
302-
}
303-
}
304-
}
305-
t = ast.ty_path(pth, none[ast.def]);
286+
t = ast.ty_path(parse_path(p, true), none[ast.def]);
306287
}
307288

308289
case (_) {
@@ -391,14 +372,46 @@ impure fn parse_lit(parser p) -> option.t[ast.lit] {
391372
ret some(spanned(lo, lo, lit));
392373
}
393374

394-
impure fn parse_name(parser p, ast.ident id) -> ast.name {
375+
fn is_ident(token.token t) -> bool {
376+
alt (t) {
377+
case (token.IDENT(_)) { ret true; }
378+
case (_) {}
379+
}
380+
ret false;
381+
}
382+
383+
impure fn parse_path(parser p, bool greedy) -> ast.path {
395384

396385
auto lo = p.get_span();
386+
auto hi = lo;
397387

398-
p.bump();
388+
let vec[ast.ident] ids = vec();
389+
let bool more = true;
390+
while (more) {
391+
alt (p.peek()) {
392+
case (token.IDENT(?i)) {
393+
hi = p.get_span();
394+
ids += i;
395+
p.bump();
396+
if (p.peek() == token.DOT) {
397+
if (greedy) {
398+
p.bump();
399+
check (is_ident(p.peek()));
400+
} else {
401+
more = false;
402+
}
403+
} else {
404+
more = false;
405+
}
406+
}
407+
case (_) {
408+
more = false;
409+
}
410+
}
411+
}
399412

400413
let vec[@ast.ty] v = vec();
401-
let util.common.spanned[vec[@ast.ty]] tys = rec(node=v, span=lo);
414+
let util.common.spanned[vec[@ast.ty]] tys = rec(node=v, span=hi);
402415

403416
alt (p.peek()) {
404417
case (token.LBRACKET) {
@@ -411,7 +424,7 @@ impure fn parse_name(parser p, ast.ident id) -> ast.name {
411424
case (_) {
412425
}
413426
}
414-
ret spanned(lo, tys.span, rec(ident=id, types=tys.node));
427+
ret spanned(lo, tys.span, rec(idents=ids, types=tys.node));
415428
}
416429

417430
impure fn parse_mutabliity(parser p) -> ast.mutability {
@@ -442,10 +455,10 @@ impure fn parse_bottom_expr(parser p) -> @ast.expr {
442455

443456
alt (p.peek()) {
444457

445-
case (token.IDENT(?i)) {
446-
auto n = parse_name(p, i);
447-
hi = n.span;
448-
ex = ast.expr_name(n, none[ast.def], ast.ann_none);
458+
case (token.IDENT(_)) {
459+
auto pth = parse_path(p, false);
460+
hi = pth.span;
461+
ex = ast.expr_path(pth, none[ast.def], ast.ann_none);
449462
}
450463

451464
case (token.LPAREN) {
@@ -546,7 +559,29 @@ impure fn parse_bottom_expr(parser p) -> @ast.expr {
546559
ret @spanned(lo, hi, ex);
547560
}
548561

549-
impure fn parse_path_expr(parser p) -> @ast.expr {
562+
fn append_dot_ident_to_expr(span lo, span hi,
563+
@ast.expr e, ast.ident i) -> @ast.expr {
564+
auto e_ = e.node;
565+
alt (e.node) {
566+
case (ast.expr_path(?pth, ?def, ?ann)) {
567+
if (_vec.len[@ast.ty](pth.node.types) == 0u) {
568+
auto idents_ = pth.node.idents;
569+
idents_ += i;
570+
auto pth_ = rec(node=rec(idents=idents_ with pth.node)
571+
with pth);
572+
e_ = ast.expr_path(pth_, def, ann);
573+
} else {
574+
e_ = ast.expr_field(e, i, ann);
575+
}
576+
}
577+
case (_) {
578+
e_ = ast.expr_field(e, i, ast.ann_none);
579+
}
580+
}
581+
ret @spanned(lo, hi, e_);
582+
}
583+
584+
impure fn parse_dot_or_call_expr(parser p) -> @ast.expr {
550585
auto lo = p.get_span();
551586
auto e = parse_bottom_expr(p);
552587
auto hi = e.span;
@@ -576,8 +611,7 @@ impure fn parse_path_expr(parser p) -> @ast.expr {
576611
case (token.IDENT(?i)) {
577612
hi = p.get_span();
578613
p.bump();
579-
auto e_ = ast.expr_field(e, i, ast.ann_none);
580-
e = @spanned(lo, hi, e_);
614+
e = append_dot_ident_to_expr(lo, hi, e, i);
581615
}
582616

583617
case (token.LPAREN) {
@@ -645,7 +679,7 @@ impure fn parse_prefix_expr(parser p) -> @ast.expr {
645679
}
646680

647681
case (_) {
648-
ret parse_path_expr(p);
682+
ret parse_dot_or_call_expr(p);
649683
}
650684
}
651685
}
@@ -658,7 +692,7 @@ impure fn parse_prefix_expr(parser p) -> @ast.expr {
658692
}
659693

660694
case (_) {
661-
ret parse_path_expr(p);
695+
ret parse_dot_or_call_expr(p);
662696
}
663697
}
664698
ret @spanned(lo, hi, ex);
@@ -1254,7 +1288,7 @@ fn stmt_ends_with_semi(@ast.stmt stmt) -> bool {
12541288
{ ret true; }
12551289
case (ast.expr_field(_,_,_)) { ret true; }
12561290
case (ast.expr_index(_,_,_)) { ret true; }
1257-
case (ast.expr_name(_,_,_)) { ret true; }
1291+
case (ast.expr_path(_,_,_)) { ret true; }
12581292
case (_) { fail; }
12591293
}
12601294
}

trunk/src/comp/middle/fold.rs

Lines changed: 21 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ import util.common.append;
1111

1212
import front.ast;
1313
import front.ast.ident;
14-
import front.ast.name;
1514
import front.ast.path;
1615
import front.ast.mutability;
1716
import front.ast.ty;
@@ -34,8 +33,8 @@ import std._vec;
3433
type ast_fold[ENV] =
3534
@rec
3635
(
37-
// Name fold.
38-
(fn(&ENV e, &span sp, ast.name_ n) -> name) fold_name,
36+
// Path fold.
37+
(fn(&ENV e, &span sp, ast.path_ p) -> path) fold_path,
3938

4039
// Type folds.
4140
(fn(&ENV e, &span sp) -> @ty) fold_ty_nil,
@@ -137,9 +136,9 @@ type ast_fold[ENV] =
137136
ann a) -> @expr) fold_expr_index,
138137

139138
(fn(&ENV e, &span sp,
140-
&name n,
139+
&path p,
141140
&option.t[def] d,
142-
ann a) -> @expr) fold_expr_name,
141+
ann a) -> @expr) fold_expr_path,
143142

144143
// Decl folds.
145144
(fn(&ENV e, &span sp,
@@ -249,13 +248,13 @@ type ast_fold[ENV] =
249248

250249
//// Fold drivers.
251250

252-
fn fold_name[ENV](&ENV env, ast_fold[ENV] fld, &name n) -> name {
251+
fn fold_path[ENV](&ENV env, ast_fold[ENV] fld, &path p) -> path {
253252
let vec[@ast.ty] tys_ = vec();
254-
for (@ast.ty t in n.node.types) {
253+
for (@ast.ty t in p.node.types) {
255254
append[@ast.ty](tys_, fold_ty(env, fld, t));
256255
}
257-
let ast.name_ n_ = rec(ident=n.node.ident, types=tys_);
258-
ret fld.fold_name(env, n.span, n_);
256+
let ast.path_ p_ = rec(idents=p.node.idents, types=tys_);
257+
ret fld.fold_path(env, p.span, p_);
259258
}
260259

261260
fn fold_ty[ENV](&ENV env, ast_fold[ENV] fld, @ty t) -> @ty {
@@ -321,11 +320,8 @@ fn fold_ty[ENV](&ENV env, ast_fold[ENV] fld, @ty t) -> @ty {
321320
}
322321

323322
case (ast.ty_path(?pth, ?ref_opt)) {
324-
let vec[ast.name] path = vec();
325-
for (ast.name n in pth) {
326-
path += fold_name(env, fld, n);
327-
}
328-
ret fld.fold_ty_path(env_, t.span, path, ref_opt);
323+
auto pth_ = fold_path(env, fld, pth);
324+
ret fld.fold_ty_path(env_, t.span, pth_, ref_opt);
329325
}
330326

331327
case (ast.ty_mutable(?ty)) {
@@ -550,9 +546,9 @@ fn fold_expr[ENV](&ENV env, ast_fold[ENV] fld, &@expr e) -> @expr {
550546
ret fld.fold_expr_index(env_, e.span, ee, iix, t);
551547
}
552548

553-
case (ast.expr_name(?n, ?r, ?t)) {
554-
auto n_ = fold_name(env_, fld, n);
555-
ret fld.fold_expr_name(env_, e.span, n_, r, t);
549+
case (ast.expr_path(?p, ?r, ?t)) {
550+
auto p_ = fold_path(env_, fld, p);
551+
ret fld.fold_expr_path(env_, e.span, p_, r, t);
556552
}
557553
}
558554

@@ -809,10 +805,10 @@ fn respan[T](&span sp, &T t) -> spanned[T] {
809805
}
810806

811807

812-
// Name identity.
808+
// Path identity.
813809

814-
fn identity_fold_name[ENV](&ENV env, &span sp, ast.name_ n) -> name {
815-
ret respan(sp, n);
810+
fn identity_fold_path[ENV](&ENV env, &span sp, ast.path_ p) -> path {
811+
ret respan(sp, p);
816812
}
817813

818814
// Type identities.
@@ -983,10 +979,10 @@ fn identity_fold_expr_index[ENV](&ENV env, &span sp,
983979
ret @respan(sp, ast.expr_index(e, ix, a));
984980
}
985981

986-
fn identity_fold_expr_name[ENV](&ENV env, &span sp,
987-
&name n, &option.t[def] d,
982+
fn identity_fold_expr_path[ENV](&ENV env, &span sp,
983+
&path p, &option.t[def] d,
988984
ann a) -> @expr {
989-
ret @respan(sp, ast.expr_name(n, d, a));
985+
ret @respan(sp, ast.expr_path(p, d, a));
990986
}
991987

992988

@@ -1176,7 +1172,7 @@ fn always_keep_going[ENV](&ENV e) -> bool {
11761172
fn new_identity_fold[ENV]() -> ast_fold[ENV] {
11771173
ret @rec
11781174
(
1179-
fold_name = bind identity_fold_name[ENV](_,_,_),
1175+
fold_path = bind identity_fold_path[ENV](_,_,_),
11801176

11811177
fold_ty_nil = bind identity_fold_ty_nil[ENV](_,_),
11821178
fold_ty_bool = bind identity_fold_ty_bool[ENV](_,_),
@@ -1214,7 +1210,7 @@ fn new_identity_fold[ENV]() -> ast_fold[ENV] {
12141210
= bind identity_fold_expr_assign_op[ENV](_,_,_,_,_,_),
12151211
fold_expr_field = bind identity_fold_expr_field[ENV](_,_,_,_,_),
12161212
fold_expr_index = bind identity_fold_expr_index[ENV](_,_,_,_,_),
1217-
fold_expr_name = bind identity_fold_expr_name[ENV](_,_,_,_,_),
1213+
fold_expr_path = bind identity_fold_expr_path[ENV](_,_,_,_,_),
12181214

12191215
fold_decl_local = bind identity_fold_decl_local[ENV](_,_,_),
12201216
fold_decl_item = bind identity_fold_decl_item[ENV](_,_,_),

0 commit comments

Comments
 (0)