at main 683 B view raw
1// SPDX-FileCopyrightText: 2025 The Project Pterodactyl Developers 2// 3// SPDX-License-Identifier: MPL-2.0 4 5import Foundation 6 7/// An abstract syntax view around a ``SyntaxCursor``. This is to be populated by extensions targetting specific `G`. 8struct SyntaxView<G: Grammar> { 9 let cursor: SyntaxCursor 10 init?(_ cursor: SyntaxCursor) { 11 guard let kind = cursor.node.tree?.kind, G.kinds.contains(kind) else { return nil } 12 self.cursor = cursor 13 } 14 15 func matchingSubview<X: Grammar>() -> SyntaxView<X>? { 16 return cursor.firstChild(mapping: SyntaxView<X>.init) 17 } 18 19 func matchingSubviews<X: Grammar>() -> [SyntaxView<X>] { 20 return cursor.children(mapping: SyntaxView<X>.init) 21 } 22}