Esempio n. 1
0
File: parse.go Progetto: enex/RUN
// ParseDir parses a directory of Calc source files. It calls ParseFile
// for each file ending in .calc found in the directory.
func ParseDir(fset *token.FileSet, path string) (*ast.Package, error) {
	fd, err := os.Open(path)
	if err != nil {
		return nil, err
	}
	defer fd.Close()

	fnames, err := fd.Readdirnames(0)
	if err != nil {
		return nil, err
	}
	fnames = filterByExt(fnames)
	if len(fnames) == 0 {
		return nil, fmt.Errorf("no files to parse; stop")
	}

	var files []*ast.File
	scope := ast.NewScope(nil)

	// TODO: use concurrency
	for _, name := range fnames {
		f, err := ParseFile(fset, filepath.Join(path, name), scope)
		if f == nil {
			return nil, err
		}
		files = append(files, f)
	}
	return &ast.Package{Scope: scope, Files: files}, nil
}
Esempio n. 2
0
File: parse.go Progetto: enex/RUN
func (p *parser) init(file *token.File, fname, src string, s *ast.Scope) {
	if s == nil {
		s = ast.NewScope(nil)
	}
	p.file = file
	p.scanner.Init(p.file, src)
	p.listok = false
	p.curScope = s //ast.NewScope(nil)
	p.topScope = p.curScope
	p.next()
}
Esempio n. 3
0
File: parse.go Progetto: enex/RUN
func (p *parser) openScope() {
	p.curScope = ast.NewScope(p.curScope)
}