Skip to content

Commit 1f8cf1b

Browse files
committed
Delete OutputType from Parser
1 parent 9e64508 commit 1f8cf1b

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,
@@ -96,16 +95,11 @@ package class Parser {
9695

9796
package func parse(line: String) -> CaptureGroup? {
9897
if line.isEmpty {
99-
outputType = .undefined
10098
return nil
10199
}
102100

103101
// Find first parser that can parse specified string
104102
guard let idx = captureGroupTypes.firstIndex(where: { $0.regex.match(string: line) }) else {
105-
// Some uncommon cases, which have additional logic and don't follow default flow
106-
107-
// Nothing found?
108-
outputType = OutputType.undefined
109103
return nil
110104
}
111105

@@ -120,8 +114,6 @@ package class Parser {
120114
return nil
121115
}
122116

123-
outputType = captureGroupType.outputType
124-
125117
// Move found parser to the top, so next time it will be checked first
126118
captureGroupTypes.insert(captureGroupTypes.remove(at: idx), at: 0)
127119

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)