mirror of
https://github.com/github/semantic.git
synced 2024-11-27 12:57:49 +03:00
Migrate syntax and stuff.
This commit is contained in:
parent
a3c91b7aa1
commit
264f0943c9
@ -28,10 +28,10 @@ enum Diff: CustomDocConvertible, Equatable {
|
||||
func diff(a: Syntax<Fix>, _ b: Syntax<Fix>) -> Diff {
|
||||
switch (a, b) {
|
||||
case let (.Apply(a, aa), .Apply(b, bb)):
|
||||
return .Copy({ .Apply(diff(a.out, b.out), lazy(zip(aa, bb)).map { ($0.out, $1.out) }.map(diff).array) })
|
||||
return .Copy({ .Apply(diff(a.out, b.out), Array(zip(aa, bb).lazy.map { ($0.out, $1.out) }.map(diff))) })
|
||||
|
||||
case let (.Abstract(p1, b1), .Abstract(p2, b2)):
|
||||
return .Copy({ .Abstract(lazy(zip(p1, p2)).map { ($0.out, $1.out) }.map(diff).array, diff(b1.out, b2.out)) })
|
||||
return .Copy({ .Abstract(Array(zip(p1, p2).lazy.map { ($0.out, $1.out) }.map(diff)), diff(b1.out, b2.out)) })
|
||||
|
||||
case let (.Assign(n1, v1), .Assign(n2, v2)) where n1 == n2:
|
||||
return .Copy({ .Assign(n2, diff(v1.out, v2.out)) })
|
||||
@ -43,7 +43,7 @@ func diff(a: Syntax<Fix>, _ b: Syntax<Fix>) -> Diff {
|
||||
return .Copy({ .Literal(v2) })
|
||||
|
||||
case let (.Group(n1, v1), .Group(n2, v2)):
|
||||
return .Copy({ .Group(diff(n1.out, n2.out), lazy(zip(v1, v2)).map { ($0.out, $1.out) }.map(diff).array) })
|
||||
return .Copy({ .Group(diff(n1.out, n2.out), Array(zip(v1, v2).lazy.map { ($0.out, $1.out) }.map(diff))) })
|
||||
|
||||
default:
|
||||
return .Patch(a, b)
|
||||
|
@ -32,13 +32,13 @@ enum Doc<Payload>: AlgebraicType, CustomStringConvertible {
|
||||
case let .Text(s):
|
||||
return s
|
||||
case let .Horizontal(a):
|
||||
return "".join(lazy(a).map { String($0) })
|
||||
return a.lazy.map { String($0) }.joinWithSeparator("")
|
||||
case let .Vertical(a):
|
||||
return "\n".join(lazy(a).map { String($0) })
|
||||
return a.lazy.map { String($0) }.joinWithSeparator("\n")
|
||||
case let .Wrap(open, body, close):
|
||||
return "\(String(open))\(String(body))\(String(close))"
|
||||
case let .Join(separator, elements):
|
||||
return String(separator).join(elements.map { String($0) })
|
||||
return elements.map { String($0) }.joinWithSeparator(String(separator))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,9 +1,9 @@
|
||||
extension String {
|
||||
func from(offset: String.Index.Distance) -> String {
|
||||
return String(characters[advance(startIndex, offset, endIndex)..<endIndex])
|
||||
return String(characters[startIndex.advancedBy(offset, limit: endIndex)..<endIndex])
|
||||
}
|
||||
|
||||
func to(offset: String.Index.Distance) -> String {
|
||||
return String(characters[startIndex..<advance(startIndex, offset, endIndex)])
|
||||
return String(characters[startIndex..<startIndex.advancedBy(offset, limit: endIndex)])
|
||||
}
|
||||
}
|
||||
|
@ -55,10 +55,10 @@ enum Syntax<Payload>: AlgebraicType, CustomDebugStringConvertible, CustomDocConv
|
||||
var debugDescription: String {
|
||||
switch self {
|
||||
case let .Apply(f, vs):
|
||||
let s = ", ".join(vs.map { String($0) })
|
||||
let s = vs.map { String($0) }.joinWithSeparator(", ")
|
||||
return ".Apply(\(f), [ \(s) ])"
|
||||
case let .Abstract(parameters, body):
|
||||
let s = ", ".join(parameters.map { String($0) })
|
||||
let s = parameters.map { String($0) }.joinWithSeparator(", ")
|
||||
return ".Abstract([ \(s) ], \(body))"
|
||||
case let .Assign(n, v):
|
||||
return ".Assign(\(n), \(v))"
|
||||
@ -67,7 +67,7 @@ enum Syntax<Payload>: AlgebraicType, CustomDebugStringConvertible, CustomDocConv
|
||||
case let .Literal(s):
|
||||
return ".Literal(\(s))"
|
||||
case let .Group(n, vs):
|
||||
let s = ", ".join(vs.map { String($0) })
|
||||
let s = vs.map { String($0) }.joinWithSeparator(", ")
|
||||
return ".Group(\(n), [ \(s) ])"
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user