Commit 6c13f8f1 authored by Robert Griesemer's avatar Robert Griesemer

fix a comment formatting bug:

- this ensures better comment formatting in template.go and codec_test.go
- it affects only 2 files of all files that have been gofmt'ed already,
  see separate CL (it fixes the same issue in those files)

R=rsc
http://go/go-review/1023002
parent fa57417d
......@@ -43,6 +43,7 @@ var (
htab = []byte{'\t'};
htabs = [...]byte{'\t', '\t', '\t', '\t', '\t', '\t', '\t', '\t'};
newlines = [...]byte{'\n', '\n', '\n', '\n', '\n', '\n', '\n', '\n'}; // more than maxNewlines
formfeeds = [...]byte{'\f', '\f', '\f', '\f', '\f', '\f', '\f', '\f'}; // more than maxNewlines
esc_quot = strings.Bytes("""); // shorter than """
esc_apos = strings.Bytes("'"); // shorter than "'"
......@@ -203,6 +204,16 @@ func (p *printer) writeNewlines(n int) {
}
func (p *printer) writeFormfeeds(n int) {
if n > 0 {
if n > maxNewlines {
n = maxNewlines;
}
p.write(formfeeds[0:n]);
}
}
func (p *printer) writeTaggedItem(data []byte, tag HtmlTag) {
// write start tag, if any
// (no html-escaping and no p.pos update for tags - use write0)
......@@ -332,7 +343,10 @@ func (p *printer) writeCommentPrefix(pos, next token.Position, isFirst, isKeywor
}
p.writeWhitespace(j);
}
p.writeNewlines(pos.Line - p.last.Line);
// use formfeeds to break columns before a comment;
// this is analogous to using formfeeds to separate
// individual lines of /*-style comments
p.writeFormfeeds(pos.Line - p.last.Line);
}
}
......@@ -535,7 +549,7 @@ func (p *printer) writeComment(comment *ast.Comment) {
// write comment lines, separated by formfeed,
// without a line break after the last line
linebreak := []byte{byte(formfeed)};
linebreak := formfeeds[0:1];
pos := comment.Pos();
for i, line := range lines {
if i > 0 {
......
......@@ -118,6 +118,9 @@ func typeswitch(x interface{}) {
}
switch v0, ok := x.(int); x.(type) {
case byte: // this comment should be on the same line as the keyword
// this comment should be normally indented
_ = 0;
case bool, int, float:
// this comment should be indented
case string:
......
......@@ -118,6 +118,9 @@ func typeswitch(x interface{}) {
}
switch v0, ok := x.(int); x.(type) {
case byte: // this comment should be on the same line as the keyword
// this comment should be normally indented
_ = 0;
case bool, int, float:
// this comment should be indented
case string:
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment