Skip to content

Commit 6510f1c

Browse files
committed
Change module dereference syntax from . to ::
This will need to be a snapshot.
1 parent dd9b6dc commit 6510f1c

File tree

9 files changed

+41
-111
lines changed

9 files changed

+41
-111
lines changed

src/comp/front/creader.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -312,7 +312,7 @@ fn resolve_path(vec[ast.ident] path, vec[u8] data) -> resolve_result {
312312
fn eq_item(vec[u8] data, str s) -> bool {
313313
ret Str.eq(Str.unsafe_from_bytes(data), s);
314314
}
315-
auto s = Str.connect(path, ".");
315+
auto s = Str.connect(path, "::");
316316
auto md = EBML.new_doc(data);
317317
auto paths = EBML.get_doc(md, metadata.tag_paths);
318318
auto eqer = bind eq_item(_, s);

src/comp/front/lexer.rs

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -634,7 +634,6 @@ fn next_token(reader rdr) -> token.token {
634634

635635
alt (c) {
636636
// One-byte tokens.
637-
case (':') { rdr.bump(); ret token.COLON; }
638637
case ('?') { rdr.bump(); ret token.QUES; }
639638
case (';') { rdr.bump(); ret token.SEMI; }
640639
case (',') { rdr.bump(); ret token.COMMA; }
@@ -648,7 +647,16 @@ fn next_token(reader rdr) -> token.token {
648647
case ('@') { rdr.bump(); ret token.AT; }
649648
case ('#') { rdr.bump(); ret token.POUND; }
650649
case ('~') { rdr.bump(); ret token.TILDE; }
651-
650+
case (':') {
651+
rdr.bump();
652+
if (rdr.curr() == ':') {
653+
rdr.bump();
654+
ret token.MOD_SEP;
655+
}
656+
else {
657+
ret token.COLON;
658+
};
659+
}
652660

653661
// Multi-byte tokens.
654662
case ('=') {

src/comp/front/parser.rs

Lines changed: 17 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -322,7 +322,7 @@ fn parse_constr_arg(parser p) -> @ast.constr_arg {
322322

323323
fn parse_ty_constr(parser p) -> @ast.constr {
324324
auto lo = p.get_lo_pos();
325-
auto path = parse_path(p, GREEDY);
325+
auto path = parse_path(p);
326326
auto pf = parse_constr_arg;
327327
auto args = parse_seq[@ast.constr_arg](token.LPAREN,
328328
token.RPAREN,
@@ -472,7 +472,7 @@ fn parse_ty(parser p) -> @ast.ty {
472472
}
473473

474474
case (token.IDENT(_)) {
475-
auto path = parse_path(p, GREEDY);
475+
auto path = parse_path(p);
476476
t = ast.ty_path(path, p.get_ann());
477477
hi = path.span.hi;
478478
}
@@ -603,11 +603,6 @@ fn is_ident(token.token t) -> bool {
603603
ret false;
604604
}
605605

606-
tag greed {
607-
GREEDY;
608-
MINIMAL;
609-
}
610-
611606
fn parse_ty_args(parser p, uint hi) ->
612607
util.common.spanned[vec[@ast.ty]] {
613608

@@ -623,33 +618,23 @@ fn parse_ty_args(parser p, uint hi) ->
623618
ret spanned(hi, hi, v);
624619
}
625620

626-
fn parse_path(parser p, greed g) -> ast.path {
621+
fn parse_path(parser p) -> ast.path {
627622

628623
auto lo = p.get_lo_pos();
629624
auto hi = lo;
630625

631626
let vec[ast.ident] ids = vec();
632-
let bool more = true;
633-
while (more) {
627+
while (true) {
634628
alt (p.peek()) {
635629
case (token.IDENT(?i)) {
636630
hi = p.get_hi_pos();
637631
ids += vec(p.get_str(i));
638632
p.bump();
639-
if (p.peek() == token.DOT) {
640-
if (g == GREEDY) {
641-
p.bump();
642-
assert (is_ident(p.peek()));
643-
} else {
644-
more = false;
645-
}
646-
} else {
647-
more = false;
648-
}
649-
}
650-
case (_) {
651-
more = false;
633+
if (p.peek() == token.MOD_SEP) {
634+
p.bump();
635+
} else { break; }
652636
}
637+
case (_) { break; }
653638
}
654639
}
655640

@@ -690,7 +675,7 @@ fn parse_bottom_expr(parser p) -> @ast.expr {
690675
alt (p.peek()) {
691676

692677
case (token.IDENT(_)) {
693-
auto pth = parse_path(p, MINIMAL);
678+
auto pth = parse_path(p);
694679
hi = pth.span.hi;
695680
ex = ast.expr_path(pth, p.get_ann());
696681
}
@@ -804,7 +789,7 @@ fn parse_bottom_expr(parser p) -> @ast.expr {
804789

805790
case (token.POUND) {
806791
p.bump();
807-
auto pth = parse_path(p, GREEDY);
792+
auto pth = parse_path(p);
808793
auto pf = parse_expr;
809794
auto es = parse_seq[@ast.expr](token.LPAREN,
810795
token.RPAREN,
@@ -980,31 +965,6 @@ fn expand_syntax_ext(parser p, ast.span sp,
980965
}
981966
}
982967

983-
fn extend_expr_by_ident(parser p, uint lo, uint hi,
984-
@ast.expr e, ast.ident i) -> @ast.expr {
985-
auto e_ = e.node;
986-
alt (e.node) {
987-
case (ast.expr_path(?pth, ?ann)) {
988-
if (Vec.len[@ast.ty](pth.node.types) == 0u) {
989-
auto idents_ = pth.node.idents;
990-
idents_ += vec(i);
991-
auto tys = parse_ty_args(p, hi);
992-
auto pth_ = spanned(pth.span.lo, tys.span.hi,
993-
rec(idents=idents_,
994-
types=tys.node));
995-
e_ = ast.expr_path(pth_, ann);
996-
ret @spanned(pth_.span.lo, pth_.span.hi, e_);
997-
} else {
998-
e_ = ast.expr_field(e, i, ann);
999-
}
1000-
}
1001-
case (_) {
1002-
e_ = ast.expr_field(e, i, p.get_ann());
1003-
}
1004-
}
1005-
ret @spanned(lo, hi, e_);
1006-
}
1007-
1008968
fn parse_self_method(parser p) -> @ast.expr {
1009969
auto sp = p.get_span();
1010970
let ast.ident f_name = parse_ident(p);
@@ -1042,7 +1002,9 @@ fn parse_dot_or_call_expr(parser p) -> @ast.expr {
10421002
case (token.IDENT(?i)) {
10431003
hi = p.get_hi_pos();
10441004
p.bump();
1045-
e = extend_expr_by_ident(p, lo, hi, e, p.get_str(i));
1005+
auto e_ = ast.expr_field(e, p.get_str(i),
1006+
p.get_ann());
1007+
e = @spanned(lo, hi, e_);
10461008
}
10471009

10481010
case (token.LPAREN) {
@@ -1404,7 +1366,7 @@ fn parse_spawn_expr(parser p) -> @ast.expr {
14041366
expect(p, token.SPAWN);
14051367

14061368
// FIXME: Parse domain and name
1407-
1369+
// FIXME: why no full expr?
14081370
auto fn_expr = parse_bottom_expr(p);
14091371
auto pf = parse_expr;
14101372
auto es = parse_seq[@ast.expr](token.LPAREN,
@@ -1509,7 +1471,7 @@ fn parse_pat(parser p) -> @ast.pat {
15091471
}
15101472
}
15111473
case (token.IDENT(_)) {
1512-
auto tag_path = parse_path(p, GREEDY);
1474+
auto tag_path = parse_path(p);
15131475
hi = tag_path.span.hi;
15141476

15151477
let vec[@ast.pat] args;
@@ -2249,7 +2211,7 @@ fn parse_rest_import_name(parser p, ast.ident first,
22492211
auto lo = p.get_lo_pos();
22502212
let vec[ast.ident] identifiers = vec(first);
22512213
while (p.peek() != token.SEMI) {
2252-
expect(p, token.DOT);
2214+
expect(p, token.MOD_SEP);
22532215
auto i = parse_ident(p);
22542216
identifiers += vec(i);
22552217
}
@@ -2377,7 +2339,7 @@ fn parse_crate_directive(parser p) -> ast.crate_directive
23772339
alt (p.peek()) {
23782340
case (token.AUTH) {
23792341
p.bump();
2380-
auto n = parse_path(p, GREEDY);
2342+
auto n = parse_path(p);
23812343
expect(p, token.EQ);
23822344
auto a = parse_auth(p);
23832345
auto hi = p.get_hi_pos();

src/comp/front/token.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ tag token {
4747
COMMA;
4848
SEMI;
4949
COLON;
50+
MOD_SEP;
5051
QUES;
5152
RARROW;
5253
SEND;
@@ -218,6 +219,7 @@ fn to_str(lexer.reader r, token t) -> str {
218219
case (COMMA) { ret ","; }
219220
case (SEMI) { ret ";"; }
220221
case (COLON) { ret ":"; }
222+
case (MOD_SEP) { ret "::"; }
221223
case (QUES) { ret "?"; }
222224
case (RARROW) { ret "->"; }
223225
case (SEND) { ret "<|"; }

src/comp/middle/metadata.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -301,7 +301,7 @@ fn add_to_index(&EBML.writer ebml_w,
301301
&mutable vec[tup(str, uint)] index,
302302
&str name) {
303303
auto full_path = path + vec(name);
304-
index += vec(tup(Str.connect(full_path, "."), ebml_w.writer.tell()));
304+
index += vec(tup(Str.connect(full_path, "::"), ebml_w.writer.tell()));
305305
}
306306

307307
fn encode_native_module_item_paths(&EBML.writer ebml_w,

src/comp/middle/resolve.rs

Lines changed: 6 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,7 @@ fn resolve_imports(&env e) {
170170
}
171171
}
172172

173+
// FIXME this should use walk (will need to add walk_arm)
173174
fn resolve_names(&@env e, &ast.crate c) -> @ast.crate {
174175
auto fld = @rec(fold_pat_tag = bind fold_pat_tag(e,_,_,_,_,_),
175176
fold_expr_path = bind fold_expr_path(e,_,_,_,_),
@@ -277,54 +278,11 @@ fn resolve_import(&env e, &@ast.view_item it, &list[scope] sc) {
277278
}
278279
}
279280

280-
// We received a path expression of the following form:
281-
//
282-
// a.b.c.d
283-
//
284-
// Somewhere along this path there might be a split from a path-expr
285-
// to a runtime field-expr. For example:
286-
//
287-
// 'a' could be the name of a variable in the local scope
288-
// and 'b.c.d' could be a field-sequence inside it.
289-
//
290-
// Or:
291-
//
292-
// 'a.b' could be a module path to a constant record, and 'c.d'
293-
// could be a field within it.
294-
//
295-
// Our job here is to figure out what the prefix of 'a.b.c.d' is that
296-
// corresponds to a static binding-name (a module or slot, with no type info)
297-
// and split that off as the 'primary' expr_path, with secondary expr_field
298-
// expressions tacked on the end.
299-
300281
fn fold_expr_path(@env e, &list[scope] sc, &span sp, &ast.path p, &ann a)
301282
-> @ast.expr {
302-
auto idents = p.node.idents;
303-
auto n_idents = Vec.len(idents);
304-
assert (n_idents != 0u);
305-
306-
auto dcur = lookup_in_scope_strict(*e, sc, sp, idents.(0), ns_value);
307-
auto i = 1u;
308-
while (i < n_idents) {
309-
if (!is_module(dcur)) { break; }
310-
dcur = lookup_in_mod_strict(*e, dcur, sp, idents.(i), ns_value,
311-
outside);
312-
i += 1u;
313-
}
314-
if (is_module(dcur)) {
315-
e.sess.span_err(sp, "can't refer to a module as a first-class value");
316-
}
317-
318-
p = rec(node=rec(idents=Vec.slice(idents, 0u, i) with p.node) with p);
319-
auto ex = @fold.respan(sp, ast.expr_path(p, a));
320-
e.def_map.insert(ast.ann_tag(a), dcur);
321-
// FIXME this duplicates the ann. Is that a problem? How will we deal with
322-
// splitting this into path and field exprs when we don't fold?
323-
while (i < n_idents) {
324-
ex = @fold.respan(sp, ast.expr_field(ex, idents.(i), a));
325-
i += 1u;
326-
}
327-
ret ex;
283+
auto df = lookup_path_strict(*e, sc, sp, p.node.idents, ns_value);
284+
e.def_map.insert(ast.ann_tag(a), df);
285+
ret @fold.respan(sp, ast.expr_path(p, a));
328286
}
329287

330288

@@ -337,7 +295,7 @@ fn fold_pat_tag(@env e, &list[scope] sc, &span sp, &ast.path p,
337295
}
338296
case (_) {
339297
e.sess.span_err(sp, "not a tag variant: " +
340-
Str.connect(p.node.idents, "."));
298+
Str.connect(p.node.idents, "::"));
341299
fail;
342300
}
343301
}
@@ -383,7 +341,7 @@ fn lookup_path_strict(&env e, &list[scope] sc, &span sp, vec[ident] idents,
383341
i += 1u;
384342
}
385343
if (is_module(dcur)) {
386-
e.sess.span_err(sp, Str.connect(idents, ".") +
344+
e.sess.span_err(sp, Str.connect(idents, "::") +
387345
" is a module, not a " + ns_name(ns));
388346
}
389347
ret dcur;

src/comp/middle/trans.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5439,7 +5439,7 @@ fn load_if_immediate(&@block_ctxt cx, ValueRef v, &ty.t t) -> ValueRef {
54395439

54405440
fn trans_log(int lvl, &@block_ctxt cx, &@ast.expr e) -> result {
54415441
auto lcx = cx.fcx.lcx;
5442-
auto modname = Str.connect(lcx.module_path, ".");
5442+
auto modname = Str.connect(lcx.module_path, "::");
54435443
auto global;
54445444
if (lcx.ccx.module_data.contains_key(modname)) {
54455445
global = lcx.ccx.module_data.get(modname);

src/comp/middle/ty.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -484,7 +484,7 @@ fn cname(&ctxt cx, &t typ) -> Option.t[str] { ret cx.ts.others.(typ).cname; }
484484
// Stringification
485485

486486
fn path_to_str(&ast.path pth) -> str {
487-
auto result = Str.connect(pth.node.idents, ".");
487+
auto result = Str.connect(pth.node.idents, "::");
488488
if (Vec.len[@ast.ty](pth.node.types) > 0u) {
489489
auto f = pretty.pprust.ty_to_str;
490490
result += "[";

src/comp/pretty/pprust.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -751,7 +751,7 @@ fn print_path(ps s, ast.path path) {
751751
auto first = true;
752752
for (str id in path.node.idents) {
753753
if (first) {first = false;}
754-
else {wrd(s.s, ".");}
754+
else {wrd(s.s, "::");}
755755
wrd(s.s, id);
756756
}
757757
if (Vec.len[@ast.ty](path.node.types) > 0u) {
@@ -856,7 +856,7 @@ fn print_view_item(ps s, @ast.view_item item) {
856856
auto first = true;
857857
for (str elt in ids) {
858858
if (first) {first = false;}
859-
else {wrd(s.s, ".");}
859+
else {wrd(s.s, ":");}
860860
wrd(s.s, elt);
861861
}
862862
}

0 commit comments

Comments
 (0)