LEFT | RIGHT |
1 // Copyright 2009 The Go Authors. All rights reserved. | 1 // Copyright 2009 The Go Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style | 2 // Use of this source code is governed by a BSD-style |
3 // license that can be found in the LICENSE file. | 3 // license that can be found in the LICENSE file. |
4 | 4 |
5 package main | 5 package main |
6 | 6 |
7 import ( | 7 import ( |
8 "bytes" | 8 "bytes" |
9 "flag" | 9 "flag" |
10 "fmt" | 10 "fmt" |
11 "go/ast" | 11 "go/ast" |
12 "go/parser" | 12 "go/parser" |
13 "go/printer" | 13 "go/printer" |
14 "go/scanner" | 14 "go/scanner" |
15 "io/ioutil" | 15 "io/ioutil" |
16 "os" | 16 "os" |
17 pathutil "path" | 17 pathutil "path" |
18 "strings" | 18 "strings" |
19 ) | 19 ) |
20 | 20 |
21 | 21 |
22 var ( | 22 var ( |
23 // main operation modes | 23 // main operation modes |
24 list = flag.Bool("l", false, "list files whose formatting differs
from gofmt's") | 24 list = flag.Bool("l", false, "list files whose formatting differs
from gofmt's") |
25 write = flag.Bool("w", false, "write result to (source) file inste
ad of stdout") | 25 write = flag.Bool("w", false, "write result to (source) file inste
ad of stdout") |
26 rewriteRule = flag.String("r", "", "rewrite rule (e.g., 'α[β:len(α)] ->
α[β:]')") | 26 rewriteRule = flag.String("r", "", "rewrite rule (e.g., 'α[β:len(α)] ->
α[β:]')") |
27 » simplifyAST = flag.Bool("s", false, "simplify source by removing some re
dundent code") | 27 » simplifyAST = flag.Bool("s", false, "simplify code") |
28 | 28 |
29 // debugging support | 29 // debugging support |
30 comments = flag.Bool("comments", true, "print comments") | 30 comments = flag.Bool("comments", true, "print comments") |
31 trace = flag.Bool("trace", false, "print parse trace") | 31 trace = flag.Bool("trace", false, "print parse trace") |
32 printAST = flag.Bool("ast", false, "print AST (before rewrites)") | 32 printAST = flag.Bool("ast", false, "print AST (before rewrites)") |
33 | 33 |
34 // layout control | 34 // layout control |
35 tabWidth = flag.Int("tabwidth", 8, "tab width") | 35 tabWidth = flag.Int("tabwidth", 8, "tab width") |
36 tabIndent = flag.Bool("tabindent", true, "indent with tabs independent o
f -spaces") | 36 tabIndent = flag.Bool("tabindent", true, "indent with tabs independent o
f -spaces") |
37 useSpaces = flag.Bool("spaces", true, "align with spaces instead of tabs
") | 37 useSpaces = flag.Bool("spaces", true, "align with spaces instead of tabs
") |
(...skipping 173 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
211 if err := processFileByName(path); err != nil { | 211 if err := processFileByName(path); err != nil { |
212 report(err) | 212 report(err) |
213 } | 213 } |
214 case dir.IsDirectory(): | 214 case dir.IsDirectory(): |
215 walkDir(path) | 215 walkDir(path) |
216 } | 216 } |
217 } | 217 } |
218 | 218 |
219 os.Exit(exitCode) | 219 os.Exit(exitCode) |
220 } | 220 } |
LEFT | RIGHT |