36 lines
787 B
Go
36 lines
787 B
Go
package scanner
|
|
|
|
import (
|
|
"path/filepath"
|
|
|
|
"git.urbach.dev/cli/q/src/config"
|
|
"git.urbach.dev/cli/q/src/errors"
|
|
"git.urbach.dev/cli/q/src/fs"
|
|
"git.urbach.dev/cli/q/src/token"
|
|
)
|
|
|
|
// scanImport scans an import.
|
|
func (s *Scanner) scanImport(file *fs.File, tokens token.List, i int) (int, error) {
|
|
i++
|
|
|
|
if tokens[i].Kind != token.Identifier {
|
|
return i, errors.New(errors.ExpectedPackageName, file, tokens[i].Position)
|
|
}
|
|
|
|
packageName := tokens[i].Text(file.Bytes)
|
|
|
|
if file.Imports == nil {
|
|
file.Imports = make(map[string]*fs.Import, 4)
|
|
}
|
|
|
|
fullPath := filepath.Join(config.Library, packageName)
|
|
|
|
file.Imports[packageName] = &fs.Import{
|
|
Path: packageName,
|
|
FullPath: fullPath,
|
|
Position: tokens[i].Position,
|
|
}
|
|
|
|
s.queueDirectory(fullPath, packageName)
|
|
return i, nil
|
|
}
|