41 lines
815 B
Go
41 lines
815 B
Go
package scanner
|
|
|
|
import (
|
|
"path/filepath"
|
|
|
|
"git.akyoto.dev/cli/q/src/config"
|
|
"git.akyoto.dev/cli/q/src/fs"
|
|
"git.akyoto.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 {
|
|
panic("expected package name")
|
|
}
|
|
|
|
packageName := tokens[i].Text(file.Bytes)
|
|
|
|
if file.Imports == nil {
|
|
file.Imports = map[string]*fs.Import{}
|
|
}
|
|
|
|
fullPath := filepath.Join(config.Library, packageName)
|
|
|
|
file.Imports[packageName] = &fs.Import{
|
|
Path: packageName,
|
|
FullPath: fullPath,
|
|
Position: tokens[i].Position,
|
|
}
|
|
|
|
s.queueDirectory(fullPath, packageName)
|
|
i++
|
|
|
|
if tokens[i].Kind != token.NewLine && tokens[i].Kind != token.EOF {
|
|
panic("expected newline or eof")
|
|
}
|
|
|
|
return i, nil
|
|
}
|