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
42 _ = s[0] << 2 | s[1] >> 4
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)
98 // the parser does not restrict expressions that may appear as statements
137 _ = f(1<<x-1, 1<<x-2)
139 _ = 1<<d.logWindowSize-1
141 buf = make(x, 2*cap(b.buf) + n)
143 dst[i*3+2] = dbuf[0]<<2
144 dst[i*3+2] = dbuf[0]<<2 | dbuf[1]>>4
146 b.buf = b.buf[0:b.off+m+n]
147 b.buf = b.buf[0:b.off+m*n]
148 f(b.buf[0:b.off+m+n])
151 tw.octal(header[148:155], chksum)
155 x1, x0 := x>>w2, x&m2
158 q1, r1 := x1/d1, x1%d1
160 x1 = (x1<<z)|(x0>>(uint(w)-z))
161 x1 = x1<<z | x0>>(uint(w)-z)
163 _ = buf[0:len(buf)+1]
184 _ = b[a>>24] ^ b[(a>>16)&0xFF] ^ b[(a>>8)&0xFF] ^ b[a&0xFF]
185 _ = len(longVariableName)*2
187 _ = token(matchType + xlength<<lengthShift + xoffset)
191 func f(x int, args ...int) {
196 // make sure syntactically legal code remains syntactically legal
197 f(3, 42 ...) // a blank must remain between 42 and ...
207 _ = 42 .x // a blank must remain between 42 and .x
217 // a blank must remain between the binary operator and the 2nd operand
226 _ = f(x/ *y, x< -1, x< <-1, x+ +1, x- -1, x& &x, x& ^x)
240 // one-line structs/interfaces in composite literals (up to a threshold)
243 _ = struct{ x int }{0}
244 _ = struct{ x, y, z int }{0, 1, 2}
246 _ = struct{ s struct { int } }{struct{ int}{0} }
251 // do not modify literals
252 _ = "tab1 tab2 tab3 end" // string contains 3 tabs
253 _ = "tab1 tab2 tab3 end" // same string with 3 blanks - may be unaligned because editors see tabs in strings
254 _ = "" // this comment should be aligned with the one on the previous line
260 _ = `three spaces before the end of the line starting here:
261 they must not be removed`
266 // smart handling of indentation for multi-line raw strings
278 // the next line should remain indented
288 // the next line should remain indented
293 var _ = /* comment */ ``
294 var _ = /* comment */ `foo`
295 var _ = /* comment */ `foo
299 var _ = /* comment */
301 var _ = /* comment */
303 var _ = /* comment */
304 // the next line should remain indented
326 // the next line should remain indented
345 // one-line function literals (body is on a single line)
347 _ = func() int { return 0 }
348 _ = func(x, y int) bool { m := (x+y)/2; return m < 0 }
350 // multi-line function literals (body is not on one line)
356 _ = func(x, y int) bool {
357 m := (x+y)/2; return x < y }
364 f(func(x, y int) bool {
365 m := (x+y)/2; return x < y })
385 _ = [][]int {{1}, {1, 2}, {1, 2, 3}}
389 // various multi-line expressions
391 // do not add extra indentation to multi-line string lists
408 `datafmt.T2 = s ["-" p "-"];`
412 `datafmt "datafmt";` +
415 `datafmt.T3 = s {" " a a / ","};`
418 const _ = `datafmt "datafmt";` +
421 `datafmt.T3 = s {" " a a / ","};`
428 `datafmt.T2 = s ["-" p "-"];`
431 `datafmt "datafmt";` +
434 `datafmt.T3 = s {" " a a / ","};`
436 _ = `datafmt "datafmt";` +
439 `datafmt.T3 = s {" " a a / ","};`
444 // respect source lines in multi-line expressions
450 _ = "933262154439441526816992388562667004907159682643816214685929" +
451 "638952175999932299156089414639761565182862536979208272237582" +
452 "51185210916864000000000000000000000000" // 100!
453 _ = "170141183460469231731687303715884105727" // prime
457 // Alignment after overlong lines
460 _ = "2432902008176640000" // 20!
461 _ = "933262154439441526816992388562667004907159682643816214685929" +
462 "638952175999932299156089414639761565182862536979208272237582" +
463 "51185210916864000000000000000000000000" // 100!
464 _ = "170141183460469231731687303715884105727" // prime
468 // Correct placement of operators and comments in multi-line expressions
476 _ = "ba0408" + "7265717569726564" // field 71, encoding 2, string "required"
480 // Correct placement of terminating comma/closing parentheses in multi-line calls.
506 // Align comments in multi-line lists of single-line expressions.
507 var txpix = [NCOL]draw.Color{
508 draw.Yellow, // yellow
510 draw.Green, // lime green
511 draw.GreyBlue, // slate
513 draw.GreyGreen, /* olive green */
514 draw.Blue, /* blue */
515 draw.Color(0xFF55AAFF), /* pink */
516 draw.Color(0xFFAAFFFF), /* lavender */
517 draw.Color(0xBB005DFF), /* maroon */
521 func same(t, u *Time) bool {
522 // respect source lines in multi-line expressions
523 return t.Year == u.Year &&
524 t.Month == u.Month &&
527 t.Minute == u.Minute &&
528 t.Second == u.Second &&
529 t.Weekday == u.Weekday &&
530 t.ZoneOffset == u.ZoneOffset &&
535 func (p *parser) charClass() {
536 // respect source lines in multi-line expressions
537 if cc.negate && len(cc.ranges) == 2 &&
538 cc.ranges[0] == '\n' && cc.ranges[1] == '\n' {
545 func addState(s []state, inst instr, match []int) {
546 // handle comments correctly in multi-line expressions
547 for i := 0; i < l; i++ {
548 if s[i].inst.index() == index && // same instruction
549 s[i].match[0] < pos { // earlier match already going; leftmost wins
555 func (self *T) foo(x int) *T { return self }
557 func _() { module.Func1().Func2() }
567 foo(2). // inline comments
570 _ = new(T).foo(1).foo(2).foo(3)
572 // handle multiline argument list correctly
649 // Don't introduce extra newlines in strangely formatted expression lists.
651 // os.Open parameters should remain on two lines
652 if writer, err = os.Open(outfile, s.O_WRONLY|os.O_CREATE|
653 os.O_TRUNC, 0666); err != nil {
658 // Handle multi-line argument lists ending in ... correctly.