about summary refs log tree commit diff
path: root/src/comp
diff options
context:
space:
mode:
authorGraydon Hoare <graydon@mozilla.com>2011-07-26 15:37:36 -0700
committerGraydon Hoare <graydon@mozilla.com>2011-07-26 15:41:42 -0700
commit1c97510a1677a93fea9d893325c828daee833b1e (patch)
treeea9f69667520dcd339cde1ec4f694c90af443231 /src/comp
parent69f8d0e7873ef1f1de30416aed45a706fc11457d (diff)
downloadrust-1c97510a1677a93fea9d893325c828daee833b1e.tar.gz
rust-1c97510a1677a93fea9d893325c828daee833b1e.zip
Improve printing of mod and native mod.
Diffstat (limited to 'src/comp')
-rw-r--r--src/comp/syntax/print/pprust.rs80
1 files changed, 47 insertions, 33 deletions
diff --git a/src/comp/syntax/print/pprust.rs b/src/comp/syntax/print/pprust.rs
index 2001646b20b..e73546b3cc4 100644
--- a/src/comp/syntax/print/pprust.rs
+++ b/src/comp/syntax/print/pprust.rs
@@ -246,17 +246,27 @@ fn commasep_exprs(&ps s, breaks b, &(@ast::expr)[] exprs) {
     commasep_cmnt(s, b, exprs, print_expr, expr_span);
 }
 
-fn print_mod(&ps s, ast::_mod _mod, &ast::attribute[] attrs) {
+fn print_mod(&ps s, &ast::_mod _mod, &ast::attribute[] attrs) {
     print_inner_attributes(s, attrs);
     for (@ast::view_item vitem in _mod.view_items) {
         print_view_item(s, vitem);
     }
     for (@ast::item item in _mod.items) {
-        hardbreak_if_not_bol(s);
         print_item(s, item);
     }
 }
 
+fn print_native_mod(&ps s, &ast::native_mod nmod,
+                    &ast::attribute[] attrs) {
+    print_inner_attributes(s, attrs);
+    for (@ast::view_item vitem in nmod.view_items) {
+        print_view_item(s, vitem);
+    }
+    for (@ast::native_item item in nmod.items) {
+        print_native_item(s, item);
+    }
+}
+
 fn print_boxed_type(&ps s, &@ast::ty ty) { print_type(s, *ty); }
 
 fn print_type(&ps s, &ast::ty ty) {
@@ -347,6 +357,40 @@ fn print_type(&ps s, &ast::ty ty) {
     end(s);
 }
 
+fn print_native_item(&ps s, &@ast::native_item item) {
+    hardbreak_if_not_bol(s);
+    maybe_print_comment(s, item.span.lo);
+    print_outer_attributes(s, item.attrs);
+    alt (item.node) {
+      ast::native_item_ty {
+        ibox(s, indent_unit);
+        ibox(s, 0u);
+        word_nbsp(s, "type");
+        word(s.s, item.ident);
+        end(s); // end the inner ibox
+        word(s.s, ";");
+        end(s); // end the outer ibox
+
+      }
+
+      ast::native_item_fn(?lname, ?decl, ?typarams) {
+        print_fn(s, decl, ast::proto_fn, item.ident,
+                 typarams);
+        alt (lname) {
+          none { }
+          some(?ss) {
+            space(s.s);
+            word_space(s, "=");
+            print_string(s, ss);
+          }
+        }
+        end(s); // end head-ibox
+        word(s.s, ";");
+        end(s); // end the outer fn box
+      }
+    }
+}
+
 fn print_item(&ps s, &@ast::item item) {
     hardbreak_if_not_bol(s);
     maybe_print_comment(s, item.span.lo);
@@ -392,37 +436,7 @@ fn print_item(&ps s, &@ast::item item) {
             word_nbsp(s, "mod");
             word_nbsp(s, item.ident);
             bopen(s);
-            print_inner_attributes(s, item.attrs);
-            for (@ast::native_item item in nmod.items) {
-                hardbreak_if_not_bol(s);
-                print_outer_attributes(s, item.attrs);
-                ibox(s, indent_unit);
-                maybe_print_comment(s, item.span.lo);
-                alt (item.node) {
-                    case (ast::native_item_ty) {
-                        word_nbsp(s, "type");
-                        word(s.s, item.ident);
-                    }
-                    case (ast::native_item_fn(?lname, ?decl, ?typarams)) {
-                        print_fn(s, decl, ast::proto_fn, item.ident,
-                                 typarams);
-                        alt (lname) {
-                            case (none) { }
-                            case (some(?ss)) {
-                                space(s.s);
-                                word_space(s, "=");
-                                print_string(s, ss);
-                            }
-                        }
-                        end(s); // end head-ibox
-
-                        end(s); // end the outer fn box
-
-                    }
-                }
-                word(s.s, ";");
-                end(s);
-            }
+            print_native_mod(s, nmod, item.attrs);
             bclose(s, item.span);
         }
         case (ast::item_ty(?ty, ?params)) {