Skip to content

Commit d952156

Browse files
committed
Remove RegexBuilder for windows 5.9 support
1 parent 390928f commit d952156

File tree

1 file changed

+9
-34
lines changed

1 file changed

+9
-34
lines changed

Sources/SwiftFormat/Core/RuleMask.swift

Lines changed: 9 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111
//===----------------------------------------------------------------------===//
1212

1313
import Foundation
14-
import RegexBuilder
1514
import SwiftSyntax
1615

1716
/// This class takes the raw source text and scans through it searching for comments that instruct
@@ -113,30 +112,10 @@ enum IgnoreDirective: CustomStringConvertible {
113112
}
114113

115114
/// Regex pattern to match an ignore directive comment.
116-
/// - Capture group #1 captures `":"`, if present.
117-
/// - Capture group #2 captures the rule name(s), if any.
118-
fileprivate func makeRegex() -> Regex<(Substring, Substring?, Substring?)> {
119-
return Regex {
120-
Anchor.startOfLine
121-
ZeroOrMore(.whitespace)
122-
"//"
123-
ZeroOrMore(.whitespace)
124-
description
125-
NegativeLookahead {
126-
CharacterClass.any.subtracting(.anyOf(":"))
127-
}
128-
Optionally {
129-
Capture {
130-
":"
131-
}
132-
}
133-
Optionally {
134-
Capture {
135-
OneOrMore(.whitespace)
136-
OneOrMore(.any)
137-
}
138-
}
139-
}
115+
/// - Capture group #1 captures the rule names if `":"` is present.
116+
fileprivate func makeRegex() -> Regex<(Substring, Substring?)> {
117+
let pattern = #"^\s*\/\/\s*"# + description + #"(?:\s*:\s*(.+))?$"#
118+
return try! Regex(pattern)
140119
}
141120
}
142121

@@ -162,10 +141,10 @@ fileprivate class RuleStatusCollectionVisitor: SyntaxVisitor {
162141
private let sourceLocationConverter: SourceLocationConverter
163142

164143
/// Cached regex object for ignoring rules at the node.
165-
private let ignoreRegex: Regex<(Substring, Substring?, Substring?)>
144+
private let ignoreRegex: Regex<(Substring, Substring?)>
166145

167146
/// Cached regex object for ignoring rules at the file.
168-
private let ignoreFileRegex: Regex<(Substring, Substring?, Substring?)>
147+
private let ignoreFileRegex: Regex<(Substring, Substring?)>
169148

170149
/// Stores the source ranges in which all rules are ignored.
171150
var allRulesIgnoredRanges: [SourceRange] = []
@@ -224,7 +203,7 @@ fileprivate class RuleStatusCollectionVisitor: SyntaxVisitor {
224203
private func appendRuleStatus(
225204
from token: TokenSyntax,
226205
of sourceRange: SourceRange,
227-
using regex: Regex<(Substring, Substring?, Substring?)>
206+
using regex: Regex<(Substring, Substring?)>
228207
) -> SyntaxVisitorContinueKind {
229208
let isFirstInFile = token.previousToken(viewMode: .sourceAccurate) == nil
230209
let comments = loneLineComments(in: token.leadingTrivia, isFirstToken: isFirstInFile)
@@ -249,18 +228,14 @@ fileprivate class RuleStatusCollectionVisitor: SyntaxVisitor {
249228
/// match, its contents (e.g. list of rule names) are returned.
250229
private func ruleStatusDirectiveMatch(
251230
in text: String,
252-
using regex: Regex<(Substring, Substring?, Substring?)>
231+
using regex: Regex<(Substring, Substring?)>
253232
) -> RuleStatusDirectiveMatch? {
254233
guard let match = text.firstMatch(of: regex) else {
255234
return nil
256235
}
257-
let hasColon = match.output.1 != nil
258-
guard hasColon else {
236+
guard let matchedRuleNames = match.output.1 else {
259237
return .all
260238
}
261-
guard let matchedRuleNames = match.output.2 else {
262-
return nil
263-
}
264239
let rules = matchedRuleNames.split(separator: ",")
265240
.map { $0.trimmingCharacters(in: .whitespaces) }
266241
.filter { $0.count > 0 }

0 commit comments

Comments
 (0)