]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/compile/internal/syntax: fix syntax.Parse doc string, improved tests
authorRobert Griesemer <gri@golang.org>
Thu, 15 Feb 2018 00:59:36 +0000 (16:59 -0800)
committerRobert Griesemer <gri@golang.org>
Thu, 15 Feb 2018 01:48:21 +0000 (01:48 +0000)
1) Fix the doc string for syntax.Parse: The returned AST is
always nil if there was an error and an error handler is missing.

2) Adjust the syntax Print and Dump tests such that they print and
dump the AST even in the presence of errors.

Change-Id: If658eabdcc83f578d815070bc65d1a5f6cfaddfc
Reviewed-on: https://go-review.googlesource.com/94157
Reviewed-by: Matthew Dempsky <mdempsky@google.com>
src/cmd/compile/internal/syntax/dumper_test.go
src/cmd/compile/internal/syntax/nodes.go
src/cmd/compile/internal/syntax/printer_test.go
src/cmd/compile/internal/syntax/syntax.go

index 02116f5aad7c5c0195a7b99414e403a9f71e8574..32337eb6f143de6fdf4e241d3ee0de8e8448b74d 100644 (file)
@@ -14,9 +14,13 @@ func TestDump(t *testing.T) {
                t.Skip("skipping test in short mode")
        }
 
-       ast, err := ParseFile(*src_, nil, nil, CheckBranches)
+       // provide a dummy error handler so parsing doesn't stop after first error
+       ast, err := ParseFile(*src_, func(error) {}, nil, CheckBranches)
        if err != nil {
-               t.Fatal(err)
+               t.Error(err)
+       }
+
+       if ast != nil {
+               Fdump(os.Stdout, ast)
        }
-       Fdump(os.Stdout, ast)
 }
index 7ab6df13c499bb167aa09498fb89b628c5c551df..d7183bd8fb00dc9cf06a7c6010ecc39cbacd3577 100644 (file)
@@ -215,8 +215,8 @@ type (
        // Fun(ArgList[0], ArgList[1], ...)
        CallExpr struct {
                Fun     Expr
-               ArgList []Expr
-               HasDots bool // last argument is followed by ...
+               ArgList []Expr // nil means no arguments
+               HasDots bool   // last argument is followed by ...
                expr
        }
 
index c21892420299443d78b7fb613b96e355f887be76..6f19846e22d51bdc9edaf2c2133493949734a778 100644 (file)
@@ -16,12 +16,16 @@ func TestPrint(t *testing.T) {
                t.Skip("skipping test in short mode")
        }
 
-       ast, err := ParseFile(*src_, nil, nil, 0)
+       // provide a dummy error handler so parsing doesn't stop after first error
+       ast, err := ParseFile(*src_, func(error) {}, nil, 0)
        if err != nil {
-               t.Fatal(err)
+               t.Error(err)
+       }
+
+       if ast != nil {
+               Fprint(os.Stdout, ast, true)
+               fmt.Println()
        }
-       Fprint(os.Stdout, ast, true)
-       fmt.Println()
 }
 
 func TestPrintString(t *testing.T) {
index f6e9303290124606e5585ea128f5837352c8eab1..7de7d4d9fae7f7095bf0d29d23fc699c24ec8245 100644 (file)
@@ -50,12 +50,13 @@ type FilenameHandler func(name string) string
 
 // Parse parses a single Go source file from src and returns the corresponding
 // syntax tree. If there are errors, Parse will return the first error found,
-// and a possibly partially constructed syntax tree, or nil if no correct package
-// clause was found. The base argument is only used for position information.
+// and a possibly partially constructed syntax tree, or nil.
 //
 // If errh != nil, it is called with each error encountered, and Parse will
-// process as much source as possible. If errh is nil, Parse will terminate
-// immediately upon encountering an error.
+// process as much source as possible. In this case, the returned syntax tree
+// is only nil if no correct package clause was found.
+// If errh is nil, Parse will terminate immediately upon encountering the first
+// error, and the returned syntax tree is nil.
 //
 // If pragh != nil, it is called with each pragma encountered.
 //