// SPDX-FileCopyrightText: 2025 The Project Pterodactyl Developers // // SPDX-License-Identifier: MPL-2.0 import Foundation import PterodactylSyntax import llbuild2fx import Logging extension Keys.Blob { public struct ParseDocument: BuildKey { public let blobId: LLBDataID public init(blobId: LLBDataID) { self.blobId = blobId } public struct ValueType: Codable, FXValue { public let tree: PterodactylSyntax.SyntaxTree public let diagnostics: [Diagnostic] } public static let versionDependencies: [any FXVersioning.Type] = [ReadContents.self, Tokenise.self] public func computeValue(_ ctx: BuildContext) async throws -> ValueType { let code = try await ctx.request(ReadContents(blobId: blobId)) let tokens = try await ctx.request(Tokenise(blobId: blobId)) var parser = Parser(source: code, tokens: tokens) PterodactylSyntax.Document.parse(&parser, recovery: []) return ValueType(tree: parser.builder.tree, diagnostics: parser.diagnostics) } } }