Implemented struct parser
This commit is contained in:
parent
00e7216256
commit
30940f0100
19 changed files with 388 additions and 252 deletions
41
src/scanner/scanImport.go
Normal file
41
src/scanner/scanImport.go
Normal file
|
@ -0,0 +1,41 @@
|
|||
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
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue