about summary refs log tree commit diff
path: root/src/librustsyntax/parse
diff options
context:
space:
mode:
authorMargaret Meyerhofer <mmeyerho@andrew>2012-05-22 17:49:16 -0700
committerMargaret Meyerhofer <mmeyerho@andrew>2012-05-22 17:49:16 -0700
commit3177286a248b4ca308fbc6b2b22689123bccaeec (patch)
tree9491246bb545e017ecf5b744d1b67f9930bac6e2 /src/librustsyntax/parse
parentf1cea3ce21eb896b0849eca0a8fd9ea4e03ab35f (diff)
downloadrust-3177286a248b4ca308fbc6b2b22689123bccaeec.tar.gz
rust-3177286a248b4ca308fbc6b2b22689123bccaeec.zip
Changed the pretty printer also read #! comments
Diffstat (limited to 'src/librustsyntax/parse')
-rw-r--r--src/librustsyntax/parse/comments.rs20
1 files changed, 17 insertions, 3 deletions
diff --git a/src/librustsyntax/parse/comments.rs b/src/librustsyntax/parse/comments.rs
index 493ed7b369b..9fa4a4c3e8c 100644
--- a/src/librustsyntax/parse/comments.rs
+++ b/src/librustsyntax/parse/comments.rs
@@ -1,4 +1,5 @@
 import io::reader_util;
+import io::println;//XXXXXXXXxxx
 import util::interner;
 import lexer::{ reader, new_reader, next_token, is_whitespace };
 
@@ -28,7 +29,8 @@ fn read_to_eol(rdr: reader) -> str {
 
 fn read_one_line_comment(rdr: reader) -> str {
     let val = read_to_eol(rdr);
-    assert (val[0] == '/' as u8 && val[1] == '/' as u8);
+    assert ((val[0] == '/' as u8 && val[1] == '/' as u8) ||
+            (val[0] == '#' as u8 && val[1] == '!' as u8));
     ret val;
 }
 
@@ -53,6 +55,15 @@ fn consume_whitespace_counting_blank_lines(rdr: reader, &comments: [cmnt]) {
     }
 }
 
+fn read_shebang_comment(rdr: reader, code_to_the_left: bool) -> cmnt {
+    #debug(">>> shebang comment");
+    let p = rdr.chpos;
+    #debug("<<< shebang comment");
+    ret {style: if code_to_the_left { trailing } else { isolated },
+         lines: [read_one_line_comment(rdr)],
+         pos: p};
+}
+
 fn read_line_comments(rdr: reader, code_to_the_left: bool) -> cmnt {
     #debug(">>> line comments");
     let p = rdr.chpos;
@@ -134,8 +145,9 @@ fn read_block_comment(rdr: reader, code_to_the_left: bool) -> cmnt {
 }
 
 fn peeking_at_comment(rdr: reader) -> bool {
-    ret rdr.curr == '/' && rdr.next() == '/' ||
-            rdr.curr == '/' && rdr.next() == '*';
+    ret ((rdr.curr == '/' && rdr.next() == '/') ||
+         (rdr.curr == '/' && rdr.next() == '*')) ||
+        (rdr.curr == '#' && rdr.next() == '!');
 }
 
 fn consume_comment(rdr: reader, code_to_the_left: bool, &comments: [cmnt]) {
@@ -144,6 +156,8 @@ fn consume_comment(rdr: reader, code_to_the_left: bool, &comments: [cmnt]) {
         comments += [read_line_comments(rdr, code_to_the_left)];
     } else if rdr.curr == '/' && rdr.next() == '*' {
         comments += [read_block_comment(rdr, code_to_the_left)];
+    } else if rdr.curr == '#' && rdr.next() == '!' {
+        comments += [read_shebang_comment(rdr, code_to_the_left)];
     } else { fail; }
     #debug("<<< consume comment");
 }