1
1
mirror of https://github.com/github/semantic.git synced 2024-11-28 18:23:44 +03:00

Remove Term.Empty.

This commit is contained in:
Rob Rix 2015-09-29 12:48:53 -04:00
parent 17271ff2ce
commit c3e8d9a801
3 changed files with 24 additions and 41 deletions

View File

@ -4,17 +4,15 @@ public enum Diff: Comparable, CustomDebugStringConvertible, CustomDocConvertible
indirect case Copy(Syntax<Diff>)
public static func Insert(term: Term) -> Diff {
return .Patch(.Empty, term)
return .Patch(Term(.Empty), term)
}
public static func Delete(term: Term) -> Diff {
return .Patch(term, .Empty)
return .Patch(term, Term(.Empty))
}
public init(_ term: Term) {
switch term {
case .Empty:
self = .Empty
case let .Roll(s):
self = .Copy(s.map(Diff.init))
}
@ -55,36 +53,27 @@ public enum Diff: Comparable, CustomDebugStringConvertible, CustomDocConvertible
}
public init(_ a: Term, _ b: Term) {
switch (a, b) {
case (.Empty, .Empty):
self = .Empty
switch (a.syntax, b.syntax) {
case let (.Apply(a, aa), .Apply(b, bb)):
self = .Copy(.Apply(Diff(a, b), Diff.diff(aa, bb)))
case let (.Roll(a), .Roll(b)):
switch (a, b) {
case let (.Apply(a, aa), .Apply(b, bb)):
self = .Copy(.Apply(Diff(a, b), Diff.diff(aa, bb)))
case let (.Abstract(p1, b1), .Abstract(p2, b2)):
self = .Copy(.Abstract(Diff.diff(p1, p2), Diff.diff(b1, b2)))
case let (.Abstract(p1, b1), .Abstract(p2, b2)):
self = .Copy(.Abstract(Diff.diff(p1, p2), Diff.diff(b1, b2)))
case let (.Assign(n1, v1), .Assign(n2, v2)) where n1 == n2:
self = .Copy(.Assign(n2, Diff(v1, v2)))
case let (.Assign(n1, v1), .Assign(n2, v2)) where n1 == n2:
self = .Copy(.Assign(n2, Diff(v1, v2)))
case let (.Variable(n1), .Variable(n2)) where n1 == n2:
self = .Copy(.Variable(n2))
case let (.Variable(n1), .Variable(n2)) where n1 == n2:
self = .Copy(.Variable(n2))
case let (.Literal(v1), .Literal(v2)) where v1 == v2:
self = .Copy(.Literal(v2))
case let (.Literal(v1), .Literal(v2)) where v1 == v2:
self = .Copy(.Literal(v2))
case let (.Group(n1, v1), .Group(n2, v2)):
self = .Copy(.Group(Diff(n1, n2), Diff.diff(v1, v2)))
default:
self = .Patch(Term(a), Term(b))
}
case let (.Group(n1, v1), .Group(n2, v2)):
self = .Copy(.Group(Diff(n1, n2), Diff.diff(v1, v2)))
default:
self = Patch(a, b)
self = .Patch(a, b)
}
}

View File

@ -1,13 +1,5 @@
public func == (left: Term, right: Term) -> Bool {
switch (left, right) {
case (.Empty, .Empty):
return true
case let (.Roll(s), .Roll(t)):
return s == t
default:
return false
}
return left.syntax == right.syntax
}
public func == <F: Equatable> (left: Syntax<F>, right: Syntax<F>) -> Bool {

View File

@ -3,13 +3,17 @@ public enum Term: CustomDebugStringConvertible, CustomDocConvertible, CustomStri
self = .Roll(out)
}
case Empty
indirect case Roll(Syntax<Term>)
public var syntax: Syntax<Term> {
switch self {
case let .Roll(syntax):
return syntax
}
}
public var debugDescription: String {
switch self {
case .Empty:
return ".Empty"
case let .Roll(s):
return s.debugDescription
}
@ -17,8 +21,6 @@ public enum Term: CustomDebugStringConvertible, CustomDocConvertible, CustomStri
public var doc: Doc {
switch self {
case .Empty:
return .Empty
case let .Roll(s):
return s.doc
}