mirror of
https://github.com/github/semantic.git
synced 2024-12-01 09:15:01 +03:00
Remove Term.Empty.
This commit is contained in:
parent
17271ff2ce
commit
c3e8d9a801
@ -4,17 +4,15 @@ public enum Diff: Comparable, CustomDebugStringConvertible, CustomDocConvertible
|
|||||||
indirect case Copy(Syntax<Diff>)
|
indirect case Copy(Syntax<Diff>)
|
||||||
|
|
||||||
public static func Insert(term: Term) -> Diff {
|
public static func Insert(term: Term) -> Diff {
|
||||||
return .Patch(.Empty, term)
|
return .Patch(Term(.Empty), term)
|
||||||
}
|
}
|
||||||
|
|
||||||
public static func Delete(term: Term) -> Diff {
|
public static func Delete(term: Term) -> Diff {
|
||||||
return .Patch(term, .Empty)
|
return .Patch(term, Term(.Empty))
|
||||||
}
|
}
|
||||||
|
|
||||||
public init(_ term: Term) {
|
public init(_ term: Term) {
|
||||||
switch term {
|
switch term {
|
||||||
case .Empty:
|
|
||||||
self = .Empty
|
|
||||||
case let .Roll(s):
|
case let .Roll(s):
|
||||||
self = .Copy(s.map(Diff.init))
|
self = .Copy(s.map(Diff.init))
|
||||||
}
|
}
|
||||||
@ -55,12 +53,7 @@ public enum Diff: Comparable, CustomDebugStringConvertible, CustomDocConvertible
|
|||||||
}
|
}
|
||||||
|
|
||||||
public init(_ a: Term, _ b: Term) {
|
public init(_ a: Term, _ b: Term) {
|
||||||
switch (a, b) {
|
switch (a.syntax, b.syntax) {
|
||||||
case (.Empty, .Empty):
|
|
||||||
self = .Empty
|
|
||||||
|
|
||||||
case let (.Roll(a), .Roll(b)):
|
|
||||||
switch (a, b) {
|
|
||||||
case let (.Apply(a, aa), .Apply(b, bb)):
|
case let (.Apply(a, aa), .Apply(b, bb)):
|
||||||
self = .Copy(.Apply(Diff(a, b), Diff.diff(aa, bb)))
|
self = .Copy(.Apply(Diff(a, b), Diff.diff(aa, bb)))
|
||||||
|
|
||||||
@ -80,11 +73,7 @@ public enum Diff: Comparable, CustomDebugStringConvertible, CustomDocConvertible
|
|||||||
self = .Copy(.Group(Diff(n1, n2), Diff.diff(v1, v2)))
|
self = .Copy(.Group(Diff(n1, n2), Diff.diff(v1, v2)))
|
||||||
|
|
||||||
default:
|
default:
|
||||||
self = .Patch(Term(a), Term(b))
|
self = .Patch(a, b)
|
||||||
}
|
|
||||||
|
|
||||||
default:
|
|
||||||
self = Patch(a, b)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,13 +1,5 @@
|
|||||||
public func == (left: Term, right: Term) -> Bool {
|
public func == (left: Term, right: Term) -> Bool {
|
||||||
switch (left, right) {
|
return left.syntax == right.syntax
|
||||||
case (.Empty, .Empty):
|
|
||||||
return true
|
|
||||||
case let (.Roll(s), .Roll(t)):
|
|
||||||
return s == t
|
|
||||||
|
|
||||||
default:
|
|
||||||
return false
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public func == <F: Equatable> (left: Syntax<F>, right: Syntax<F>) -> Bool {
|
public func == <F: Equatable> (left: Syntax<F>, right: Syntax<F>) -> Bool {
|
||||||
|
@ -3,13 +3,17 @@ public enum Term: CustomDebugStringConvertible, CustomDocConvertible, CustomStri
|
|||||||
self = .Roll(out)
|
self = .Roll(out)
|
||||||
}
|
}
|
||||||
|
|
||||||
case Empty
|
|
||||||
indirect case Roll(Syntax<Term>)
|
indirect case Roll(Syntax<Term>)
|
||||||
|
|
||||||
|
public var syntax: Syntax<Term> {
|
||||||
|
switch self {
|
||||||
|
case let .Roll(syntax):
|
||||||
|
return syntax
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public var debugDescription: String {
|
public var debugDescription: String {
|
||||||
switch self {
|
switch self {
|
||||||
case .Empty:
|
|
||||||
return ".Empty"
|
|
||||||
case let .Roll(s):
|
case let .Roll(s):
|
||||||
return s.debugDescription
|
return s.debugDescription
|
||||||
}
|
}
|
||||||
@ -17,8 +21,6 @@ public enum Term: CustomDebugStringConvertible, CustomDocConvertible, CustomStri
|
|||||||
|
|
||||||
public var doc: Doc {
|
public var doc: Doc {
|
||||||
switch self {
|
switch self {
|
||||||
case .Empty:
|
|
||||||
return .Empty
|
|
||||||
case let .Roll(s):
|
case let .Roll(s):
|
||||||
return s.doc
|
return s.doc
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user