package scanner import ( "os" "git.akyoto.dev/cli/q/src/errors" "git.akyoto.dev/cli/q/src/fs" "git.akyoto.dev/cli/q/src/token" ) // scanFile scans a single file. func (s *Scanner) scanFile(path string, pkg string) error { contents, err := os.ReadFile(path) if err != nil { return err } tokens := token.Tokenize(contents) file := &fs.File{ Path: path, Bytes: contents, Tokens: tokens, Package: pkg, } s.files <- file i := 0 for i < len(tokens) { switch tokens[i].Kind { case token.NewLine: case token.Import: i, err = s.scanImport(file, tokens, i) case token.Struct: i, err = s.scanStruct(file, tokens, i) case token.Identifier: i, err = s.scanFunction(file, tokens, i) case token.EOF: return nil case token.Invalid: return errors.New(&errors.InvalidCharacter{Character: tokens[i].Text(file.Bytes)}, file, tokens[i].Position) default: return errors.New(&errors.InvalidInstruction{Instruction: tokens[i].Text(file.Bytes)}, file, tokens[i].Position) } if err != nil { return err } i++ } return nil }