about summary refs log tree commit diff
path: root/src/comp
diff options
context:
space:
mode:
authorErick Tryzelaar <erick.tryzelaar@gmail.com>2011-08-16 09:03:58 -0700
committerErick Tryzelaar <erick.tryzelaar@gmail.com>2011-08-16 14:16:14 -0700
commit014c6922e12d4faa6a2181674d12a7f487c06bb6 (patch)
tree2cee316e045d2742f3007bf884f460326f136606 /src/comp
parent9304b7ee5980b889e941251a8a3990593c496eff (diff)
downloadrust-014c6922e12d4faa6a2181674d12a7f487c06bb6.tar.gz
rust-014c6922e12d4faa6a2181674d12a7f487c06bb6.zip
Change expr foo[T] syntax to foo::<T>.
This preserves the old syntax for now.
Diffstat (limited to 'src/comp')
-rw-r--r--src/comp/syntax/parse/parser.rs31
-rw-r--r--src/comp/syntax/print/pprust.rs15
2 files changed, 38 insertions, 8 deletions
diff --git a/src/comp/syntax/parse/parser.rs b/src/comp/syntax/parse/parser.rs
index c629b7eaa4c..2bbebc3c56e 100644
--- a/src/comp/syntax/parse/parser.rs
+++ b/src/comp/syntax/parse/parser.rs
@@ -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;
 }
diff --git a/src/comp/syntax/print/pprust.rs b/src/comp/syntax/print/pprust.rs
index d2c2192fd02..f7a967fd57c 100644
--- a/src/comp/syntax/print/pprust.rs
+++ b/src/comp/syntax/print/pprust.rs
@@ -100,7 +100,9 @@ fn stmt_to_str(s: &ast::stmt) -> str { be to_str(s, print_stmt); }
 
 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_type(s: &ps, ty: &@ast::ty) {
         }
         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_expr(s: &ps, expr: &@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);