mirror of
https://github.com/golang/go
synced 2024-11-26 16:36:49 -07:00
cmd/compile/internal/syntax: fix syntax.Parse doc string, improved tests
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>
This commit is contained in:
parent
1a22738749
commit
eda39fe9b2
@ -14,9 +14,13 @@ func TestDump(t *testing.T) {
|
|||||||
t.Skip("skipping test in short mode")
|
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 {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Error(err)
|
||||||
|
}
|
||||||
|
|
||||||
|
if ast != nil {
|
||||||
|
Fdump(os.Stdout, ast)
|
||||||
}
|
}
|
||||||
Fdump(os.Stdout, ast)
|
|
||||||
}
|
}
|
||||||
|
@ -215,8 +215,8 @@ type (
|
|||||||
// Fun(ArgList[0], ArgList[1], ...)
|
// Fun(ArgList[0], ArgList[1], ...)
|
||||||
CallExpr struct {
|
CallExpr struct {
|
||||||
Fun Expr
|
Fun Expr
|
||||||
ArgList []Expr
|
ArgList []Expr // nil means no arguments
|
||||||
HasDots bool // last argument is followed by ...
|
HasDots bool // last argument is followed by ...
|
||||||
expr
|
expr
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -16,12 +16,16 @@ func TestPrint(t *testing.T) {
|
|||||||
t.Skip("skipping test in short mode")
|
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 {
|
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) {
|
func TestPrintString(t *testing.T) {
|
||||||
|
@ -50,12 +50,13 @@ type FilenameHandler func(name string) string
|
|||||||
|
|
||||||
// Parse parses a single Go source file from src and returns the corresponding
|
// 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,
|
// 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
|
// and a possibly partially constructed syntax tree, or nil.
|
||||||
// clause was found. The base argument is only used for position information.
|
|
||||||
//
|
//
|
||||||
// If errh != nil, it is called with each error encountered, and Parse will
|
// 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
|
// process as much source as possible. In this case, the returned syntax tree
|
||||||
// immediately upon encountering an error.
|
// 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.
|
// If pragh != nil, it is called with each pragma encountered.
|
||||||
//
|
//
|
||||||
|
Loading…
Reference in New Issue
Block a user