diff options
author | Ondřej Surý <ondrej@sury.org> | 2011-08-03 17:26:15 +0200 |
---|---|---|
committer | Ondřej Surý <ondrej@sury.org> | 2011-08-03 17:31:49 +0200 |
commit | b757d264230d65f988e08158e096a09497d39eb4 (patch) | |
tree | e20ec608a2ec8ebf603fa7aa060eb9723c4780b9 /src/pkg/go/parser/interface.go | |
parent | 5976088995f5c0d0bcada7d491fda4b6245e54e0 (diff) | |
download | golang-b757d264230d65f988e08158e096a09497d39eb4.tar.gz |
Imported Upstream version 2011.07.29
Diffstat (limited to 'src/pkg/go/parser/interface.go')
-rw-r--r-- | src/pkg/go/parser/interface.go | 35 |
1 files changed, 20 insertions, 15 deletions
diff --git a/src/pkg/go/parser/interface.go b/src/pkg/go/parser/interface.go index 1764c38e4..4f980fc65 100644 --- a/src/pkg/go/parser/interface.go +++ b/src/pkg/go/parser/interface.go @@ -17,7 +17,6 @@ import ( "path/filepath" ) - // If src != nil, readSource converts src to a []byte if possible; // otherwise it returns an error. If src == nil, readSource returns // the result of reading the file specified by filename. @@ -49,13 +48,14 @@ func readSource(filename string, src interface{}) ([]byte, os.Error) { return ioutil.ReadFile(filename) } - -func (p *parser) parseEOF() os.Error { - p.expect(token.EOF) - return p.GetError(scanner.Sorted) +func (p *parser) errors() os.Error { + mode := scanner.Sorted + if p.mode&SpuriousErrors == 0 { + mode = scanner.NoMultiples + } + return p.GetError(mode) } - // ParseExpr parses a Go expression and returns the corresponding // AST node. The fset, filename, and src arguments have the same interpretation // as for ParseFile. If there is an error, the result expression @@ -73,9 +73,10 @@ func ParseExpr(fset *token.FileSet, filename string, src interface{}) (ast.Expr, if p.tok == token.SEMICOLON { p.next() // consume automatically inserted semicolon, if any } - return x, p.parseEOF() -} + p.expect(token.EOF) + return x, p.errors() +} // ParseStmtList parses a list of Go statements and returns the list // of corresponding AST nodes. The fset, filename, and src arguments have the same @@ -90,9 +91,11 @@ func ParseStmtList(fset *token.FileSet, filename string, src interface{}) ([]ast var p parser p.init(fset, filename, data, 0) - return p.parseStmtList(), p.parseEOF() -} + list := p.parseStmtList() + p.expect(token.EOF) + return list, p.errors() +} // ParseDeclList parses a list of Go declarations and returns the list // of corresponding AST nodes. The fset, filename, and src arguments have the same @@ -107,9 +110,11 @@ func ParseDeclList(fset *token.FileSet, filename string, src interface{}) ([]ast var p parser p.init(fset, filename, data, 0) - return p.parseDeclList(), p.parseEOF() -} + list := p.parseDeclList() + p.expect(token.EOF) + return list, p.errors() +} // ParseFile parses the source code of a single Go source file and returns // the corresponding ast.File node. The source code may be provided via @@ -139,9 +144,10 @@ func ParseFile(fset *token.FileSet, filename string, src interface{}, mode uint) var p parser p.init(fset, filename, data, mode) - return p.parseFile(), p.GetError(scanner.NoMultiples) // parseFile() reads to EOF -} + file := p.parseFile() // parseFile reads to EOF + return file, p.errors() +} // ParseFiles calls ParseFile for each file in the filenames list and returns // a map of package name -> package AST with all the packages found. The mode @@ -171,7 +177,6 @@ func ParseFiles(fset *token.FileSet, filenames []string, mode uint) (pkgs map[st return } - // ParseDir calls ParseFile for the files in the directory specified by path and // returns a map of package name -> package AST with all the packages found. If // filter != nil, only the files with os.FileInfo entries passing through the filter |