import (
"bytes";
+ "container/vector";
"fmt";
"go/ast";
"go/scanner";
+ "go/token";
"io";
"os";
pathutil "path";
}
+// 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
}
+func (p *parser) parseDeclList() []ast.Decl {
+ var list vector.Vector;
+ for p.tok != token.EOF {
+ decl, _ := p.parseDecl(true); // consume optional semicolon
+ list.Push(decl);
+ }
+ decls := make([]ast.Decl, list.Len());
+ for i := 0; i < list.Len(); i++ {
+ decls[i] = list.At(i).(ast.Decl);
+ }
+ return decls;
+}
+
+
// ----------------------------------------------------------------------------
// Source files