Commit bda20741 authored by Robert Griesemer's avatar Robert Griesemer

New flags for gofmt:

- oldparser            parse old syntax (required semicolons)
- oldprinter           print old syntax (required semicolons)

By default, these flags are enabled for now.
Setting -oldparser=false has no effect until go/parser is changed
to accept the new syntax.

Enabled exp/parser in Makefile; update dependent exp/eval.

R=rsc
https://golang.org/cl/174051
parent 02d41ec7
...@@ -29,6 +29,14 @@ The flags are: ...@@ -29,6 +29,14 @@ The flags are:
-tabwidth=8 -tabwidth=8
tab width in spaces. tab width in spaces.
Flags to aid the transition to the new semicolon-free syntax (these flags will be
removed eventually):
-oldparser=true
parse old syntax (required semicolons).
-oldprinter=true
print old syntax (required semicolons).
Debugging flags: Debugging flags:
-trace -trace
......
...@@ -6,6 +6,7 @@ package main ...@@ -6,6 +6,7 @@ package main
import ( import (
"bytes"; "bytes";
oldParser "exp/parser";
"flag"; "flag";
"fmt"; "fmt";
"go/ast"; "go/ast";
...@@ -30,9 +31,13 @@ var ( ...@@ -30,9 +31,13 @@ var (
trace = flag.Bool("trace", false, "print parse trace"); trace = flag.Bool("trace", false, "print parse trace");
// layout control // layout control
tabwidth = flag.Int("tabwidth", 8, "tab width"); tabWidth = flag.Int("tabwidth", 8, "tab width");
tabindent = flag.Bool("tabindent", false, "indent with tabs independent of -spaces"); tabIndent = flag.Bool("tabindent", false, "indent with tabs independent of -spaces");
usespaces = flag.Bool("spaces", false, "align with spaces instead of tabs"); useSpaces = flag.Bool("spaces", false, "align with spaces instead of tabs");
// semicolon transition
useOldParser = flag.Bool("oldparser", true, "parse old syntax (required semicolons)");
useOldPrinter = flag.Bool("oldprinter", true, "print old syntax (required semicolons)");
) )
...@@ -69,13 +74,16 @@ func initParserMode() { ...@@ -69,13 +74,16 @@ func initParserMode() {
func initPrinterMode() { func initPrinterMode() {
printerMode = uint(0); printerMode = printer.NoStringConcat;
if *tabindent { if *tabIndent {
printerMode |= printer.TabIndent printerMode |= printer.TabIndent
} }
if *usespaces { if *useSpaces {
printerMode |= printer.UseSpaces printerMode |= printer.UseSpaces
} }
if !*useOldPrinter {
printerMode |= printer.NoSemis
}
} }
...@@ -91,7 +99,12 @@ func processFile(f *os.File) os.Error { ...@@ -91,7 +99,12 @@ func processFile(f *os.File) os.Error {
return err return err
} }
file, err := parser.ParseFile(f.Name(), src, parserMode); var file *ast.File;
if *useOldParser {
file, err = oldParser.ParseFile(f.Name(), src, parserMode)
} else {
file, err = parser.ParseFile(f.Name(), src, parserMode)
}
if err != nil { if err != nil {
return err return err
} }
...@@ -101,7 +114,7 @@ func processFile(f *os.File) os.Error { ...@@ -101,7 +114,7 @@ func processFile(f *os.File) os.Error {
} }
var res bytes.Buffer; var res bytes.Buffer;
_, err = (&printer.Config{printerMode, *tabwidth, nil}).Fprint(&res, file); _, err = (&printer.Config{printerMode, *tabWidth, nil}).Fprint(&res, file);
if err != nil { if err != nil {
return err return err
} }
...@@ -176,8 +189,8 @@ func walkDir(path string) { ...@@ -176,8 +189,8 @@ func walkDir(path string) {
func main() { func main() {
flag.Usage = usage; flag.Usage = usage;
flag.Parse(); flag.Parse();
if *tabwidth < 0 { if *tabWidth < 0 {
fmt.Fprintf(os.Stderr, "negative tabwidth %d\n", *tabwidth); fmt.Fprintf(os.Stderr, "negative tabwidth %d\n", *tabWidth);
os.Exit(2); os.Exit(2);
} }
......
...@@ -55,6 +55,7 @@ DIRS=\ ...@@ -55,6 +55,7 @@ DIRS=\
exp/eval\ exp/eval\
exp/exception\ exp/exception\
exp/iterable\ exp/iterable\
exp/parser\
expvar\ expvar\
flag\ flag\
fmt\ fmt\
......
...@@ -9,7 +9,7 @@ package eval ...@@ -9,7 +9,7 @@ package eval
import ( import (
"go/ast"; "go/ast";
"go/parser"; parser "exp/parser";
"go/scanner"; "go/scanner";
"go/token"; "go/token";
"os"; "os";
......
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