about summary refs log tree commit diff
path: root/src/comp/syntax/parse
diff options
context:
space:
mode:
authorGraydon Hoare <graydon@mozilla.com>2011-07-25 17:09:45 -0700
committerGraydon Hoare <graydon@mozilla.com>2011-07-25 17:10:08 -0700
commit1243ce271e0e2340a3cdebae7a70d3b61e86bc23 (patch)
tree619acf06fb327d0637b5f6765a580775aec8a116 /src/comp/syntax/parse
parentac2424dd22eb5faf5da86cef6d723d07e548a7b4 (diff)
downloadrust-1243ce271e0e2340a3cdebae7a70d3b61e86bc23.tar.gz
rust-1243ce271e0e2340a3cdebae7a70d3b61e86bc23.zip
Recognize and preserve first blank line if first line of file.
Diffstat (limited to 'src/comp/syntax/parse')
-rw-r--r--src/comp/syntax/parse/lexer.rs18
1 files changed, 13 insertions, 5 deletions
diff --git a/src/comp/syntax/parse/lexer.rs b/src/comp/syntax/parse/lexer.rs
index 9f9c2a1f269..cdbc6bafec9 100644
--- a/src/comp/syntax/parse/lexer.rs
+++ b/src/comp/syntax/parse/lexer.rs
@@ -609,14 +609,19 @@ fn consume_non_eol_whitespace(&reader rdr) {
     }
 }
 
+fn push_blank_line_comment(&reader rdr,
+                           &mutable cmnt[] comments) {
+    log ">>> blank-line comment";
+    let str[] v = ~[];
+    comments += ~[rec(style=blank_line, lines=v,
+                      pos=rdr.get_chpos())];
+}
+
 fn consume_whitespace_counting_blank_lines(&reader rdr,
                                            &mutable cmnt[] comments) {
     while (is_whitespace(rdr.curr()) && !rdr.is_eof()) {
-        if (rdr.curr() == '\n' && rdr.next() == '\n') {
-            log ">>> blank-line comment";
-            let str[] v = ~[];
-            comments += ~[rec(style=blank_line, lines=v,
-                              pos=rdr.get_chpos())];
+        if rdr.curr() == '\n' && rdr.next() == '\n' {
+            push_blank_line_comment(rdr, comments);
         }
         rdr.bump();
     }
@@ -750,6 +755,9 @@ fn gather_comments_and_literals(&codemap::codemap cm, str path,
             auto code_to_the_left = !first_read;
             consume_non_eol_whitespace(rdr);
             if (rdr.curr() == '\n') {
+                if first_read {
+                    push_blank_line_comment(rdr, comments);
+                }
                 code_to_the_left = false;
                 consume_whitespace_counting_blank_lines(rdr, comments);
             }