Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
G
go
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
go
Commits
45eadcf4
Commit
45eadcf4
authored
Sep 03, 2009
by
Russ Cox
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
add ParseDeclList
R=austin DELTA=34 (34 added, 0 deleted, 0 changed) OCL=34280 CL=34352
parent
db27b5bc
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
34 additions
and
0 deletions
+34
-0
src/pkg/go/parser/interface.go
src/pkg/go/parser/interface.go
+20
-0
src/pkg/go/parser/parser.go
src/pkg/go/parser/parser.go
+14
-0
No files found.
src/pkg/go/parser/interface.go
View file @
45eadcf4
...
...
@@ -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
...
...
src/pkg/go/parser/parser.go
View file @
45eadcf4
...
...
@@ -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
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment