1
1
mirror of https://github.com/github/semantic.git synced 2024-11-27 12:57:49 +03:00

Syntax, Fix, Doc, and Pretty are public.

This commit is contained in:
Rob Rix 2015-09-11 10:17:19 -04:00
parent d118fc5dfe
commit 29e3aaf361
3 changed files with 35 additions and 35 deletions

View File

@ -1,4 +1,4 @@
enum Doc<Payload>: AlgebraicType, CustomStringConvertible {
public enum Doc<Payload>: AlgebraicType, CustomStringConvertible {
case Empty
case Text(String)
case Horizontal([Payload])
@ -6,7 +6,7 @@ enum Doc<Payload>: AlgebraicType, CustomStringConvertible {
case Wrap(Payload, Payload, Payload)
case Join(Payload, [Payload])
func map<Other>(@noescape transform: Payload -> Other) -> Doc<Other> {
public func map<Other>(@noescape transform: Payload -> Other) -> Doc<Other> {
switch self {
case .Empty:
return .Empty
@ -23,9 +23,9 @@ enum Doc<Payload>: AlgebraicType, CustomStringConvertible {
}
}
typealias Recur = Payload
public typealias Recur = Payload
var description: String {
public var description: String {
switch self {
case .Empty:
return ""
@ -44,51 +44,51 @@ enum Doc<Payload>: AlgebraicType, CustomStringConvertible {
}
struct Pretty: CustomStringConvertible, Equatable, FixpointType {
init<T>(_ value: T) {
public struct Pretty: CustomStringConvertible, Equatable, FixpointType {
public init<T>(_ value: T) {
self.init((value as? CustomDocConvertible)?.doc ?? .Text(String(value)))
}
init(_ doc: Doc<Pretty>) {
public init(_ doc: Doc<Pretty>) {
self.init { doc }
}
init(_ doc: () -> Doc<Pretty>) {
public init(_ doc: () -> Doc<Pretty>) {
self.doc = doc
}
let doc: () -> Doc<Pretty>
var out: Doc<Pretty> {
public var out: Doc<Pretty> {
return doc()
}
var description: String {
public var description: String {
return out.description
}
static let Empty = Pretty(Doc<Pretty>.Empty)
static let Text = Doc<Pretty>.Text >>> Pretty.init
static let Horizontal = Doc<Pretty>.Horizontal >>> Pretty.init
static let Vertical = Doc<Pretty>.Vertical >>> Pretty.init
static let Wrap = Doc<Pretty>.Wrap >>> Pretty.init
public static let Empty = Pretty(Doc<Pretty>.Empty)
public static let Text = Doc<Pretty>.Text >>> Pretty.init
public static let Horizontal = Doc<Pretty>.Horizontal >>> Pretty.init
public static let Vertical = Doc<Pretty>.Vertical >>> Pretty.init
public static let Wrap = Doc<Pretty>.Wrap >>> Pretty.init
static func Wrap(open: Pretty, _ body: Pretty, _ close: Pretty) -> Pretty {
public static func Wrap(open: Pretty, _ body: Pretty, _ close: Pretty) -> Pretty {
return Pretty(.Wrap(open, body, close))
}
static func Join(separator: Pretty, _ elements: [Pretty]) -> Pretty {
public static func Join(separator: Pretty, _ elements: [Pretty]) -> Pretty {
return Pretty(.Join(separator, elements))
}
}
protocol CustomDocConvertible: CustomStringConvertible {
public protocol CustomDocConvertible: CustomStringConvertible {
var doc: Doc<Pretty> { get }
}
extension CustomDocConvertible {
var description: String {
public var description: String {
return doc.description
}
}

View File

@ -1,8 +1,8 @@
func == (left: Fix, right: Fix) -> Bool {
public func == (left: Fix, right: Fix) -> Bool {
return left.out == right.out
}
func == <F: Equatable> (left: Syntax<F>, right: Syntax<F>) -> Bool {
public func == <F: Equatable> (left: Syntax<F>, right: Syntax<F>) -> Bool {
switch (left, right) {
case let (.Apply(a, aa), .Apply(b, bb)):
return a == b && aa == bb
@ -32,7 +32,7 @@ func == (left: Diff, right: Diff) -> Bool {
}
}
func == <F: Equatable> (left: Doc<F>, right: Doc<F>) -> Bool {
public func == <F: Equatable> (left: Doc<F>, right: Doc<F>) -> Bool {
switch (left, right) {
case (.Empty, .Empty):
return true
@ -51,6 +51,6 @@ func == <F: Equatable> (left: Doc<F>, right: Doc<F>) -> Bool {
}
}
func == (left: Pretty, right: Pretty) -> Bool {
public func == (left: Pretty, right: Pretty) -> Bool {
return left.out == right.out
}

View File

@ -1,31 +1,31 @@
struct Fix: CustomDebugStringConvertible, CustomDocConvertible, CustomStringConvertible, Equatable, FixpointType {
init(_ roll: () -> Syntax<Fix>) {
public struct Fix: CustomDebugStringConvertible, CustomDocConvertible, CustomStringConvertible, Equatable, FixpointType {
public init(_ roll: () -> Syntax<Fix>) {
self.roll = roll
}
init(_ out: Syntax<Fix>) {
public init(_ out: Syntax<Fix>) {
self.init { out }
}
let roll: () -> Syntax<Fix>
var out: Syntax<Fix> {
public var out: Syntax<Fix> {
return roll()
}
var debugDescription: String {
public var debugDescription: String {
return cata { String(reflecting: $0) } (self)
}
var doc: Doc<Pretty> {
public var doc: Doc<Pretty> {
return cata { (syntax: Syntax<Doc<Pretty>>) in syntax.doc } (self)
}
var description: String {
public var description: String {
return cata { String($0) } (self)
}
}
enum Syntax<Payload>: AlgebraicType, CustomDebugStringConvertible, CustomDocConvertible {
public enum Syntax<Payload>: AlgebraicType, CustomDebugStringConvertible, CustomDocConvertible {
case Apply(Payload, [Payload])
case Abstract([Payload], Payload)
case Assign(String, Payload)
@ -33,7 +33,7 @@ enum Syntax<Payload>: AlgebraicType, CustomDebugStringConvertible, CustomDocConv
case Literal(String)
case Group(Payload, [Payload])
func map<T>(@noescape transform: Payload -> T) -> Syntax<T> {
public func map<T>(@noescape transform: Payload -> T) -> Syntax<T> {
switch self {
case let .Apply(f, args):
return .Apply(transform(f), args.map(transform))
@ -50,9 +50,9 @@ enum Syntax<Payload>: AlgebraicType, CustomDebugStringConvertible, CustomDocConv
}
}
typealias Recur = Payload
public typealias Recur = Payload
var debugDescription: String {
public var debugDescription: String {
switch self {
case let .Apply(f, vs):
let s = vs.map { String($0) }.joinWithSeparator(", ")
@ -72,7 +72,7 @@ enum Syntax<Payload>: AlgebraicType, CustomDebugStringConvertible, CustomDocConv
}
}
var doc: Doc<Pretty> {
public var doc: Doc<Pretty> {
switch self {
case let .Apply(f, vs):
return .Horizontal([