// SPDX-FileCopyrightText: 2025 The Project Pterodactyl Developers // // SPDX-License-Identifier: MPL-2.0 import Foundation public enum Document: Grammar { public static let kind = SyntaxTreeKind(name: "document") public static let kinds = [kind] public static func precondition(_ parser: inout Parser) -> Bool { true } public static func inside(_ parser: inout Parser, recovery: Set) -> ParseResult { parser.eatTrivia() // Parse imports while !parser.isAt(kind: .eof) { parser.eatTrivia() if Theory.precondition(&parser) { break } if !Import.tryParse(&parser, recovery: recovery) { parser.advance(error: "Expected to see either an import or a theory declaration, but instead got \(parser.currentToken.kind): \(parser.currentToken.text)") } } // Theories section while !parser.isAt(kind: .eof) { if !Theory.tryParse(&parser, recovery: recovery) { if parser.isAt(kindSatisfying: \.isVisible) { let token = parser.currentToken parser.advance(error: "Unexpected token: \(token.kind)") } else { parser.advance(metadata: nil) } } parser.eatTrivia() } parser.eatTrivia() _ = parser.eat(kind: .eof, metadata: nil) return ParseResult(kind: Self.kind) } } extension SyntaxView { var imports: [SyntaxView] { matchingSubviews() } var theories: [SyntaxView] { matchingSubviews() } }