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
7enum Declaration: Grammar {
8 enum Kinds {
9 static let claim = SyntaxTreeKind(name: "decl.claim")
10 static let refine = SyntaxTreeKind(name: "decl.refine")
11 static let define = SyntaxTreeKind(name: "decl.define")
12 }
13
14 static let kinds = [Kinds.claim, Kinds.refine, Kinds.define]
15
16 static func before(_ parser: inout Parser) -> Bool {
17 Lhs.before(&parser)
18 }
19
20 static let punctuationMap: [Punctuation: SyntaxTreeKind] = [
21 .colon: Kinds.claim,
22 .doubleLeftArrow: Kinds.refine,
23 .doubleRightArrow: Kinds.define
24 ]
25
26 static func inside(_ parser: inout Parser) -> ParseResult {
27 Lhs.parse(&parser)
28 parser.eatTrivia()
29
30 var kind: SyntaxTreeKind = .error
31 for cell in punctuationMap {
32 if parser.eat(kind: .punctuation(cell.key), metadata: TokenMetadata(semanticTokenType: .operator)) {
33 kind = cell.value
34 break
35 }
36 }
37
38 if kind == .error {
39 parser.advance(error: "Expected one of \(punctuationMap.keys.map(\.rawValue)) in declaration")
40 }
41
42 parser.eatTrivia()
43 Rhs.parse(&parser)
44
45 return ParseResult(kind: kind)
46 }
47}
48
49extension SyntaxView<Declaration> {
50 var lhs: SyntaxView<Lhs>? { matchingSubview() }
51 var rhs: SyntaxView<Rhs>? { matchingSubview() }
52}