Tighten up comment rules a little more.
This commit is contained in:
parent
cf57553679
commit
1676c67446
2 changed files with 22 additions and 22 deletions
|
@ -547,7 +547,7 @@ fn eof(printer p) { p.pretty_print(EOF); }
|
||||||
fn word(printer p, str wrd) {
|
fn word(printer p, str wrd) {
|
||||||
p.pretty_print(STRING(wrd, str::char_len(wrd) as int));
|
p.pretty_print(STRING(wrd, str::char_len(wrd) as int));
|
||||||
}
|
}
|
||||||
fn word_and_eol(printer p, str wrd) {
|
fn huge_word(printer p, str wrd) {
|
||||||
p.pretty_print(STRING(wrd, 0xffff));
|
p.pretty_print(STRING(wrd, 0xffff));
|
||||||
}
|
}
|
||||||
fn spaces(printer p, uint n) { break_offset(p, n, 0); }
|
fn spaces(printer p, uint n) { break_offset(p, n, 0); }
|
||||||
|
|
|
@ -17,7 +17,7 @@ import pp::box;
|
||||||
import pp::cbox;
|
import pp::cbox;
|
||||||
import pp::ibox;
|
import pp::ibox;
|
||||||
import pp::word;
|
import pp::word;
|
||||||
import pp::word_and_eol;
|
import pp::huge_word;
|
||||||
import pp::space;
|
import pp::space;
|
||||||
import pp::zerobreak;
|
import pp::zerobreak;
|
||||||
import pp::hardbreak;
|
import pp::hardbreak;
|
||||||
|
@ -152,7 +152,8 @@ fn commasep_cmnt[IN](ps s, breaks b, vec[IN] elts, fn(ps, &IN) op,
|
||||||
i += 1u;
|
i += 1u;
|
||||||
if (i < len) {
|
if (i < len) {
|
||||||
word(s.s, ",");
|
word(s.s, ",");
|
||||||
if (!maybe_print_line_comment(s, get_span(elt))) {space(s.s);}
|
maybe_print_trailing_comment(s, get_span(elt));
|
||||||
|
space(s.s);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
end(s.s);
|
end(s.s);
|
||||||
|
@ -350,7 +351,7 @@ fn print_item(ps s, @ast::item item) {
|
||||||
pclose(s);
|
pclose(s);
|
||||||
}
|
}
|
||||||
word(s.s, ";");
|
word(s.s, ";");
|
||||||
maybe_print_line_comment(s, v.span);
|
maybe_print_trailing_comment(s, v.span);
|
||||||
}
|
}
|
||||||
bclose(s, item.span);
|
bclose(s, item.span);
|
||||||
}
|
}
|
||||||
|
@ -409,13 +410,13 @@ fn print_block(ps s, ast::block blk) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (front::parser::stmt_ends_with_semi(st)) {word(s.s, ";");}
|
if (front::parser::stmt_ends_with_semi(st)) {word(s.s, ";");}
|
||||||
maybe_print_line_comment(s, st.span);
|
maybe_print_trailing_comment(s, st.span);
|
||||||
}
|
}
|
||||||
alt (blk.node.expr) {
|
alt (blk.node.expr) {
|
||||||
case (option::some[@ast::expr](?expr)) {
|
case (option::some[@ast::expr](?expr)) {
|
||||||
space(s.s);
|
space(s.s);
|
||||||
print_expr(s, expr);
|
print_expr(s, expr);
|
||||||
maybe_print_line_comment(s, expr.span);
|
maybe_print_trailing_comment(s, expr.span);
|
||||||
}
|
}
|
||||||
case (_) {}
|
case (_) {}
|
||||||
}
|
}
|
||||||
|
@ -1105,19 +1106,17 @@ fn maybe_print_comment(ps s, uint pos) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn maybe_print_line_comment(ps s, common::span span) -> bool {
|
fn maybe_print_trailing_comment(ps s, common::span span) {
|
||||||
auto cm;
|
auto cm;
|
||||||
alt (s.cm) {
|
alt (s.cm) {
|
||||||
case (option::some[codemap](?ccm)) {
|
case (option::some[codemap](?ccm)) {
|
||||||
cm = ccm;
|
cm = ccm;
|
||||||
}
|
}
|
||||||
case (_) {
|
case (_) { ret; }
|
||||||
ret false;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
alt (next_comment(s)) {
|
alt (next_comment(s)) {
|
||||||
case (option::some[lexer::cmnt](?cmnt)) {
|
case (option::some[lexer::cmnt](?cmnt)) {
|
||||||
if (cmnt.style != lexer::trailing) { ret false; }
|
if (cmnt.style != lexer::trailing) { ret; }
|
||||||
|
|
||||||
auto span_line = codemap::lookup_pos(cm, span.hi);
|
auto span_line = codemap::lookup_pos(cm, span.hi);
|
||||||
auto comment_line = codemap::lookup_pos(cm, cmnt.pos);
|
auto comment_line = codemap::lookup_pos(cm, cmnt.pos);
|
||||||
|
@ -1125,12 +1124,10 @@ fn maybe_print_line_comment(ps s, common::span span) -> bool {
|
||||||
word(s.s, " ");
|
word(s.s, " ");
|
||||||
print_comment(s, cmnt);
|
print_comment(s, cmnt);
|
||||||
s.cur_cmnt += 1u;
|
s.cur_cmnt += 1u;
|
||||||
ret true;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
case (_) {}
|
case (_) {}
|
||||||
}
|
}
|
||||||
ret false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn print_remaining_comments(ps s) {
|
fn print_remaining_comments(ps s) {
|
||||||
|
@ -1148,21 +1145,24 @@ fn print_remaining_comments(ps s) {
|
||||||
fn print_comment(ps s, lexer::cmnt cmnt) {
|
fn print_comment(ps s, lexer::cmnt cmnt) {
|
||||||
alt (cmnt.style) {
|
alt (cmnt.style) {
|
||||||
case (lexer::isolated) {
|
case (lexer::isolated) {
|
||||||
zerobreak(s.s);
|
hardbreak(s.s);
|
||||||
for (str line in cmnt.lines) {
|
for (str line in cmnt.lines) {
|
||||||
word_and_eol(s.s, line);
|
huge_word(s.s, line);
|
||||||
zerobreak(s.s);
|
zerobreak(s.s);
|
||||||
}
|
}
|
||||||
zerobreak(s.s);
|
|
||||||
}
|
}
|
||||||
case (lexer::trailing) {
|
case (lexer::trailing) {
|
||||||
cbox(s.s, 0u);
|
if (vec::len(cmnt.lines) == 1u) {
|
||||||
for (str line in cmnt.lines) {
|
word(s.s, cmnt.lines.(0));
|
||||||
word_and_eol(s.s, line);
|
hardbreak(s.s);
|
||||||
zerobreak(s.s);
|
} else {
|
||||||
|
cbox(s.s, 0u);
|
||||||
|
for (str line in cmnt.lines) {
|
||||||
|
huge_word(s.s, line);
|
||||||
|
zerobreak(s.s);
|
||||||
|
}
|
||||||
|
end(s.s);
|
||||||
}
|
}
|
||||||
end(s.s);
|
|
||||||
zerobreak(s.s);
|
|
||||||
}
|
}
|
||||||
case (lexer::mixed) {
|
case (lexer::mixed) {
|
||||||
assert vec::len(cmnt.lines) == 1u;
|
assert vec::len(cmnt.lines) == 1u;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue