1
1
mirror of https://github.com/github/semantic.git synced 2024-11-23 16:37:50 +03:00

Diff uses indirect.

This commit is contained in:
Rob Rix 2015-09-11 11:40:01 -04:00
parent 367e3b0ebc
commit 5b6fc850f9
2 changed files with 10 additions and 10 deletions

View File

@ -1,6 +1,6 @@
public enum Diff: CustomDocConvertible, Equatable {
case Patch(Fix, Fix)
case Copy(() -> Syntax<Diff>)
indirect case Copy(Syntax<Diff>)
public var doc: Doc<Pretty> {
switch self {
@ -10,7 +10,7 @@ public enum Diff: CustomDocConvertible, Equatable {
.Wrap(Pretty.Text("{+"), Pretty(b.doc), Pretty.Text("+}"))
])
case let .Copy(a):
return a().doc
return a.doc
}
}
@ -19,29 +19,29 @@ public enum Diff: CustomDocConvertible, Equatable {
case let .Patch(a, b):
return ".Patch(\(a), \(b))"
case let .Copy(a):
return ".Copy(\(a()))"
return ".Copy(\(a))"
}
}
public init(_ a: Fix, _ b: Fix) {
switch (a.out, b.out) {
case let (.Apply(a, aa), .Apply(b, bb)):
self = .Copy({ .Apply(Diff(a, b), Array(zip(aa, bb).lazy.map(Diff.init))) })
self = .Copy(.Apply(Diff(a, b), Array(zip(aa, bb).lazy.map(Diff.init))))
case let (.Abstract(p1, b1), .Abstract(p2, b2)):
self = .Copy({ .Abstract(Array(zip(p1, p2).lazy.map(Diff.init)), Diff(b1, b2)) })
self = .Copy(.Abstract(Array(zip(p1, p2).lazy.map(Diff.init)), Diff(b1, b2)))
case let (.Assign(n1, v1), .Assign(n2, v2)) where n1 == n2:
self = .Copy({ .Assign(n2, Diff(v1, v2)) })
self = .Copy(.Assign(n2, Diff(v1, v2)))
case let (.Variable(n1), .Variable(n2)) where n1 == n2:
self = .Copy({ .Variable(n2) })
self = .Copy(.Variable(n2))
case let (.Literal(v1), .Literal(v2)) where v1 == v2:
self = .Copy({ .Literal(v2) })
self = .Copy(.Literal(v2))
case let (.Group(n1, v1), .Group(n2, v2)):
self = .Copy({ .Group(Diff(n1, n2), Array(zip(v1, v2).lazy.map(Diff.init))) })
self = .Copy(.Group(Diff(n1, n2), Array(zip(v1, v2).lazy.map(Diff.init))))
default:
self = .Patch(a, b)

View File

@ -26,7 +26,7 @@ public func == (left: Diff, right: Diff) -> Bool {
case let (.Patch(a1, b1), .Patch(a2, b2)):
return a1 == a2 && b1 == b2
case let (.Copy(a), .Copy(b)):
return a() == b()
return a == b
default:
return false
}