Commit 7ecfb021 authored by Robert Griesemer's avatar Robert Griesemer

- rewrite declaration printing to take full use of discardable tabwriter columns

- honor line breaks in multi-line expressions
- do not add extra indentation to multi-line string lists
- don't put blanks around simple function calls and conversions
- do not modify `` strings
- added extra test cases

R=rsc
DELTA=398  (246 added, 51 deleted, 101 changed)
OCL=35453
CL=35465
parent 093af4e5
This diff is collapsed.
......@@ -147,6 +147,16 @@ func _() {
z = 2;
zzz = 3;
)
// no entry has a value
var (
_ int;
_ float;
_ string;
_ int; // comment
_ float; // comment
_ string; // comment
)
// some entries have a type
var (
xxxxxx int;
......@@ -157,6 +167,14 @@ func _() {
yyyy = "bar";
yyy string = "foo";
)
// mixed entries - all comments should be aligned
var (
a, b, c int;
x = 10;
d int; // comment
y = 20; // comment
f, ff, fff, ffff int = 0, 1, 2, 3; // comment
)
}
func _() {
......@@ -228,6 +246,14 @@ type _ struct {
}
// difficult cases
type _ struct {
bool; // comment
text []byte; // comment
}
// formatting of interfaces
type EI interface{}
......
......@@ -135,7 +135,7 @@ func _() {
yyyyyyyy float = iota;
yyyy = "bar";
yyy;
yy = 2;
yy = 2;
)
}
......@@ -146,6 +146,15 @@ func _() {
z = 2;
zzz = 3;
)
// no entry has a value
var (
_ int;
_ float;
_ string;
_ int; // comment
_ float; // comment
_ string; // comment
)
// some entries have a type
var (
xxxxxx int;
......@@ -156,6 +165,14 @@ func _() {
yyyy = "bar";
yyy string = "foo";
)
// mixed entries - all comments should be aligned
var (
a, b, c int;
x = 10;
d int; // comment
y = 20; // comment
f, ff, fff, ffff int = 0, 1, 2, 3; // comment
)
}
func _() {
......@@ -227,6 +244,13 @@ type _ struct {
}
// difficult cases
type _ struct {
bool; // comment
text []byte; // comment
}
// formatting of interfaces
type EI interface{}
......
......@@ -39,6 +39,8 @@ func _() {
_ = "foo"+s;
_ = s+"foo";
_ = 'a'+'b';
_ = len(s)/2;
_ = len(t0.x)/a;
// spaces around expressions of different precedence or expressions containing spaces
_ = a + -b;
......@@ -80,6 +82,8 @@ func _() {
_ = (a+b+c)*2;
_ = a - b + c - d + (a+b+c) + d&e;
_ = under_bar-1;
_ = Open(dpath + "/file", O_WRONLY | O_CREAT, 0666);
_ = int(c0&_Mask4)<<18 | int(c1&_Maskx)<<12 | int(c2&_Maskx)<<6 | int(c3&_Maskx);
}
......@@ -101,9 +105,63 @@ func _() {
func _() {
// TODO respect source line breaks in multi-line expressions
// do not modify `` strings
_ = ``;
_ = `
`; // TODO(gri): fix line breaks here
_ = `foo
bar`;
}
func _() {
// not not add extra indentation to multi-line string lists
_ = "foo" "bar";
_ = "foo"
"bar"
"bah";
_ = []string {
"abc"
"def",
"foo"
"bar"
}
}
func _() {
// respect source lines in multi-line expressions
_ = a+
b+
c;
_ = a < b ||
b < a;
_ = "1234567890"
"1234567890";
// TODO(gri): add more test cases
// TODO(gri): these comments should be indented
}
func same(t, u *Time) bool {
// respect source lines in multi-line expressions
return t.Year == u.Year
&& t.Month == u.Month
&& t.Day == u.Day
&& t.Hour == u.Hour
&& t.Minute == u.Minute
&& t.Second == u.Second
&& t.Weekday == u.Weekday
&& t.ZoneOffset == u.ZoneOffset
&& t.Zone == u.Zone
}
func (p *parser) charClass() {
// respect source lines in multi-line expressions
if cc.negate && len(cc.ranges) == 2 &&
cc.ranges[0] == '\n' && cc.ranges[1] == '\n' {
nl := new(_NotNl);
p.re.add(nl);
}
}
......@@ -39,6 +39,8 @@ func _() {
_ = "foo"+s;
_ = s+"foo";
_ = 'a'+'b';
_ = len(s)/2;
_ = len(t0.x)/a;
// spaces around expressions of different precedence or expressions containing spaces
_ = a + -b;
......@@ -80,6 +82,8 @@ func _() {
_ = (a+b+c)*2;
_ = a - b + c - d + (a+b+c) + d&e;
_ = under_bar - 1;
_ = Open(dpath+"/file", O_WRONLY|O_CREAT, 0666);
_ = int(c0&_Mask4)<<18 | int(c1&_Maskx)<<12 | int(c2&_Maskx)<<6 | int(c3&_Maskx);
}
......@@ -101,8 +105,65 @@ func _() {
func _() {
// TODO respect source line breaks in multi-line expressions
_ = a < b || b < a;
// do not modify `` strings
_ = ``;
_ = `
`;
// TODO(gri): fix line breaks here
_ = `foo
bar`;
}
func _() {
// not not add extra indentation to multi-line string lists
_ = "foo" "bar";
_ = "foo"
"bar"
"bah";
_ = []string{
"abc"
"def",
"foo"
"bar",
};
}
func _() {
// respect source lines in multi-line expressions
_ = a +
b +
c;
_ = a < b ||
b < a;
_ = "1234567890"
"1234567890";
// TODO(gri): add more test cases
// TODO(gri): these comments should be indented
}
func same(t, u *Time) bool {
// respect source lines in multi-line expressions
return t.Year == u.Year &&
t.Month == u.Month &&
t.Day == u.Day &&
t.Hour == u.Hour &&
t.Minute == u.Minute &&
t.Second == u.Second &&
t.Weekday == u.Weekday &&
t.ZoneOffset == u.ZoneOffset &&
t.Zone == u.Zone;
}
func (p *parser) charClass() {
// respect source lines in multi-line expressions
if cc.negate && len(cc.ranges) == 2 &&
cc.ranges[0] == '\n' && cc.ranges[1] == '\n' {
nl := new(_NotNl);
p.re.add(nl);
}
}
......@@ -175,15 +175,15 @@ var facts = map[int]string{
10: "3628800",
20: "2432902008176640000",
100: "933262154439441526816992388562667004907159682643816214685929"
"638952175999932299156089414639761565182862536979208272237582"
"51185210916864000000000000000000000000",
"638952175999932299156089414639761565182862536979208272237582"
"51185210916864000000000000000000000000",
}
func usage() {
fmt.Fprintf(os.Stderr,
// TODO(gri): the 2nd string of this string list should not be indented
"usage: godoc package [name ...]\n"
" godoc -http=:6060\n");
" godoc -http=:6060\n");
flag.PrintDefaults();
os.Exit(2);
}
......
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