]> Cypherpunks repositories - gostls13.git/commitdiff
gofmt: preserve syntactically relevant blanks between ints and tokens that start...
authorRobert Griesemer <gri@golang.org>
Thu, 23 Sep 2010 21:56:44 +0000 (14:56 -0700)
committerRobert Griesemer <gri@golang.org>
Thu, 23 Sep 2010 21:56:44 +0000 (14:56 -0700)
R=rsc
CC=golang-dev
https://golang.org/cl/2270042

src/pkg/go/printer/nodes.go
src/pkg/go/printer/printer.go
src/pkg/go/printer/testdata/expressions.golden
src/pkg/go/printer/testdata/expressions.input
src/pkg/go/printer/testdata/expressions.raw

index 4650df6448d9ed4266d6b5b00b48eda6aa8343bb..2451116fdb64f39e77d2d195c03f6051d88e47d2 100644 (file)
@@ -848,14 +848,6 @@ func (p *printer) expr1(expr ast.Expr, prec1, depth int, ctxt exprContext, multi
                p.print(x.Lparen, token.LPAREN)
                p.exprList(x.Lparen, x.Args, depth, commaSep|commaTerm, multiLine, x.Rparen)
                if x.Ellipsis.IsValid() {
-                       if p.lastTok == token.INT {
-                               // w/o a blank, the previous int will become a float
-                               // (this could be solved more generally in the print
-                               // function but it appears that this is the only
-                               // place in the grammar where a token starting with
-                               // a do may legally extend the previous token)
-                               p.print(blank)
-                       }
                        p.print(x.Ellipsis, token.ELLIPSIS)
                }
                p.print(x.Rparen, token.RPAREN)
index bb87b9f58c531ca4ff50b04ece4bb1b4925a6beb..3e6299da77a409c8509461cd1199066b401c41b9 100644 (file)
@@ -802,10 +802,19 @@ func (p *printer) print(args ...interface{}) {
                        data = []byte("\xff" + string(data) + "\xff")
                        tok = x.Kind
                case token.Token:
+                       s := x.String()
+                       if p.lastTok == token.INT && s[0] == '.' {
+                               // separate int with blank from '.' so it doesn't become a float
+                               if len(p.buffer) != 0 {
+                                       p.internalError("whitespace buffer not empty")
+                               }
+                               p.buffer = p.buffer[0:1]
+                               p.buffer[0] = ' '
+                       }
                        if p.Styler != nil {
                                data, tag = p.Styler.Token(x)
                        } else {
-                               data = []byte(x.String())
+                               data = []byte(s)
                        }
                        tok = x
                case token.Position:
index c828dbe675f018c9a7103ce4b1c89c39388c3c37..02bae49b48d5788944ca746fe07ea29edada3dc8 100644 (file)
@@ -184,6 +184,16 @@ func f(x int, args ...int) {
        f(9, .42...)
        f(10, 42e0...)
        f(11, 42e0...)
+
+       _ = 42 .x       // a blank must remain between 42 and .x
+       _ = 42..x
+       _ = 42..x
+       _ = 42.0.x
+       _ = 42.0.x
+       _ = .42.x
+       _ = .42.x
+       _ = 42e0.x
+       _ = 42e0.x
 }
 
 
index 06e17a666263a3e352cffaeebe2310cde441f945..7d5889b064bc6200bc1fb9e66bc39e5857dae925 100644 (file)
@@ -184,6 +184,16 @@ func f(x int, args ...int) {
        f(9, .42...)
        f(10, 42e0 ...)
        f(11, 42e0...)
+
+       _ = 42 .x // a blank must remain between 42 and .x
+       _ = 42. .x
+       _ = 42..x
+       _ = 42.0 .x
+       _ = 42.0.x
+       _ = .42 .x
+       _ = .42.x
+       _ = 42e0 .x
+       _ = 42e0.x
 }
 
 
index 56ec39b96839871664053fa14bf487891387a80c..9e83892e87b6da09bc6f6373d0ba083ff893b5af 100644 (file)
@@ -184,6 +184,16 @@ func f(x int, args ...int) {
        f(9, .42...)
        f(10, 42e0...)
        f(11, 42e0...)
+
+       _ = 42 .x       // a blank must remain between 42 and .x
+       _ = 42..x
+       _ = 42..x
+       _ = 42.0.x
+       _ = 42.0.x
+       _ = .42.x
+       _ = .42.x
+       _ = 42e0.x
+       _ = 42e0.x
 }