forked from swiftlang/swift-evolution-metadata-extractor
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPreviousProposalExtractor.swift
More file actions
43 lines (34 loc) · 1.63 KB
/
Copy pathPreviousProposalExtractor.swift
File metadata and controls
43 lines (34 loc) · 1.63 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
// This source file is part of the Swift.org open source project
//
// Copyright (c) 2024 Apple Inc. and the Swift project authors
// Licensed under Apache License v2.0 with Runtime Library Exception
//
// See https://swift.org/LICENSE.txt for license information
// See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
import Markdown
import EvolutionMetadataModel
struct PreviousProposalExtractor: MarkupWalker, ValueExtractor {
private var source: HeaderFieldSource
init(source: HeaderFieldSource) { self.source = source }
private var issues = IssueWrapper()
private var previousProposalIDs: [String]? {
_previousProposalIDs.isEmpty ? nil : _previousProposalIDs
}
private var _previousProposalIDs: [String] = []
mutating func extractValue() -> ExtractionResult<[String]> {
if let prevPropField = source["Previous Proposal", "Previous Proposals"] {
visit(prevPropField.value)
// validate that if the header field is here at least one proposal ID was found
if _previousProposalIDs.isEmpty {
issues.reportIssue(.previousProposalIDsExtractionFailure, source: source)
}
}
return ExtractionResult(value: previousProposalIDs, warnings: issues.warnings, errors: issues.errors)
}
mutating func visitText(_ text: Text) -> () {
// VALIDATION ENHANCEMENT: Potentially look for missing links or text that does not include a proposal ID
for match in text.string.matches(of: /SE-\d{4}/) {
_previousProposalIDs.append(String(match.0))
}
}
}