Change expr foo[T] syntax to foo::<T>.

This preserves the old syntax for now.
This commit is contained in:
Erick Tryzelaar 2011-08-16 09:03:58 -07:00
parent 9304b7ee59
commit 014c6922e1
2 changed files with 38 additions and 8 deletions

View File

@ -643,8 +643,8 @@ fn parse_fn_block_arg(p: &parser) -> ast::arg {
ret {mode: m, ty: t, ident: i, id: p.get_id()};
}
fn parse_seq_to_gt[T](sep: option::t[token::token], f: fn(&parser) -> T,
p: &parser) -> [T] {
fn parse_seq_to_before_gt[T](sep: option::t[token::token],
f: fn(&parser) -> T, p: &parser) -> [T] {
let first = true;
let v = ~[];
while p.peek() != token::GT &&
@ -657,11 +657,27 @@ fn parse_seq_to_gt[T](sep: option::t[token::token], f: fn(&parser) -> T,
v += ~[f(p)];
}
ret v;
}
fn parse_seq_to_gt[T](sep: option::t[token::token], f: fn(&parser) -> T,
p: &parser) -> [T] {
let v = parse_seq_to_before_gt(sep, f, p);
expect_gt(p);
ret v;
}
fn parse_seq_lt_gt[T](sep: option::t[token::token], f: fn(&parser) -> T,
p: &parser) -> spanned[[T]] {
let lo = p.get_lo_pos();
expect(p, token::LT);
let result = parse_seq_to_before_gt[T](sep, f, p);
let hi = p.get_hi_pos();
expect_gt(p);
ret spanned(lo, hi, result);
}
fn parse_seq_to_end[T](ket: token::token, sep: option::t[token::token],
f: fn(&parser) -> T , p: &parser) -> [T] {
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 {
{global: path.node.global,
idents: path.node.idents,
types: seq.node});
} else if p.peek() == token::MOD_SEP {
p.bump();
let seq = parse_seq_lt_gt(some(token::COMMA), bind parse_ty(_, false),
p);
let hi = seq.span.hi;
path =
spanned(lo, hi,
{global: path.node.global,
idents: path.node.idents,
types: seq.node});
}
ret path;
}

View File

@ -100,7 +100,9 @@ fn print_crate(cm: &codemap, crate: @ast::crate, filename: str,
fn item_to_str(i: &@ast::item) -> str { be to_str(i, print_item); }
fn path_to_str(p: &ast::path) -> str { be to_str(p, print_path); }
fn path_to_str(p: &ast::path) -> str {
be to_str(p, bind print_path(_, _, false));
}
fn fun_to_str(f: &ast::_fn, name: str, params: &[ast::ty_param]) -> str {
let writer = io::string_writer();
@ -341,7 +343,7 @@ fn print_field(s: &ps, f: &ast::ty_field) {
}
bclose(s, ty.span);
}
ast::ty_path(path, _) { print_path(s, path); }
ast::ty_path(path, _) { print_path(s, path, false); }
ast::ty_type. { word(s.s, "type"); }
ast::ty_constr(t, cs) {
print_type(s, t);
@ -690,7 +692,7 @@ fn print_mac(s: &ps, m: &ast::mac) {
alt m.node {
ast::mac_invoc(path, arg, body) {
word(s.s, "#");
print_path(s, path);
print_path(s, path, false);
alt (arg.node) {
ast::expr_vec(_,_,_) {}
_ { word(s.s, " "); }
@ -933,7 +935,7 @@ fn print_opt(s: &ps, expr: &option::t[@ast::expr]) {
print_expr(s, index);
pclose(s);
}
ast::expr_path(path) { print_path(s, path); }
ast::expr_path(path) { print_path(s, path, true); }
ast::expr_fail(maybe_fail_val) {
word(s.s, "fail");
alt maybe_fail_val {
@ -1088,7 +1090,7 @@ fn print_for_decl(s: &ps, loc: &@ast::local, coll: &@ast::expr) {
print_expr(s, coll);
}
fn print_path(s: &ps, path: &ast::path) {
fn print_path(s: &ps, path: &ast::path, colons_before_params: bool) {
maybe_print_comment(s, path.span.lo);
if path.node.global { word(s.s, "::"); }
let first = true;
@ -1097,6 +1099,7 @@ fn print_path(s: &ps, path: &ast::path) {
word(s.s, id);
}
if vec::len(path.node.types) > 0u {
if colons_before_params { word(s.s, "::"); }
word(s.s, "<");
commasep(s, inconsistent, path.node.types, print_type);
word(s.s, ">");
@ -1112,7 +1115,7 @@ fn print_pat(s: &ps, pat: &@ast::pat) {
ast::pat_bind(id) { word(s.s, id); }
ast::pat_lit(lit) { print_literal(s, lit); }
ast::pat_tag(path, args) {
print_path(s, path);
print_path(s, path, true);
if vec::len(args) > 0u {
popen(s);
commasep(s, inconsistent, args, print_pat);