// SPDX-FileCopyrightText: 2025 The Project Pterodactyl Developers // // SPDX-License-Identifier: MPL-2.0 import Foundation public struct ImportParser { private var lexer: PterodactylSyntax.Lexer public private(set) var imports: [String] = [] public init(input: String) { self.lexer = PterodactylSyntax.Lexer(input: input) } public mutating func parseHeader() { while true { guard let token = nextSignificantToken() else { return } switch token.kind { case .keyword(.import): parseImportStatement() default: return } } } /// Returns the next non-whitespace token. private mutating func nextSignificantToken() -> Token? { var token = lexer.nextToken() while token?.kind.isTrivia == true { token = lexer.nextToken() } guard let token else { return nil } return Token(kind: token.kind, text: token.text) } /// Parses a single `import xyz` line. private mutating func parseImportStatement() { guard let next = nextSignificantToken() else { return } guard next.kind == .identifier else { return } imports.append(next.text) } }