Skip to content

Commit

Permalink
Delete OutputType from Parser
Browse files Browse the repository at this point in the history
  • Loading branch information
cpisciotta committed Feb 25, 2024
1 parent 9e64508 commit 1f8cf1b
Show file tree
Hide file tree
Showing 5 changed files with 4 additions and 81 deletions.
4 changes: 3 additions & 1 deletion Sources/XcbeautifyLib/CaptureGroups.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,11 @@ package protocol CaptureGroup {
init?(groups: [String])
}

extension CaptureGroup {
package extension CaptureGroup {
var outputType: OutputType { Self.outputType }

Check warning on line 10 in Sources/XcbeautifyLib/CaptureGroups.swift

View check run for this annotation

Codecov / codecov/patch

Sources/XcbeautifyLib/CaptureGroups.swift#L10

Added line #L10 was not covered by tests
}

extension CaptureGroup {
static var pattern: String { regex.pattern }
var pattern: String { Self.regex.pattern }
}
Expand Down
8 changes: 0 additions & 8 deletions Sources/XcbeautifyLib/Parser.swift
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import Foundation

package class Parser {

Check warning on line 3 in Sources/XcbeautifyLib/Parser.swift

View workflow job for this annotation

GitHub Actions / SwiftFormat

Remove leading blank line at the start of a scope. (blankLinesAtStartOfScope)
package private(set) var outputType = OutputType.undefined

private lazy var captureGroupTypes: [CaptureGroup.Type] = [
AnalyzeCaptureGroup.self,
Expand Down Expand Up @@ -96,16 +95,11 @@ package class Parser {

package func parse(line: String) -> CaptureGroup? {
if line.isEmpty {
outputType = .undefined
return nil
}

// Find first parser that can parse specified string
guard let idx = captureGroupTypes.firstIndex(where: { $0.regex.match(string: line) }) else {
// Some uncommon cases, which have additional logic and don't follow default flow

// Nothing found?
outputType = OutputType.undefined
return nil
}

Expand All @@ -120,8 +114,6 @@ package class Parser {
return nil

Check warning on line 114 in Sources/XcbeautifyLib/Parser.swift

View check run for this annotation

Codecov / codecov/patch

Sources/XcbeautifyLib/Parser.swift#L113-L114

Added lines #L113 - L114 were not covered by tests
}

outputType = captureGroupType.outputType

// Move found parser to the top, so next time it will be checked first
captureGroupTypes.insert(captureGroupTypes.remove(at: idx), at: 0)

Expand Down
2 changes: 1 addition & 1 deletion Sources/xcbeautify/Xcbeautify.swift
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ struct Xcbeautify: ParsableCommand {
continue
}
guard let formatted = formatter.format(captureGroup: captureGroup) else { continue }
output.write(parser.outputType, formatted)
output.write(captureGroup.outputType, formatted)
}

if !report.isEmpty {
Expand Down
Loading

0 comments on commit 1f8cf1b

Please sign in to comment.