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
b32f22b3
Commit
b32f22b3
authored
Mar 15, 2010
by
Robert Griesemer
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
gofmt: fix for gofmt rewrite feature
Fixes #643. R=rsc CC=golang-dev
https://golang.org/cl/576041
parent
6129dbbe
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
15 additions
and
5 deletions
+15
-5
doc.go
src/cmd/gofmt/doc.go
+2
-2
rewrite.go
src/cmd/gofmt/rewrite.go
+13
-3
No files found.
src/cmd/gofmt/doc.go
View file @
b32f22b3
...
...
@@ -41,8 +41,8 @@ The rewrite rule specified with the -r flag must be a string of the form:
pattern -> replacement
Both pattern and replacement must be valid Go expressions.
In the pattern, single-character lowercase identifers serve as
wildcards matching arbitrary subexpressions; those expressions
In the pattern, single-character lowercase identif
i
ers serve as
wildcards matching arbitrary sub
-
expressions; those expressions
will be substituted for the same identifiers in the replacement.
...
...
src/cmd/gofmt/rewrite.go
View file @
b32f22b3
...
...
@@ -46,7 +46,7 @@ func parseExpr(s string, what string) ast.Expr {
}
// rewriteFile appl
ys the rewrite rule pattern -> replace
to an entire file.
// rewriteFile appl
ies the rewrite rule 'pattern -> replace'
to an entire file.
func
rewriteFile
(
pattern
,
replace
ast
.
Expr
,
p
*
ast
.
File
)
*
ast
.
File
{
m
:=
make
(
map
[
string
]
reflect
.
Value
)
pat
:=
reflect
.
NewValue
(
pattern
)
...
...
@@ -127,9 +127,19 @@ func match(m map[string]reflect.Value, pattern, val reflect.Value) bool {
return
false
}
// Token positions need not match.
if
pattern
.
Type
()
==
positionType
{
// Special cases.
switch
pattern
.
Type
()
{
case
positionType
:
// token positions don't need to match
return
true
case
identType
:
// For identifiers, only the names need to match
// (and none of the other *ast.Object information).
// This is a common case, handle it all here instead
// of recursing down any further via reflection.
p
:=
pattern
.
Interface
()
.
(
*
ast
.
Ident
)
v
:=
val
.
Interface
()
.
(
*
ast
.
Ident
)
return
p
==
nil
&&
v
==
nil
||
p
!=
nil
&&
v
!=
nil
&&
p
.
Name
()
==
v
.
Name
()
}
p
:=
reflect
.
Indirect
(
pattern
)
...
...
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