Skip to content

Commit 2d0370a

Browse files
authored
Public all the things (#6)
1 parent 749cb2f commit 2d0370a

File tree

12 files changed

+118
-74
lines changed

12 files changed

+118
-74
lines changed

Package.resolved

Lines changed: 43 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,7 @@ With Swift Package Manager, put this inside your `Package.swift`:
160160

161161
```swift
162162
.Package(url: "https://github.com/bkase/DoctorPretty.git",
163-
majorVersion: 0, minor: 2)
163+
majorVersion: 0, minor: 3)
164164
```
165165

166166
## How does it work?

Sources/Alignment.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,17 +12,17 @@ import Operadics
1212
// Alignment and Indentation
1313
extension Doc {
1414
/// Indent all lines of the doc by `i`
15-
func indent(_ i: IndentLevel) -> Doc {
15+
public func indent(_ i: IndentLevel) -> Doc {
1616
return (.text(spaces(i)) <> self).hang(i)
1717
}
1818

1919
/// Hanging indentation
20-
func hang(_ i: IndentLevel) -> Doc {
20+
public func hang(_ i: IndentLevel) -> Doc {
2121
return (Doc.nest(i, self)).align()
2222
}
2323

2424
/// Align this document with the nesting level set to the current column
25-
func align() -> Doc {
25+
public func align() -> Doc {
2626
return .column { k in
2727
.nesting { i in .nest(k - i, self) }
2828
}

Sources/Atoms.swift

Lines changed: 24 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -11,49 +11,49 @@ import Operadics
1111

1212
extension Doc {
1313
/// Enclose a doc between left and right
14-
func enclose(left: Doc, right: Doc) -> Doc {
14+
public func enclose(left: Doc, right: Doc) -> Doc {
1515
return left <> self <> right
1616
}
1717

18-
var squotes: Doc {
18+
public var squotes: Doc {
1919
return enclose(left: .squote, right: .squote)
2020
}
2121

22-
var dquotes: Doc {
22+
public var dquotes: Doc {
2323
return enclose(left: .dquote, right: .dquote)
2424
}
2525

26-
var braces: Doc {
26+
public var braces: Doc {
2727
return enclose(left: .lbrace, right: .rbrace)
2828
}
2929

30-
var parens: Doc {
30+
public var parens: Doc {
3131
return enclose(left: .lparen, right: .rparen)
3232
}
3333

34-
var angles: Doc {
34+
public var angles: Doc {
3535
return enclose(left: .langle, right: .rangle)
3636
}
3737

38-
var brackets: Doc {
38+
public var brackets: Doc {
3939
return enclose(left: .lbracket, right: .rbracket)
4040
}
4141

42-
static let squote: Doc = .char("'")
43-
static let dquote: Doc = .char("\"")
44-
static let lbrace: Doc = .char("{")
45-
static let rbrace: Doc = .char("}")
46-
static let lparen: Doc = .char("(")
47-
static let rparen: Doc = .char(")")
48-
static let langle: Doc = .char("<")
49-
static let rangle: Doc = .char(">")
50-
static let lbracket: Doc = .char("[")
51-
static let rbracket: Doc = .char("]")
52-
53-
static let space: Doc = .char(" ")
54-
static let dot: Doc = .char(".")
55-
static let comma: Doc = .char(",")
56-
static let semi: Doc = .char(";")
57-
static let backslash: Doc = .char("\\")
58-
static let equals: Doc = .char("=")
42+
public static let squote: Doc = .char("'")
43+
public static let dquote: Doc = .char("\"")
44+
public static let lbrace: Doc = .char("{")
45+
public static let rbrace: Doc = .char("}")
46+
public static let lparen: Doc = .char("(")
47+
public static let rparen: Doc = .char(")")
48+
public static let langle: Doc = .char("<")
49+
public static let rangle: Doc = .char(">")
50+
public static let lbracket: Doc = .char("[")
51+
public static let rbracket: Doc = .char("]")
52+
53+
public static let space: Doc = .char(" ")
54+
public static let dot: Doc = .char(".")
55+
public static let comma: Doc = .char(",")
56+
public static let semi: Doc = .char(";")
57+
public static let backslash: Doc = .char("\\")
58+
public static let equals: Doc = .char("=")
5959
}

Sources/Doc.swift

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
import Swiftx
22
import Operadics
33

4-
typealias Width = Int
4+
public typealias Width = Int
55
// TODO: What does this int mean, really
6-
typealias ColumnCount = Int
7-
typealias IndentLevel = Int
6+
public typealias ColumnCount = Int
7+
public typealias IndentLevel = Int
88
/// The ribbon width is the maximal amount of non-indentation characters on a line
9-
typealias RibbonWidth = Int
9+
public typealias RibbonWidth = Int
1010

11-
indirect enum Doc {
11+
public indirect enum Doc {
1212
case empty
1313
/// Invariant: char != '\n'
1414
case _char(Character)
@@ -30,34 +30,34 @@ indirect enum Doc {
3030
case columns((ColumnCount?) -> Doc)
3131
case ribbon((RibbonWidth?) -> Doc)
3232

33-
static func char(_ c: Character) -> Doc {
33+
public static func char(_ c: Character) -> Doc {
3434
return c == "\n" ? ._line : ._char(c)
3535
}
3636

37-
static func text(_ str: String) -> Doc {
37+
public static func text(_ str: String) -> Doc {
3838
return str == "" ? .empty : ._text(length: str.characters.count, str)
3939
}
4040

41-
static var line: Doc {
41+
public static var line: Doc {
4242
return .flatAlt(primary: ._line, whenFlattened: .space)
4343
}
4444

45-
static var linebreak: Doc {
45+
public static var linebreak: Doc {
4646
return .flatAlt(primary: ._line, whenFlattened: .zero)
4747
}
4848

49-
static var hardline: Doc {
49+
public static var hardline: Doc {
5050
return ._line
5151
}
5252

5353
/// Used to specify alternative layouts
5454
/// `doc.grouped` removes all line breaks in `doc`. The resulting line
5555
/// is added if it fits on the page. If it doesn't, it's rendered as is
56-
var grouped: Doc {
56+
public var grouped: Doc {
5757
return .union(longerLines: flattened, shorterLines: self)
5858
}
5959

60-
var flattened: Doc {
60+
public var flattened: Doc {
6161
switch self {
6262
case .empty: return self
6363
case ._char(_): return self

Sources/DocMonoid.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,10 @@ import protocol Algebra.Additive
1111
import Operadics
1212

1313
extension Doc: Additive {
14-
static func <>(l: Doc, r: Doc) -> Doc {
14+
public static func <>(l: Doc, r: Doc) -> Doc {
1515
return .concat(l, r)
1616
}
1717

18-
static var zero: Doc { return .empty }
18+
public static var zero: Doc { return .empty }
1919
}
2020

Sources/Enclosed.swift

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,11 @@ import Operadics
1212
extension BidirectionalCollection where Iterator.Element == Doc, IndexDistance == Int, SubSequence.Iterator.Element == Doc {
1313

1414
/// Intersperses punctuation inside docs
15-
func punctuate(with punctuation: Doc) -> [Doc] {
15+
public func punctuate(with punctuation: Doc) -> [Doc] {
1616
if let d = first {
17-
return [d] + self.dropFirst().reduce([]) { acc, d2 in
18-
acc <> [punctuation, d2]
17+
return [d] + self.dropFirst().reduce([Doc]()) { t in
18+
let (acc, d2) = t
19+
return acc <> [punctuation, d2]
1920
}
2021
} else {
2122
return []
@@ -35,7 +36,7 @@ extension BidirectionalCollection where Iterator.Element == Doc, IndexDistance =
3536
/// baz
3637
/// ]
3738
/// Note: The Haskell version sticks the separator at the front
38-
func enclose(left: Doc, right: Doc, separator: Doc, indent: IndentLevel) -> Doc {
39+
public func enclose(left: Doc, right: Doc, separator: Doc, indent: IndentLevel) -> Doc {
3940
if count == 0 {
4041
return left <> right
4142
}
@@ -51,17 +52,17 @@ extension BidirectionalCollection where Iterator.Element == Doc, IndexDistance =
5152
}
5253

5354
/// See @enclose
54-
func list(indent: IndentLevel) -> Doc {
55+
public func list(indent: IndentLevel) -> Doc {
5556
return enclose(left: Doc.lbracket, right: Doc.rbracket, separator: Doc.comma, indent: indent)
5657
}
5758

5859
/// See @enclose
59-
func tupled(indent: IndentLevel) -> Doc {
60+
public func tupled(indent: IndentLevel) -> Doc {
6061
return enclose(left: Doc.lparen, right: Doc.rparen, separator: Doc.comma, indent: indent)
6162
}
6263

6364
/// See @enclose
64-
func semiBraces(indent: IndentLevel) -> Doc {
65+
public func semiBraces(indent: IndentLevel) -> Doc {
6566
return enclose(left: Doc.lbrace, right: Doc.rbrace, separator: Doc.semi, indent: indent)
6667
}
6768
}

Sources/Extras.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,6 @@
88

99
import Foundation
1010

11-
func spaces(_ i: Int) -> String {
11+
public func spaces(_ i: Int) -> String {
1212
return (0..<i).map{ _ in " " }.joined()
1313
}

Sources/Fills.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,16 +12,16 @@ import Operadics
1212
extension Doc {
1313
/// Render doc then fill until width == i
1414
/// If too large, put in a line-break and then pad
15-
func fillBreak(_ i: IndentLevel) -> Doc {
15+
public func fillBreak(_ i: IndentLevel) -> Doc {
1616
return width { w in w > i ? .nest(i, .linebreak) : .text(spaces(i - w)) }
1717
}
1818

1919
/// Render doc then fill until width == i
20-
func fill(_ i: IndentLevel) -> Doc {
20+
public func fill(_ i: IndentLevel) -> Doc {
2121
return width { w in w >= i ? .zero : .text(spaces(i - w)) }
2222
}
2323

24-
func width(_ f: @escaping (IndentLevel) -> Doc) -> Doc {
24+
public func width(_ f: @escaping (IndentLevel) -> Doc) -> Doc {
2525
return .column { k1 in self <> .column { k2 in f(k2 - k1) } }
2626
}
2727
}

0 commit comments

Comments
 (0)