OLD | NEW |
1 // Copyright 2009 The Go Authors. All rights reserved. | 1 // Copyright 2009 The Go Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style | 2 // Use of this source code is governed by a BSD-style |
3 // license that can be found in the LICENSE file. | 3 // license that can be found in the LICENSE file. |
4 | 4 |
5 // This file contains the exported entry points for invoking the parser. | 5 // This file contains the exported entry points for invoking the parser. |
6 | 6 |
7 package parser | 7 package parser |
8 | 8 |
9 import ( | 9 import ( |
10 "bytes" | 10 "bytes" |
(...skipping 165 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
176 // returns a map of package name -> package AST with all the packages found. If | 176 // returns a map of package name -> package AST with all the packages found. If |
177 // filter != nil, only the files with os.FileInfo entries passing through the fi
lter | 177 // filter != nil, only the files with os.FileInfo entries passing through the fi
lter |
178 // are considered. The mode bits are passed to ParseFile unchanged. Position | 178 // are considered. The mode bits are passed to ParseFile unchanged. Position |
179 // information is recorded in the file set fset. | 179 // information is recorded in the file set fset. |
180 // | 180 // |
181 // If the directory couldn't be read, a nil map and the respective error are | 181 // If the directory couldn't be read, a nil map and the respective error are |
182 // returned. If a parse error occurred, a non-nil but incomplete map and the | 182 // returned. If a parse error occurred, a non-nil but incomplete map and the |
183 // error are returned. | 183 // error are returned. |
184 // | 184 // |
185 func ParseDir(fset *token.FileSet, path string, filter func(*os.FileInfo) bool,
mode uint) (map[string]*ast.Package, os.Error) { | 185 func ParseDir(fset *token.FileSet, path string, filter func(*os.FileInfo) bool,
mode uint) (map[string]*ast.Package, os.Error) { |
186 » fd, err := os.Open(path, os.O_RDONLY, 0) | 186 » fd, err := os.Open(path) |
187 if err != nil { | 187 if err != nil { |
188 return nil, err | 188 return nil, err |
189 } | 189 } |
190 defer fd.Close() | 190 defer fd.Close() |
191 | 191 |
192 list, err := fd.Readdir(-1) | 192 list, err := fd.Readdir(-1) |
193 if err != nil { | 193 if err != nil { |
194 return nil, err | 194 return nil, err |
195 } | 195 } |
196 | 196 |
197 filenames := make([]string, len(list)) | 197 filenames := make([]string, len(list)) |
198 n := 0 | 198 n := 0 |
199 for i := 0; i < len(list); i++ { | 199 for i := 0; i < len(list); i++ { |
200 d := &list[i] | 200 d := &list[i] |
201 if filter == nil || filter(d) { | 201 if filter == nil || filter(d) { |
202 filenames[n] = filepath.Join(path, d.Name) | 202 filenames[n] = filepath.Join(path, d.Name) |
203 n++ | 203 n++ |
204 } | 204 } |
205 } | 205 } |
206 filenames = filenames[0:n] | 206 filenames = filenames[0:n] |
207 | 207 |
208 return ParseFiles(fset, filenames, mode) | 208 return ParseFiles(fset, filenames, mode) |
209 } | 209 } |
OLD | NEW |