]> Cypherpunks repositories - gostls13.git/commitdiff
New flags for gofmt:
authorRobert Griesemer <gri@golang.org>
Fri, 11 Dec 2009 03:03:28 +0000 (19:03 -0800)
committerRobert Griesemer <gri@golang.org>
Fri, 11 Dec 2009 03:03:28 +0000 (19:03 -0800)
- 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

src/cmd/gofmt/doc.go
src/cmd/gofmt/gofmt.go
src/pkg/Makefile
src/pkg/exp/eval/world.go

index 4b4adba030bb7ff7ddbcac0fced59eb889f2b40c..e9b1d6c47f3342e2257059e0d15f0ce4b1e76357 100644 (file)
@@ -29,6 +29,14 @@ The flags are:
        -tabwidth=8
                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:
 
        -trace
index b3a96857d579fd3f0de6f25f2c5a1836f5813218..115ddb9280bdb04841af884f8eb5278a786a82e6 100644 (file)
@@ -6,6 +6,7 @@ package main
 
 import (
        "bytes";
+       oldParser "exp/parser";
        "flag";
        "fmt";
        "go/ast";
@@ -30,9 +31,13 @@ var (
        trace           = flag.Bool("trace", false, "print parse trace");
 
        // layout control
-       tabwidth        = flag.Int("tabwidth", 8, "tab width");
-       tabindent       = flag.Bool("tabindent", false, "indent with tabs independent of -spaces");
-       usespaces       = flag.Bool("spaces", false, "align with spaces instead of tabs");
+       tabWidth        = flag.Int("tabwidth", 8, "tab width");
+       tabIndent       = flag.Bool("tabindent", false, "indent with tabs independent of -spaces");
+       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() {
 
 
 func initPrinterMode() {
-       printerMode = uint(0);
-       if *tabindent {
+       printerMode = printer.NoStringConcat;
+       if *tabIndent {
                printerMode |= printer.TabIndent
        }
-       if *usespaces {
+       if *useSpaces {
                printerMode |= printer.UseSpaces
        }
+       if !*useOldPrinter {
+               printerMode |= printer.NoSemis
+       }
 }
 
 
@@ -91,7 +99,12 @@ func processFile(f *os.File) os.Error {
                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 {
                return err
        }
@@ -101,7 +114,7 @@ func processFile(f *os.File) os.Error {
        }
 
        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 {
                return err
        }
@@ -176,8 +189,8 @@ func walkDir(path string) {
 func main() {
        flag.Usage = usage;
        flag.Parse();
-       if *tabwidth < 0 {
-               fmt.Fprintf(os.Stderr, "negative tabwidth %d\n", *tabwidth);
+       if *tabWidth < 0 {
+               fmt.Fprintf(os.Stderr, "negative tabwidth %d\n", *tabWidth);
                os.Exit(2);
        }
 
index 912bc9d6040108c9811f862aa7edc456c8106ca0..dee9ad992eb3e1fff88801367517c05bd9c5ab40 100644 (file)
@@ -55,6 +55,7 @@ DIRS=\
        exp/eval\
        exp/exception\
        exp/iterable\
+       exp/parser\
        expvar\
        flag\
        fmt\
index c442f79237f5243e31d628ef79bd735197c184f8..184e737c6500d9a4ea429dd42b5e12cccfb27d32 100644 (file)
@@ -9,7 +9,7 @@ package eval
 
 import (
        "go/ast";
-       "go/parser";
+       parser "exp/parser";
        "go/scanner";
        "go/token";
        "os";