Skip to content

Commit fbff72f

Browse files
committed
Delete OutputType from Parser
1 parent f309511 commit fbff72f

File tree

6 files changed

+4
-91
lines changed

6 files changed

+4
-91
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

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

33
package class Parser {
4-
package private(set) var outputType = OutputType.undefined
5-
64
private lazy var captureGroupTypes: [any CaptureGroup.Type] = [
75
AnalyzeCaptureGroup.self,
86
BuildTargetCaptureGroup.self,
@@ -102,16 +100,11 @@ package class Parser {
102100

103101
package func parse(line: String) -> (any CaptureGroup)? {
104102
if line.isEmpty {
105-
outputType = .undefined
106103
return nil
107104
}
108105

109106
// Find first parser that can parse specified string
110107
guard let idx = captureGroupTypes.firstIndex(where: { $0.regex.match(string: line) }) else {
111-
// Some uncommon cases, which have additional logic and don't follow default flow
112-
113-
// Nothing found?
114-
outputType = OutputType.undefined
115108
return nil
116109
}
117110

@@ -126,8 +119,6 @@ package class Parser {
126119
return nil
127120
}
128121

129-
outputType = captureGroupType.outputType
130-
131122
// Move found parser to the top, so next time it will be checked first
132123
captureGroupTypes.insert(captureGroupTypes.remove(at: idx), at: 0)
133124

Sources/xcbeautify/Xcbeautify.swift

+1-1
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ struct Xcbeautify: ParsableCommand {
103103
continue
104104
}
105105
guard let formatted = formatter.format(captureGroup: captureGroup) else { continue }
106-
output.write(parser.outputType, formatted)
106+
output.write(captureGroup.outputType, formatted)
107107
}
108108

109109
if !report.isEmpty {

0 commit comments

Comments
 (0)