Recognize and preserve first blank line if first line of file.

This commit is contained in:
Graydon Hoare 2011-07-25 17:09:45 -07:00
parent ac2424dd22
commit 1243ce271e

View File

@ -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);
}