summaryrefslogtreecommitdiff
path: root/src/pkg/go/parser/interface.go
diff options
context:
space:
mode:
authorRuss Cox <rsc@golang.org>2009-09-03 17:01:10 -0700
committerRuss Cox <rsc@golang.org>2009-09-03 17:01:10 -0700
commit72afc835accfa35984736f63738a021ab9c27a38 (patch)
tree1c74b3a33d50f638a0fef572929f1150aa571825 /src/pkg/go/parser/interface.go
parent774753af3559171c5483c71543c20d56a26d65bb (diff)
downloadgolang-72afc835accfa35984736f63738a021ab9c27a38.tar.gz
add ParseDeclList
R=austin DELTA=34 (34 added, 0 deleted, 0 changed) OCL=34280 CL=34352
Diffstat (limited to 'src/pkg/go/parser/interface.go')
-rw-r--r--src/pkg/go/parser/interface.go20
1 files changed, 20 insertions, 0 deletions
diff --git a/src/pkg/go/parser/interface.go b/src/pkg/go/parser/interface.go
index 94835b8ec..d840e9a4a 100644
--- a/src/pkg/go/parser/interface.go
+++ b/src/pkg/go/parser/interface.go
@@ -8,9 +8,11 @@ package parser
import (
"bytes";
+ "container/vector";
"fmt";
"go/ast";
"go/scanner";
+ "go/token";
"io";
"os";
pathutil "path";
@@ -86,6 +88,24 @@ func ParseStmtList(filename string, src interface{}) ([]ast.Stmt, os.Error) {
}
+// ParseDeclList parses a list of Go declarations and returns the list
+// of corresponding AST nodes. The filename and src arguments have the same
+// interpretation as for ParseFile. If there is an error, the node
+// list may be nil or contain partial ASTs.
+//
+func ParseDeclList(filename string, src interface{}) ([]ast.Decl, os.Error) {
+ data, err := readSource(filename, src);
+ if err != nil {
+ return nil, err;
+ }
+
+ var p parser;
+ p.init(filename, data, 0);
+ list := p.parseDeclList(); // TODO 6g bug - function call order in expr lists
+ return list, p.GetError(scanner.Sorted);
+}
+
+
// ParseFile parses a Go source file and returns a File node.
//
// If src != nil, ParseFile parses the file source from src. src may