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
21 // no spaces around simple or parenthesized expressions
48 // spaces around expressions of different precedence or expressions containing spaces
70 // spaces around operators with equal or lower precedence than comparisons
80 // spaces around "long" operands
81 _ = a + longIdentifier1
82 _ = longIdentifier1 + a
83 _ = longIdentifier1 + longIdentifier2*longIdentifier3
84 _ = s + "a longer string"
86 // some selected cases
88 _ = a + t0.x + t1.x*t2.x
89 _ = a + b + c + d + e + 2*3
90 _ = a + b + c + 2*3 + d + e
92 _ = a - b + c - d + (a + b + c) + d&e
94 _ = Open(dpath+"/file", O_WRONLY|O_CREAT, 0666)
95 _ = int(c0&_Mask4)<<18 | int(c1&_Maskx)<<12 | int(c2&_Maskx)<<6 | int(c3&_Maskx)
97 // the parser does not restrict expressions that may appear as statements
135 _ = f(1<<x-1, 1<<x-2)
137 _ = 1<<d.logWindowSize - 1
139 buf = make(x, 2*cap(b.buf)+n)
141 dst[i*3+2] = dbuf[0] << 2
142 dst[i*3+2] = dbuf[0]<<2 | dbuf[1]>>4
144 b.buf = b.buf[0 : b.off+m+n]
145 b.buf = b.buf[0 : b.off+m*n]
146 f(b.buf[0 : b.off+m+n])
149 tw.octal(header[148:155], chksum)
153 x1, x0 := x>>w2, x&m2
155 z1 = (t1 + t0>>w2) >> w2
156 q1, r1 := x1/d1, x1%d1
158 x1 = (x1 << z) | (x0 >> (uint(w) - z))
159 x1 = x1<<z | x0>>(uint(w)-z)
161 _ = buf[0 : len(buf)+1]
182 _ = b[a>>24] ^ b[(a>>16)&0xFF] ^ b[(a>>8)&0xFF] ^ b[a&0xFF]
183 _ = len(longVariableName) * 2
185 _ = token(matchType + xlength<<lengthShift + xoffset)
188 func f(x int, args ...int) {
193 // make sure syntactically legal code remains syntactically legal
194 f(3, 42 ...) // a blank must remain between 42 and ...
204 _ = 42 .x // a blank must remain between 42 and .x
214 // a blank must remain between the binary operator and the 2nd operand
223 _ = f(x / *y, x < -1, x < <-1, x + +1, x - -1, x & &x, x & ^x)
235 // one-line structs/interfaces in composite literals (up to a threshold)
238 _ = struct{ x int }{0}
239 _ = struct{ x, y, z int }{0, 1, 2}
241 _ = struct{ s struct{ int } }{struct{ int }{0}}
245 // do not modify literals
246 _ = "tab1 tab2 tab3 end" // string contains 3 tabs
247 _ = "tab1 tab2 tab3 end" // same string with 3 blanks - may be unaligned because editors see tabs in strings
248 _ = "" // this comment should be aligned with the one on the previous line
254 _ = `three spaces before the end of the line starting here:
255 they must not be removed`
259 // smart handling of indentation for multi-line raw strings
268 // the next line should remain indented
277 // the next line should remain indented
281 var _ = /* comment */ ``
282 var _ = /* comment */ `foo`
283 var _ = /* comment */ `foo
286 var _ = /* comment */
288 var _ = /* comment */
290 var _ = /* comment */
291 // the next line should remain indented
311 // the next line should remain indented
329 // one-line function literals (body is on a single line)
331 _ = func() int { return 0 }
332 _ = func(x, y int) bool { m := (x + y) / 2; return m < 0 }
334 // multi-line function literals (body is not on one line)
340 _ = func(x, y int) bool {
350 f(func(x, y int) bool {
372 _ = [][]int{{1}, {1, 2}, {1, 2, 3}}
375 // various multi-line expressions
377 // do not add extra indentation to multi-line string lists
393 `datafmt.T2 = s ["-" p "-"];`
395 const _ = `datafmt "datafmt";` +
398 `datafmt.T3 = s {" " a a / ","};`
400 const _ = `datafmt "datafmt";` +
403 `datafmt.T3 = s {" " a a / ","};`
409 `datafmt.T2 = s ["-" p "-"];`
412 `datafmt "datafmt";` +
415 `datafmt.T3 = s {" " a a / ","};`
417 _ = `datafmt "datafmt";` +
420 `datafmt.T3 = s {" " a a / ","};`
424 // respect source lines in multi-line expressions
430 _ = "933262154439441526816992388562667004907159682643816214685929" +
431 "638952175999932299156089414639761565182862536979208272237582" +
432 "51185210916864000000000000000000000000" // 100!
433 _ = "170141183460469231731687303715884105727" // prime
436 // Alignment after overlong lines
439 _ = "2432902008176640000" // 20!
440 _ = "933262154439441526816992388562667004907159682643816214685929" +
441 "638952175999932299156089414639761565182862536979208272237582" +
442 "51185210916864000000000000000000000000" // 100!
443 _ = "170141183460469231731687303715884105727" // prime
446 // Correct placement of operators and comments in multi-line expressions
454 _ = "ba0408" + "7265717569726564" // field 71, encoding 2, string "required"
457 // Correct placement of terminating comma/closing parentheses in multi-line calls.
482 // Align comments in multi-line lists of single-line expressions.
483 var txpix = [NCOL]draw.Color{
484 draw.Yellow, // yellow
486 draw.Green, // lime green
487 draw.GreyBlue, // slate
489 draw.GreyGreen, /* olive green */
490 draw.Blue, /* blue */
491 draw.Color(0xFF55AAFF), /* pink */
492 draw.Color(0xFFAAFFFF), /* lavender */
493 draw.Color(0xBB005DFF), /* maroon */
496 func same(t, u *Time) bool {
497 // respect source lines in multi-line expressions
498 return t.Year == u.Year &&
499 t.Month == u.Month &&
502 t.Minute == u.Minute &&
503 t.Second == u.Second &&
504 t.Weekday == u.Weekday &&
505 t.ZoneOffset == u.ZoneOffset &&
509 func (p *parser) charClass() {
510 // respect source lines in multi-line expressions
511 if cc.negate && len(cc.ranges) == 2 &&
512 cc.ranges[0] == '\n' && cc.ranges[1] == '\n' {
518 func addState(s []state, inst instr, match []int) {
519 // handle comments correctly in multi-line expressions
520 for i := 0; i < l; i++ {
521 if s[i].inst.index() == index && // same instruction
522 s[i].match[0] < pos { // earlier match already going; leftmost wins
528 func (self *T) foo(x int) *T { return self }
530 func _() { module.Func1().Func2() }
540 foo(2). // inline comments
543 _ = new(T).foo(1).foo(2).foo(3)
545 // handle multiline argument list correctly
620 // Don't introduce extra newlines in strangely formatted expression lists.
622 // os.Open parameters should remain on two lines
623 if writer, err = os.Open(outfile, s.O_WRONLY|os.O_CREATE|
624 os.O_TRUNC, 0666); err != nil {
629 // Handle multi-line argument lists ending in ... correctly.
651 // Literal function types in conversions must be parenthesized;
652 // for now go/parser accepts the unparenthesized form where it
655 // these conversions should be rewritten to look
656 // the same as the parenthesized conversions below
658 _ = (func(x int) float)(nil)
659 _ = (func() func() func())(nil)
662 _ = (func(x int) float)(nil)
663 _ = (func() func() func())(nil)