Skip to content

Commit 014c692

Browse files
committed
Change expr foo[T] syntax to foo::<T>.
This preserves the old syntax for now.
1 parent 9304b7e commit 014c692

File tree

2 files changed

+38
-8
lines changed

2 files changed

+38
-8
lines changed

src/comp/syntax/parse/parser.rs

+29-2
Original file line numberDiff line numberDiff line change
@@ -643,8 +643,8 @@ fn parse_fn_block_arg(p: &parser) -> ast::arg {
643643
ret {mode: m, ty: t, ident: i, id: p.get_id()};
644644
}
645645

646-
fn parse_seq_to_gt[T](sep: option::t[token::token], f: fn(&parser) -> T,
647-
p: &parser) -> [T] {
646+
fn parse_seq_to_before_gt[T](sep: option::t[token::token],
647+
f: fn(&parser) -> T, p: &parser) -> [T] {
648648
let first = true;
649649
let v = ~[];
650650
while p.peek() != token::GT &&
@@ -657,11 +657,27 @@ fn parse_seq_to_gt[T](sep: option::t[token::token], f: fn(&parser) -> T,
657657
v += ~[f(p)];
658658
}
659659

660+
ret v;
661+
}
662+
663+
fn parse_seq_to_gt[T](sep: option::t[token::token], f: fn(&parser) -> T,
664+
p: &parser) -> [T] {
665+
let v = parse_seq_to_before_gt(sep, f, p);
660666
expect_gt(p);
661667

662668
ret v;
663669
}
664670

671+
fn parse_seq_lt_gt[T](sep: option::t[token::token], f: fn(&parser) -> T,
672+
p: &parser) -> spanned[[T]] {
673+
let lo = p.get_lo_pos();
674+
expect(p, token::LT);
675+
let result = parse_seq_to_before_gt[T](sep, f, p);
676+
let hi = p.get_hi_pos();
677+
expect_gt(p);
678+
ret spanned(lo, hi, result);
679+
}
680+
665681
fn parse_seq_to_end[T](ket: token::token, sep: option::t[token::token],
666682
f: fn(&parser) -> T , p: &parser) -> [T] {
667683
let val = parse_seq_to_before_end(ket, sep, f, p);
@@ -787,6 +803,17 @@ fn parse_path_and_ty_param_substs(p: &parser) -> ast::path {
787803
{global: path.node.global,
788804
idents: path.node.idents,
789805
types: seq.node});
806+
} else if p.peek() == token::MOD_SEP {
807+
p.bump();
808+
809+
let seq = parse_seq_lt_gt(some(token::COMMA), bind parse_ty(_, false),
810+
p);
811+
let hi = seq.span.hi;
812+
path =
813+
spanned(lo, hi,
814+
{global: path.node.global,
815+
idents: path.node.idents,
816+
types: seq.node});
790817
}
791818
ret path;
792819
}

src/comp/syntax/print/pprust.rs

+9-6
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,9 @@ fn stmt_to_str(s: &ast::stmt) -> str { be to_str(s, print_stmt); }
100100

101101
fn item_to_str(i: &@ast::item) -> str { be to_str(i, print_item); }
102102

103-
fn path_to_str(p: &ast::path) -> str { be to_str(p, print_path); }
103+
fn path_to_str(p: &ast::path) -> str {
104+
be to_str(p, bind print_path(_, _, false));
105+
}
104106

105107
fn fun_to_str(f: &ast::_fn, name: str, params: &[ast::ty_param]) -> str {
106108
let writer = io::string_writer();
@@ -341,7 +343,7 @@ fn print_type(s: &ps, ty: &@ast::ty) {
341343
}
342344
bclose(s, ty.span);
343345
}
344-
ast::ty_path(path, _) { print_path(s, path); }
346+
ast::ty_path(path, _) { print_path(s, path, false); }
345347
ast::ty_type. { word(s.s, "type"); }
346348
ast::ty_constr(t, cs) {
347349
print_type(s, t);
@@ -690,7 +692,7 @@ fn print_mac(s: &ps, m: &ast::mac) {
690692
alt m.node {
691693
ast::mac_invoc(path, arg, body) {
692694
word(s.s, "#");
693-
print_path(s, path);
695+
print_path(s, path, false);
694696
alt (arg.node) {
695697
ast::expr_vec(_,_,_) {}
696698
_ { word(s.s, " "); }
@@ -933,7 +935,7 @@ fn print_expr(s: &ps, expr: &@ast::expr) {
933935
print_expr(s, index);
934936
pclose(s);
935937
}
936-
ast::expr_path(path) { print_path(s, path); }
938+
ast::expr_path(path) { print_path(s, path, true); }
937939
ast::expr_fail(maybe_fail_val) {
938940
word(s.s, "fail");
939941
alt maybe_fail_val {
@@ -1088,7 +1090,7 @@ fn print_for_decl(s: &ps, loc: &@ast::local, coll: &@ast::expr) {
10881090
print_expr(s, coll);
10891091
}
10901092

1091-
fn print_path(s: &ps, path: &ast::path) {
1093+
fn print_path(s: &ps, path: &ast::path, colons_before_params: bool) {
10921094
maybe_print_comment(s, path.span.lo);
10931095
if path.node.global { word(s.s, "::"); }
10941096
let first = true;
@@ -1097,6 +1099,7 @@ fn print_path(s: &ps, path: &ast::path) {
10971099
word(s.s, id);
10981100
}
10991101
if vec::len(path.node.types) > 0u {
1102+
if colons_before_params { word(s.s, "::"); }
11001103
word(s.s, "<");
11011104
commasep(s, inconsistent, path.node.types, print_type);
11021105
word(s.s, ">");
@@ -1112,7 +1115,7 @@ fn print_pat(s: &ps, pat: &@ast::pat) {
11121115
ast::pat_bind(id) { word(s.s, id); }
11131116
ast::pat_lit(lit) { print_literal(s, lit); }
11141117
ast::pat_tag(path, args) {
1115-
print_path(s, path);
1118+
print_path(s, path, true);
11161119
if vec::len(args) > 0u {
11171120
popen(s);
11181121
commasep(s, inconsistent, args, print_pat);

0 commit comments

Comments
 (0)