Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in
Toggle navigation
G
golang
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Commits
Issue Boards
Open sidebar
go
golang
Commits
0716d950
Commit
0716d950
authored
Sep 23, 2010
by
Robert Griesemer
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
gofmt: don't remove syntactically relevant blank in f(42 ...)
R=rsc CC=golang-dev
https://golang.org/cl/2246046
parent
f3549d83
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
50 additions
and
5 deletions
+50
-5
nodes.go
src/pkg/go/printer/nodes.go
+8
-0
printer.go
src/pkg/go/printer/printer.go
+9
-5
expressions.golden
src/pkg/go/printer/testdata/expressions.golden
+11
-0
expressions.input
src/pkg/go/printer/testdata/expressions.input
+11
-0
expressions.raw
src/pkg/go/printer/testdata/expressions.raw
+11
-0
No files found.
src/pkg/go/printer/nodes.go
View file @
0716d950
...
@@ -848,6 +848,14 @@ func (p *printer) expr1(expr ast.Expr, prec1, depth int, ctxt exprContext, multi
...
@@ -848,6 +848,14 @@ 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
)
...
...
src/pkg/go/printer/printer.go
View file @
0716d950
...
@@ -65,10 +65,11 @@ type printer struct {
...
@@ -65,10 +65,11 @@ type printer struct {
errors
chan
os
.
Error
errors
chan
os
.
Error
// Current state
// Current state
nesting
int
// nesting level (0: top-level (package scope), >0: functions/decls.)
nesting
int
// nesting level (0: top-level (package scope), >0: functions/decls.)
written
int
// number of bytes written
written
int
// number of bytes written
indent
int
// current indentation
indent
int
// current indentation
escape
bool
// true if in escape sequence
escape
bool
// true if in escape sequence
lastTok
token
.
Token
// the last token printed (token.ILLEGAL if it's whitespace)
// Buffered whitespace
// Buffered whitespace
buffer
[]
whiteSpace
buffer
[]
whiteSpace
...
@@ -762,6 +763,7 @@ func (p *printer) print(args ...interface{}) {
...
@@ -762,6 +763,7 @@ func (p *printer) print(args ...interface{}) {
var
data
[]
byte
var
data
[]
byte
var
tag
HTMLTag
var
tag
HTMLTag
var
tok
token
.
Token
var
tok
token
.
Token
switch
x
:=
f
.
(
type
)
{
switch
x
:=
f
.
(
type
)
{
case
whiteSpace
:
case
whiteSpace
:
if
x
==
ignore
{
if
x
==
ignore
{
...
@@ -798,7 +800,7 @@ func (p *printer) print(args ...interface{}) {
...
@@ -798,7 +800,7 @@ func (p *printer) print(args ...interface{}) {
// bytes since they do not appear in legal UTF-8 sequences)
// bytes since they do not appear in legal UTF-8 sequences)
// TODO(gri): do this more efficiently.
// TODO(gri): do this more efficiently.
data
=
[]
byte
(
"
\xff
"
+
string
(
data
)
+
"
\xff
"
)
data
=
[]
byte
(
"
\xff
"
+
string
(
data
)
+
"
\xff
"
)
tok
=
token
.
INT
// representing all literal tokens
tok
=
x
.
Kind
case
token
.
Token
:
case
token
.
Token
:
if
p
.
Styler
!=
nil
{
if
p
.
Styler
!=
nil
{
data
,
tag
=
p
.
Styler
.
Token
(
x
)
data
,
tag
=
p
.
Styler
.
Token
(
x
)
...
@@ -810,10 +812,12 @@ func (p *printer) print(args ...interface{}) {
...
@@ -810,10 +812,12 @@ func (p *printer) print(args ...interface{}) {
if
x
.
IsValid
()
{
if
x
.
IsValid
()
{
next
=
x
// accurate position of next item
next
=
x
// accurate position of next item
}
}
tok
=
p
.
lastTok
default
:
default
:
fmt
.
Fprintf
(
os
.
Stderr
,
"print: unsupported argument type %T
\n
"
,
f
)
fmt
.
Fprintf
(
os
.
Stderr
,
"print: unsupported argument type %T
\n
"
,
f
)
panic
(
"go/printer type"
)
panic
(
"go/printer type"
)
}
}
p
.
lastTok
=
tok
p
.
pos
=
next
p
.
pos
=
next
if
data
!=
nil
{
if
data
!=
nil
{
...
...
src/pkg/go/printer/testdata/expressions.golden
View file @
0716d950
...
@@ -173,6 +173,17 @@ func f(x int, args ...int) {
...
@@ -173,6 +173,17 @@ func f(x int, args ...int) {
f
(
0
,
args
...)
f
(
0
,
args
...)
f
(
1
,
args
)
f
(
1
,
args
)
f
(
2
,
args
[
0
])
f
(
2
,
args
[
0
])
//
make
sure
syntactically
legal
code
remains
syntactically
legal
f
(
3
,
42
...)
//
a
blank
must
remain
between
42
and
...
f
(
4
,
42.
...)
f
(
5
,
42.
...)
f
(
6
,
42.0
...)
f
(
7
,
42.0
...)
f
(
8
,
.42
...)
f
(
9
,
.42
...)
f
(
10
,
42e0
...)
f
(
11
,
42e0
...)
}
}
...
...
src/pkg/go/printer/testdata/expressions.input
View file @
0716d950
...
@@ -173,6 +173,17 @@ func f(x int, args ...int) {
...
@@ -173,6 +173,17 @@ func f(x int, args ...int) {
f
(
0
,
args
...)
f
(
0
,
args
...)
f
(
1
,
args
)
f
(
1
,
args
)
f
(
2
,
args
[
0
])
f
(
2
,
args
[
0
])
//
make
sure
syntactically
legal
code
remains
syntactically
legal
f
(
3
,
42
...)
//
a
blank
must
remain
between
42
and
...
f
(
4
,
42.
...)
f
(
5
,
42.
...)
f
(
6
,
42.0
...)
f
(
7
,
42.0
...)
f
(
8
,
.42
...)
f
(
9
,
.42
...)
f
(
10
,
42e0
...)
f
(
11
,
42e0
...)
}
}
...
...
src/pkg/go/printer/testdata/expressions.raw
View file @
0716d950
...
@@ -173,6 +173,17 @@ func f(x int, args ...int) {
...
@@ -173,6 +173,17 @@ func f(x int, args ...int) {
f
(
0
,
args
...)
f
(
0
,
args
...)
f
(
1
,
args
)
f
(
1
,
args
)
f
(
2
,
args
[
0
])
f
(
2
,
args
[
0
])
//
make
sure
syntactically
legal
code
remains
syntactically
legal
f
(
3
,
42
...)
//
a
blank
must
remain
between
42
and
...
f
(
4
,
42.
...)
f
(
5
,
42.
...)
f
(
6
,
42.0
...)
f
(
7
,
42.0
...)
f
(
8
,
.42
...)
f
(
9
,
.42
...)
f
(
10
,
42e0
...)
f
(
11
,
42e0
...)
}
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment