Skip to content

Commit ff20a03

Browse files
committed
Delete OutputType from Parser
1 parent 0f3cecb commit ff20a03

File tree

5 files changed

+4
-81
lines changed

5 files changed

+4
-81
lines changed

Sources/XcbeautifyLib/CaptureGroups.swift

+3-1
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,11 @@ package protocol CaptureGroup {
66
init?(groups: [String])
77
}
88

9-
extension CaptureGroup {
9+
package extension CaptureGroup {
1010
var outputType: OutputType { Self.outputType }
11+
}
1112

13+
extension CaptureGroup {
1214
static var pattern: String { regex.pattern }
1315
var pattern: String { Self.regex.pattern }
1416
}

Sources/XcbeautifyLib/Parser.swift

-8
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import Foundation
22

33
package class Parser {
4-
package private(set) var outputType = OutputType.undefined
54

65
private lazy var captureGroupTypes: [CaptureGroup.Type] = [
76
AnalyzeCaptureGroup.self,
@@ -100,16 +99,11 @@ package class Parser {
10099

101100
package func parse(line: String) -> CaptureGroup? {
102101
if line.isEmpty {
103-
outputType = .undefined
104102
return nil
105103
}
106104

107105
// Find first parser that can parse specified string
108106
guard let idx = captureGroupTypes.firstIndex(where: { $0.regex.match(string: line) }) else {
109-
// Some uncommon cases, which have additional logic and don't follow default flow
110-
111-
// Nothing found?
112-
outputType = OutputType.undefined
113107
return nil
114108
}
115109

@@ -124,8 +118,6 @@ package class Parser {
124118
return nil
125119
}
126120

127-
outputType = captureGroupType.outputType
128-
129121
// Move found parser to the top, so next time it will be checked first
130122
captureGroupTypes.insert(captureGroupTypes.remove(at: idx), at: 0)
131123

Sources/xcbeautify/Xcbeautify.swift

+1-1
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ struct Xcbeautify: ParsableCommand {
7676
continue
7777
}
7878
guard let formatted = formatter.format(captureGroup: captureGroup) else { continue }
79-
output.write(parser.outputType, formatted)
79+
output.write(captureGroup.outputType, formatted)
8080
}
8181

8282
if !report.isEmpty {

0 commit comments

Comments
 (0)