this repo has no description
www.jonmsterling.com/01HC/
1// SPDX-FileCopyrightText: 2025 The Project Pterodactyl Developers
2//
3// SPDX-License-Identifier: MPL-2.0
4
5import Foundation
6
7public protocol Grammar: Sendable {
8 static var kinds: [SyntaxTreeKind] { get }
9 static func before(_ parser: inout Parser) -> Bool
10 static func inside(_ parser: inout Parser) -> ParseResult
11}
12
13public struct ParseResult {
14 public var kind: SyntaxTreeKind
15 public var metadata: SyntaxTreeMetadata? = nil
16
17 public init(kind: SyntaxTreeKind, metadata: SyntaxTreeMetadata? = nil) {
18 self.kind = kind
19 self.metadata = metadata
20 }
21}
22
23
24public extension Grammar {
25 static func tryParse(_ parser: inout Parser) -> Bool {
26 guard !parser.isEndOfFile && before(&parser) else { return false }
27 parse(&parser)
28 return true
29 }
30
31 static func parse(_ parser: inout Parser) {
32 let mark = parser.open()
33 let result = inside(&parser)
34 parser.close(mark: mark, kind: result.kind, metadata: result.metadata)
35 }
36}