]> Cypherpunks repositories - gostls13.git/commitdiff
go/parser: expressions may have comments
authorRobert Griesemer <gri@golang.org>
Thu, 19 Jan 2012 21:54:31 +0000 (13:54 -0800)
committerRobert Griesemer <gri@golang.org>
Thu, 19 Jan 2012 21:54:31 +0000 (13:54 -0800)
Thanks to 0xE2.0x9A.0x9B for the patch suggestion.

Fixes #2739.

R=r
CC=golang-dev
https://golang.org/cl/5536071

src/pkg/go/parser/interface.go

index 2ce3df8df714750db66d8e785fd18bda450c0351..4b72f38518eeb8636c9995f3497a20e9d8dda3a7 100644 (file)
@@ -135,8 +135,10 @@ func ParseDir(fset *token.FileSet, path string, filter func(os.FileInfo) bool, m
 // 
 func ParseExpr(x string) (ast.Expr, error) {
        // parse x within the context of a complete package for correct scopes;
-       // use //line directive for correct positions in error messages
-       file, err := ParseFile(token.NewFileSet(), "", "package p;func _(){_=\n//line :1\n"+x+";}", 0)
+       // use //line directive for correct positions in error messages and put
+       // x alone on a separate line (handles line comments), followed by a ';'
+       // to force an error if the expression is incomplete
+       file, err := ParseFile(token.NewFileSet(), "", "package p;func _(){_=\n//line :1\n"+x+"\n;}", 0)
        if err != nil {
                return nil, err
        }