1// SPDX-FileCopyrightText: 2025 The Project Pterodactyl Developers 2// 3// SPDX-License-Identifier: MPL-2.0 4 5import Foundation 6 7struct SyntaxView<G: Grammar> { 8 let cursor: SyntaxTree.Cursor 9 init?(_ cursor: SyntaxTree.Cursor) { 10 guard let kind = cursor.node.tree?.kind, G.kinds.contains(kind) else { return nil } 11 self.cursor = cursor 12 } 13 14 func matchingSubview<X: Grammar>() -> SyntaxView<X>? { 15 return cursor.firstChild(mapping: SyntaxView<X>.init) 16 } 17 18 func matchingSubviews<X: Grammar>() -> [SyntaxView<X>] { 19 return cursor.children(mapping: SyntaxView<X>.init) 20 } 21}