Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code | Sign in
(1740)

Delta Between Two Patch Sets: src/cmd/gofmt/gofmt.go

Issue 174051: code review 174051: New flags for gofmt: (Closed)
Left Patch Set: code review 174051: New flags for gofmt: Created 15 years, 3 months ago
Right Patch Set: code review 174051: New flags for gofmt: Created 15 years, 3 months ago
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments. Please Sign in to add in-line comments.
Jump to:
Left: Side by side diff | Download
Right: Side by side diff | Download
« no previous file with change/comment | « src/cmd/gofmt/doc.go ('k') | src/pkg/Makefile » ('j') | no next file with change/comment »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
LEFTRIGHT
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 oldParser "exp/parser"; 9 oldParser "exp/parser";
10 "flag"; 10 "flag";
(...skipping 18 matching lines...) Expand all
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 32
33 // layout control 33 // layout control
34 tabWidth = flag.Int("tabwidth", 8, "tab width"); 34 tabWidth = flag.Int("tabwidth", 8, "tab width");
35 tabIndent = flag.Bool("tabindent", false, "indent with tabs indepe ndent of -spaces"); 35 tabIndent = flag.Bool("tabindent", false, "indent with tabs indepe ndent of -spaces");
36 useSpaces = flag.Bool("spaces", false, "align with spaces instead of tabs"); 36 useSpaces = flag.Bool("spaces", false, "align with spaces instead of tabs");
37 37
38 // semicolon transition 38 // semicolon transition
39 » insertSemis» » = flag.Bool("insertsemis", false, "accept automa tically inserted semicolons"); 39 » useOldParser» = flag.Bool("oldparser", true, "parse old syntax (requir ed semicolons)");
rsc 2009/12/10 23:53:33 It's not clear to me (just looking at the name) wh
40 » printNoSemis» » = flag.Bool("printnosemis", false, "don't print semicolons that can be left away"); 40 » useOldPrinter» = flag.Bool("oldprinter", true, "print old syntax (requi red semicolons)");
41 » printNoStringConcat» = flag.Bool("printnostringconcat", false, "don't print string lists without '+'");
42 ) 41 )
43 42
44 43
45 var ( 44 var (
46 exitCode = 0; 45 exitCode = 0;
47 rewrite func(*ast.File) *ast.File; 46 rewrite func(*ast.File) *ast.File;
48 parserMode uint; 47 parserMode uint;
49 printerMode uint; 48 printerMode uint;
50 ) 49 )
51 50
(...skipping 16 matching lines...) Expand all
68 if *comments { 67 if *comments {
69 parserMode |= parser.ParseComments 68 parserMode |= parser.ParseComments
70 } 69 }
71 if *trace { 70 if *trace {
72 parserMode |= parser.Trace 71 parserMode |= parser.Trace
73 } 72 }
74 } 73 }
75 74
76 75
77 func initPrinterMode() { 76 func initPrinterMode() {
78 » printerMode = uint(0); 77 » printerMode = printer.NoStringConcat;
79 if *tabIndent { 78 if *tabIndent {
80 printerMode |= printer.TabIndent 79 printerMode |= printer.TabIndent
81 } 80 }
82 if *useSpaces { 81 if *useSpaces {
83 printerMode |= printer.UseSpaces 82 printerMode |= printer.UseSpaces
84 } 83 }
85 » if *printNoSemis { 84 » if !*useOldPrinter {
86 printerMode |= printer.NoSemis 85 printerMode |= printer.NoSemis
87 }
88 if *printNoStringConcat {
89 printerMode |= printer.NoStringConcat
90 } 86 }
91 } 87 }
92 88
93 89
94 func isGoFile(d *os.Dir) bool { 90 func isGoFile(d *os.Dir) bool {
95 // ignore non-Go files 91 // ignore non-Go files
96 return d.IsRegular() && !strings.HasPrefix(d.Name, ".") && strings.HasSu ffix(d.Name, ".go") 92 return d.IsRegular() && !strings.HasPrefix(d.Name, ".") && strings.HasSu ffix(d.Name, ".go")
97 } 93 }
98 94
99 95
100 func processFile(f *os.File) os.Error { 96 func processFile(f *os.File) os.Error {
101 src, err := ioutil.ReadAll(f); 97 src, err := ioutil.ReadAll(f);
102 if err != nil { 98 if err != nil {
103 return err 99 return err
104 } 100 }
105 101
106 var file *ast.File; 102 var file *ast.File;
107 » if *insertSemis { 103 » if *useOldParser {
104 » » file, err = oldParser.ParseFile(f.Name(), src, parserMode)
105 » } else {
108 file, err = parser.ParseFile(f.Name(), src, parserMode) 106 file, err = parser.ParseFile(f.Name(), src, parserMode)
109 } else {
110 file, err = oldParser.ParseFile(f.Name(), src, parserMode)
111 } 107 }
112 if err != nil { 108 if err != nil {
113 return err 109 return err
114 } 110 }
115 111
116 if rewrite != nil { 112 if rewrite != nil {
117 file = rewrite(file) 113 file = rewrite(file)
118 } 114 }
119 115
120 var res bytes.Buffer; 116 var res bytes.Buffer;
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after
217 if err := processFileByName(path); err != nil { 213 if err := processFileByName(path); err != nil {
218 report(err) 214 report(err)
219 } 215 }
220 case dir.IsDirectory(): 216 case dir.IsDirectory():
221 walkDir(path) 217 walkDir(path)
222 } 218 }
223 } 219 }
224 220
225 os.Exit(exitCode); 221 os.Exit(exitCode);
226 } 222 }
LEFTRIGHT

Powered by Google App Engine
RSS Feeds Recent Issues | This issue
This is Rietveld f62528b