Commit 45eadcf4 authored by Russ Cox's avatar Russ Cox

add ParseDeclList

R=austin
DELTA=34  (34 added, 0 deleted, 0 changed)
OCL=34280
CL=34352
parent db27b5bc
......@@ -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
......
......@@ -1889,6 +1889,20 @@ func (p *parser) parseDecl(getSemi bool) (decl ast.Decl, gotSemi bool) {
}
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
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment