Implemented struct parser

This commit is contained in:
Eduard Urbach 2025-02-04 14:41:04 +01:00
parent 00e7216256
commit 30940f0100
Signed by: eduard
GPG key ID: 49226B848C78F6C8
19 changed files with 388 additions and 252 deletions

41
src/scanner/scanImport.go Normal file
View 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
}