Skip to content

Commit

Permalink
Merge pull request #9 from nakajima/main
Browse files Browse the repository at this point in the history
Maybe fix some concurrency warnings
  • Loading branch information
mattmassicotte authored Jul 3, 2024
2 parents 453bc35 + b4ae186 commit 5dd8a8d
Show file tree
Hide file tree
Showing 2 changed files with 64 additions and 53 deletions.
102 changes: 54 additions & 48 deletions Sources/TextFormation/TextualIndenter+Language.swift
Original file line number Diff line number Diff line change
@@ -1,65 +1,71 @@
import Foundation

public extension TextualIndenter {
static let basicPatterns: [PatternMatcher] = [
CurrentLinePrefixOutdenter(prefix: "}"),
CurrentLinePrefixOutdenter(prefix: ")"),
CurrentLinePrefixOutdenter(prefix: "]"),
static var basicPatterns: [PatternMatcher] {
[
CurrentLinePrefixOutdenter(prefix: "}"),
CurrentLinePrefixOutdenter(prefix: ")"),
CurrentLinePrefixOutdenter(prefix: "]"),

PreceedingLinePrefixIndenter(prefix: "{"),
PreceedingLinePrefixIndenter(prefix: "("),
PreceedingLinePrefixIndenter(prefix: "["),
PreceedingLinePrefixIndenter(prefix: "{"),
PreceedingLinePrefixIndenter(prefix: "("),
PreceedingLinePrefixIndenter(prefix: "["),

PreceedingLineSuffixIndenter(suffix: "{"),
PreceedingLineSuffixIndenter(suffix: "("),
PreceedingLineSuffixIndenter(suffix: "["),
]
PreceedingLineSuffixIndenter(suffix: "{"),
PreceedingLineSuffixIndenter(suffix: "("),
PreceedingLineSuffixIndenter(suffix: "["),
]
}
}

public extension TextualIndenter {
/// Specialized indentation patterns for Ruby.
static let rubyPatterns: [PatternMatcher] = [
CurrentLinePrefixOutdenter(prefix: "else"),
CurrentLinePrefixOutdenter(prefix: "elsif"),
CurrentLinePrefixOutdenter(prefix: "ensure"),
CurrentLinePrefixOutdenter(prefix: "rescue"),
CurrentLinePrefixOutdenter(prefix: "when"),
CurrentLinePrefixOutdenter(prefix: "end"),
static var rubyPatterns: [PatternMatcher] {
[
CurrentLinePrefixOutdenter(prefix: "else"),
CurrentLinePrefixOutdenter(prefix: "elsif"),
CurrentLinePrefixOutdenter(prefix: "ensure"),
CurrentLinePrefixOutdenter(prefix: "rescue"),
CurrentLinePrefixOutdenter(prefix: "when"),
CurrentLinePrefixOutdenter(prefix: "end"),

PreceedingLinePrefixIndenter(prefix: "{"),
PreceedingLinePrefixIndenter(prefix: "("),
PreceedingLinePrefixIndenter(prefix: "["),
PreceedingLinePrefixIndenter(prefix: "{"),
PreceedingLinePrefixIndenter(prefix: "("),
PreceedingLinePrefixIndenter(prefix: "["),

PreceedingLineSuffixIndenter(suffix: "{"),
PreceedingLineSuffixIndenter(suffix: "("),
PreceedingLineSuffixIndenter(suffix: "["),
PreceedingLineSuffixIndenter(suffix: "|"),
PreceedingLineSuffixIndenter(suffix: "do"),
PreceedingLineSuffixIndenter(suffix: "{"),
PreceedingLineSuffixIndenter(suffix: "("),
PreceedingLineSuffixIndenter(suffix: "["),
PreceedingLineSuffixIndenter(suffix: "|"),
PreceedingLineSuffixIndenter(suffix: "do"),

PreceedingLinePrefixIndenter(prefix: "if"),
PreceedingLinePrefixIndenter(prefix: "else"),
PreceedingLinePrefixIndenter(prefix: "elsif"),
PreceedingLinePrefixIndenter(prefix: "ensure"),
PreceedingLinePrefixIndenter(prefix: "rescue"),
PreceedingLinePrefixIndenter(prefix: "when"),
PreceedingLinePrefixIndenter(prefix: "for"),
PreceedingLinePrefixIndenter(prefix: "unless"),
PreceedingLinePrefixIndenter(prefix: "while"),
PreceedingLinePrefixIndenter(prefix: "class"),
PreceedingLinePrefixIndenter(prefix: "module"),
PreceedingLinePrefixIndenter(prefix: "def"),
]
PreceedingLinePrefixIndenter(prefix: "if"),
PreceedingLinePrefixIndenter(prefix: "else"),
PreceedingLinePrefixIndenter(prefix: "elsif"),
PreceedingLinePrefixIndenter(prefix: "ensure"),
PreceedingLinePrefixIndenter(prefix: "rescue"),
PreceedingLinePrefixIndenter(prefix: "when"),
PreceedingLinePrefixIndenter(prefix: "for"),
PreceedingLinePrefixIndenter(prefix: "unless"),
PreceedingLinePrefixIndenter(prefix: "while"),
PreceedingLinePrefixIndenter(prefix: "class"),
PreceedingLinePrefixIndenter(prefix: "module"),
PreceedingLinePrefixIndenter(prefix: "def"),
]
}

/// Specialized indentation patterns for Python.
static let pythonPatterns: [PatternMatcher] = [
PreceedingLineSuffixIndenter(suffix: ":"),
static var pythonPatterns: [PatternMatcher] {
[
PreceedingLineSuffixIndenter(suffix: ":"),

PreceedingLinePrefixIndenter(prefix: "{"),
PreceedingLinePrefixIndenter(prefix: "("),
PreceedingLinePrefixIndenter(prefix: "["),
PreceedingLinePrefixIndenter(prefix: "{"),
PreceedingLinePrefixIndenter(prefix: "("),
PreceedingLinePrefixIndenter(prefix: "["),

PreceedingLineSuffixIndenter(suffix: "{"),
PreceedingLineSuffixIndenter(suffix: "("),
PreceedingLineSuffixIndenter(suffix: "["),
]
PreceedingLineSuffixIndenter(suffix: "{"),
PreceedingLineSuffixIndenter(suffix: "("),
PreceedingLineSuffixIndenter(suffix: "["),
]
}
}
15 changes: 10 additions & 5 deletions Sources/TextFormation/WhitespaceProviders.swift
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,14 @@ public struct WhitespaceProviders {
}

extension WhitespaceProviders {
public static let passthroughProvider: StringSubstitutionProvider = { $1.substring(from: $0) ?? "" }
public static let removeAllProvider: StringSubstitutionProvider = { _, _ in return "" }

public static let none = WhitespaceProviders(leadingWhitespace: WhitespaceProviders.passthroughProvider,
trailingWhitespace: WhitespaceProviders.passthroughProvider)
public static var passthroughProvider: StringSubstitutionProvider {
{ $1.substring(from: $0) ?? "" }
}
public static var removeAllProvider: StringSubstitutionProvider {
{ _, _ in return "" }
}
public static var none: WhitespaceProviders {
WhitespaceProviders(leadingWhitespace: WhitespaceProviders.passthroughProvider,
trailingWhitespace: WhitespaceProviders.passthroughProvider)
}
}

0 comments on commit 5dd8a8d

Please sign in to comment.