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 &&
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);
{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;
}
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();
}
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);
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, " "); }
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 {
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;
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, ">");
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);