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 23, 2024
1 parent c695fa7 commit 050c0c7
Show file tree
Hide file tree
Showing 6 changed files with 7 additions and 83 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 }
}

extension CaptureGroup {
static var pattern: String { regex.pattern }
var pattern: String { Self.regex.pattern }
}
Expand Down
11 changes: 2 additions & 9 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 @@ -92,15 +91,11 @@ package class Parser {

// MARK: - Init

public init() { }
package init() { }

public func parse(line: String) -> CaptureGroup? {
package func parse(line: String) -> CaptureGroup? {
// 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 @@ -115,8 +110,6 @@ package class Parser {
return nil
}

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/XcbeautifyLib/Regex.swift
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import Foundation

public final class Regex {
package final class Regex {
let pattern: String

private lazy var regex: NSRegularExpression? = try? NSRegularExpression(pattern: "^" + pattern, options: [.caseInsensitive])
Expand Down
2 changes: 1 addition & 1 deletion Sources/xcbeautify/Xcbeautify.swift
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,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 050c0c7

Please sign in to comment.