Skip to content

Commit ae17593

Browse files
committed
---
yaml --- r: 3515 b: refs/heads/master c: 6d441d3 h: refs/heads/master i: 3513: 37e7fa8 3511: 8e39362 v: v3
1 parent 5832267 commit ae17593

File tree

4 files changed

+33
-14
lines changed

4 files changed

+33
-14
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
---
2-
refs/heads/master: dc9f285b069d598f571d70e895726221140f32f0
2+
refs/heads/master: 6d441d32381037401642a204ddb8eccc71f4e4c5

trunk/src/comp/front/lexer.rs

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -536,6 +536,8 @@ tag cmnt_style {
536536

537537
mixed; // Code before /* foo */ and after the comment
538538

539+
blank_line; // Just a manual blank linke "\n\n", for layout
540+
539541
}
540542

541543
type cmnt = rec(cmnt_style style, vec[str] lines, uint pos);
@@ -546,7 +548,6 @@ fn read_to_eol(&reader rdr) -> str {
546548
str::push_char(val, rdr.curr());
547549
rdr.bump();
548550
}
549-
if (rdr.curr() == '\n') { rdr.bump(); } else { assert (rdr.is_eof()); }
550551
ret val;
551552
}
552553

@@ -566,6 +567,19 @@ fn consume_non_eol_whitespace(&reader rdr) {
566567
}
567568
}
568569

570+
fn consume_whitespace_counting_blank_lines(&reader rdr,
571+
&mutable vec[cmnt] comments) {
572+
while (is_whitespace(rdr.curr()) && !rdr.is_eof()) {
573+
if (rdr.curr() == '\n' && rdr.next() == '\n') {
574+
log ">>> blank-line comment";
575+
let vec[str] v = [];
576+
comments += [rec(style=blank_line, lines=v,
577+
pos=rdr.get_chpos())];
578+
}
579+
rdr.bump();
580+
}
581+
}
582+
569583
fn read_line_comments(&reader rdr, bool code_to_the_left) -> cmnt {
570584
log ">>> line comments";
571585
auto p = rdr.get_chpos();
@@ -694,19 +708,21 @@ fn gather_comments_and_literals(session sess, str path) ->
694708
consume_non_eol_whitespace(rdr);
695709
if (rdr.curr() == '\n') {
696710
code_to_the_left = false;
697-
consume_whitespace(rdr);
711+
consume_whitespace_counting_blank_lines(rdr, comments);
698712
}
699713
while (peeking_at_comment(rdr)) {
700714
consume_comment(rdr, code_to_the_left, comments);
701-
consume_whitespace(rdr);
715+
consume_whitespace_counting_blank_lines(rdr, comments);
702716
}
703717
break;
704718
}
705-
if (is_lit(next_token(rdr))) {
719+
auto tok = next_token(rdr);
720+
if (is_lit(tok)) {
706721
vec::push[lit](literals,
707722
rec(lit=rdr.get_mark_str(),
708723
pos=rdr.get_mark_chpos()));
709724
}
725+
log "tok: " + token::to_str(rdr, tok);
710726
first_read = false;
711727
}
712728
ret rec(cmnts=comments, lits=literals);

trunk/src/comp/pretty/ppaux.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -279,6 +279,11 @@ fn print_comment(&ps s, lexer::cmnt cmnt) {
279279
end(s);
280280
}
281281
}
282+
case (lexer::blank_line) {
283+
// We need to do at least one, possibly two hardbreaks.
284+
pprust::hardbreak_if_not_bol(s);
285+
hardbreak(s.s);
286+
}
282287
}
283288
}
284289

trunk/src/comp/pretty/pprust.rs

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -191,9 +191,7 @@ fn print_mod(&ps s, ast::_mod _mod, &vec[ast::attribute] attrs) {
191191
print_view_item(s, vitem);
192192
}
193193
for (@ast::item item in _mod.items) {
194-
// Mod-level item printing we're a little more space-y about.
195-
hardbreak(s.s);
196-
hardbreak(s.s);
194+
hardbreak_if_not_bol(s);
197195
print_item(s, item);
198196
}
199197
print_remaining_comments(s);
@@ -271,7 +269,7 @@ fn print_type(&ps s, &ast::ty ty) {
271269
head(s, "obj");
272270
bopen(s);
273271
for (ast::ty_method m in methods) {
274-
hardbreak(s.s);
272+
hardbreak_if_not_bol(s);
275273
cbox(s, indent_unit);
276274
maybe_print_comment(s, m.span.lo);
277275
print_ty_fn(s, m.node.proto, some(m.node.ident),
@@ -338,7 +336,7 @@ fn print_item(&ps s, &@ast::item item) {
338336
word_nbsp(s, item.ident);
339337
bopen(s);
340338
for (@ast::native_item item in nmod.items) {
341-
hardbreak(s.s);
339+
hardbreak_if_not_bol(s);
342340
ibox(s, indent_unit);
343341
maybe_print_comment(s, item.span.lo);
344342
alt (item.node) {
@@ -427,7 +425,7 @@ fn print_item(&ps s, &@ast::item item) {
427425
bopen(s);
428426
for (@ast::method meth in _obj.methods) {
429427
let vec[ast::ty_param] typarams = [];
430-
hardbreak(s.s);
428+
hardbreak_if_not_bol(s);
431429
maybe_print_comment(s, meth.span.lo);
432430
print_fn(s, meth.node.meth.decl, meth.node.meth.proto,
433431
meth.node.ident, typarams);
@@ -475,7 +473,7 @@ fn print_outer_attributes(&ps s, vec[ast::attribute] attrs) {
475473
case (_) {/* fallthrough */ }
476474
}
477475
}
478-
if (count > 0) { hardbreak(s.s); }
476+
if (count > 0) { hardbreak_if_not_bol(s); }
479477
}
480478

481479
fn print_inner_attributes(&ps s, vec[ast::attribute] attrs) {
@@ -490,11 +488,11 @@ fn print_inner_attributes(&ps s, vec[ast::attribute] attrs) {
490488
case (_) { /* fallthrough */ }
491489
}
492490
}
493-
if (count > 0) { hardbreak(s.s); }
491+
if (count > 0) { hardbreak_if_not_bol(s); }
494492
}
495493

496494
fn print_attribute(&ps s, &ast::attribute attr) {
497-
hardbreak(s.s);
495+
hardbreak_if_not_bol(s);
498496
maybe_print_comment(s, attr.span.lo);
499497
word(s.s, "#[");
500498
print_meta_item(s, @attr.node.value);

0 commit comments

Comments
 (0)