Commit 44b3b205 authored by Robert Griesemer's avatar Robert Griesemer

gofmt: preserve syntactically relevant blanks between ints and tokens that...

gofmt: preserve syntactically relevant blanks between ints and tokens that start with a '.' (2nd attempt)

R=rsc
CC=golang-dev
https://golang.org/cl/2270042
parent 0716d950
...@@ -848,14 +848,6 @@ func (p *printer) expr1(expr ast.Expr, prec1, depth int, ctxt exprContext, multi ...@@ -848,14 +848,6 @@ func (p *printer) expr1(expr ast.Expr, prec1, depth int, ctxt exprContext, multi
p.print(x.Lparen, token.LPAREN) p.print(x.Lparen, token.LPAREN)
p.exprList(x.Lparen, x.Args, depth, commaSep|commaTerm, multiLine, x.Rparen) p.exprList(x.Lparen, x.Args, depth, commaSep|commaTerm, multiLine, x.Rparen)
if x.Ellipsis.IsValid() { 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.Ellipsis, token.ELLIPSIS)
} }
p.print(x.Rparen, token.RPAREN) p.print(x.Rparen, token.RPAREN)
......
...@@ -802,10 +802,19 @@ func (p *printer) print(args ...interface{}) { ...@@ -802,10 +802,19 @@ func (p *printer) print(args ...interface{}) {
data = []byte("\xff" + string(data) + "\xff") data = []byte("\xff" + string(data) + "\xff")
tok = x.Kind tok = x.Kind
case token.Token: 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 { if p.Styler != nil {
data, tag = p.Styler.Token(x) data, tag = p.Styler.Token(x)
} else { } else {
data = []byte(x.String()) data = []byte(s)
} }
tok = x tok = x
case token.Position: case token.Position:
......
...@@ -184,6 +184,16 @@ func f(x int, args ...int) { ...@@ -184,6 +184,16 @@ func f(x int, args ...int) {
f(9, .42...) f(9, .42...)
f(10, 42e0...) f(10, 42e0...)
f(11, 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
} }
......
...@@ -184,6 +184,16 @@ func f(x int, args ...int) { ...@@ -184,6 +184,16 @@ func f(x int, args ...int) {
f(9, .42...) f(9, .42...)
f(10, 42e0 ...) f(10, 42e0 ...)
f(11, 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
} }
......
...@@ -184,6 +184,16 @@ func f(x int, args ...int) { ...@@ -184,6 +184,16 @@ func f(x int, args ...int) {
f(9, .42...) f(9, .42...)
f(10, 42e0...) f(10, 42e0...)
f(11, 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
} }
......
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