1 // Copyright 2009 The Go Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style
3 // license that can be found in the LICENSE file.
14 longIdentifier1, longIdentifier2, longIdentifier3 int
22 // no spaces around simple or parenthesized expressions
49 // spaces around expressions of different precedence or expressions containing spaces
71 // spaces around operators with equal or lower precedence than comparisons
81 // spaces around "long" operands
82 _ = a + longIdentifier1
83 _ = longIdentifier1 + a
84 _ = longIdentifier1 + longIdentifier2*longIdentifier3
85 _ = s + "a longer string"
87 // some selected cases
89 _ = a + t0.x + t1.x*t2.x
90 _ = a + b + c + d + e + 2*3
91 _ = a + b + c + 2*3 + d + e
93 _ = a - b + c - d + (a + b + c) + d&e
95 _ = Open(dpath+"/file", O_WRONLY|O_CREAT, 0666)
96 _ = int(c0&_Mask4)<<18 | int(c1&_Maskx)<<12 | int(c2&_Maskx)<<6 | int(c3&_Maskx)
120 1<<d.logWindowSize - 1
122 buf = make(x, 2*cap(b.buf)+n)
124 dst[i*3+2] = dbuf[0] << 2
125 dst[i*3+2] = dbuf[0]<<2 | dbuf[1]>>4
127 b.buf = b.buf[0 : b.off+m+n]
128 b.buf = b.buf[0 : b.off+m*n]
129 f(b.buf[0 : b.off+m+n])
132 tw.octal(header[148:155], chksum)
136 x1, x0 := x>>w2, x&m2
138 z1 = (t1 + t0>>w2) >> w2
139 q1, r1 := x1/d1, x1%d1
141 x1 = (x1 << z) | (x0 >> (uint(w) - z))
142 x1 = x1<<z | x0>>(uint(w)-z)
165 b[a>>24] ^ b[(a>>16)&0xFF] ^ b[(a>>8)&0xFF] ^ b[a&0xFF]
166 len(longVariableName) * 2
168 token(matchType + xlength<<lengthShift + xoffset)
172 func f(x int, args ...int) {
177 // make sure syntactically legal code remains syntactically legal
178 f(3, 42 ...) // a blank must remain between 42 and ...
188 _ = 42 .x // a blank must remain between 42 and .x
198 // a blank must remain between the binary operator and the 2nd operand
207 _ = f(x / *y, x < -1, x < <-1, x + +1, x - -1, x & &x, x & ^x)
221 // one-line structs/interfaces in composite literals (up to a threshold)
224 _ = struct{ x int }{0}
225 _ = struct{ x, y, z int }{0, 1, 2}
231 }{struct{ int }{0}} // compositeLit context not propagated => multiLine result
236 // do not modify literals
237 _ = "tab1 tab2 tab3 end" // string contains 3 tabs
238 _ = "tab1 tab2 tab3 end" // same string with 3 blanks - may be unaligned because editors see tabs in strings
239 _ = "" // this comment should be aligned with the one on the previous line
245 _ = `three spaces before the end of the line starting here:
246 they must not be removed`
251 // one-line function literals (body is on a single line)
253 _ = func() int { return 0 }
254 _ = func(x, y int) bool { m := (x + y) / 2; return m < 0 }
256 // multi-line function literals (body is not on one line)
262 _ = func(x, y int) bool {
272 f(func(x, y int) bool {
295 _ = [][]int{{1}, {1, 2}, {1, 2, 3}}
299 // various multi-line expressions
301 // do not add extra indentation to multi-line string lists
318 `datafmt.T2 = s ["-" p "-"];`
321 const _ = `datafmt "datafmt";` +
324 `datafmt.T3 = s {" " a a / ","};`
327 const _ = `datafmt "datafmt";` +
330 `datafmt.T3 = s {" " a a / ","};`
337 `datafmt.T2 = s ["-" p "-"];`
340 `datafmt "datafmt";` +
343 `datafmt.T3 = s {" " a a / ","};`
345 _ = `datafmt "datafmt";` +
348 `datafmt.T3 = s {" " a a / ","};`
353 // respect source lines in multi-line expressions
359 _ = "933262154439441526816992388562667004907159682643816214685929" +
360 "638952175999932299156089414639761565182862536979208272237582" +
361 "51185210916864000000000000000000000000" // 100!
362 _ = "170141183460469231731687303715884105727" // prime
366 // Alignment after overlong lines
369 _ = "2432902008176640000" // 20!
370 _ = "933262154439441526816992388562667004907159682643816214685929" +
371 "638952175999932299156089414639761565182862536979208272237582" +
372 "51185210916864000000000000000000000000" // 100!
373 _ = "170141183460469231731687303715884105727" // prime
377 // Correct placement of operators and comments in multi-line expressions
385 _ = "ba0408" + "7265717569726564" // field 71, encoding 2, string "required"
389 // Correct placement of terminating comma/closing parentheses in multi-line calls.
415 // Align comments in multi-line lists of single-line expressions.
416 var txpix = [NCOL]draw.Color{
417 draw.Yellow, // yellow
419 draw.Green, // lime green
420 draw.GreyBlue, // slate
422 draw.GreyGreen, /* olive green */
423 draw.Blue, /* blue */
424 draw.Color(0xFF55AAFF), /* pink */
425 draw.Color(0xFFAAFFFF), /* lavender */
426 draw.Color(0xBB005DFF), /* maroon */
430 func same(t, u *Time) bool {
431 // respect source lines in multi-line expressions
432 return t.Year == u.Year &&
433 t.Month == u.Month &&
436 t.Minute == u.Minute &&
437 t.Second == u.Second &&
438 t.Weekday == u.Weekday &&
439 t.ZoneOffset == u.ZoneOffset &&
444 func (p *parser) charClass() {
445 // respect source lines in multi-line expressions
446 if cc.negate && len(cc.ranges) == 2 &&
447 cc.ranges[0] == '\n' && cc.ranges[1] == '\n' {
454 func addState(s []state, inst instr, match []int) {
455 // handle comments correctly in multi-line expressions
456 for i := 0; i < l; i++ {
457 if s[i].inst.index() == index && // same instruction
458 s[i].match[0] < pos { // earlier match already going; leftmost wins
464 func (self *T) foo(x int) *T { return self }
466 func _() { module.Func1().Func2() }
476 foo(2). // inline comments
479 _ = new(T).foo(1).foo(2).foo(3)
481 // handle multiline argument list correctly