Skip to content

Commit

Permalink
Add RefDiff
Browse files Browse the repository at this point in the history
  • Loading branch information
Jonathan Gordon authored and Jonathan Gordon committed Mar 25, 2020
1 parent 65c8240 commit ffdc141
Showing 1 changed file with 19 additions and 0 deletions.
19 changes: 19 additions & 0 deletions parser/diff/terms.go
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,8 @@ func DiffTerms(a, b parser.Term) TermDiff {
return DiffTerms(a.Term, b.(parser.CutPoint).Term)
case parser.ExtRef:
return diffSes(parser.S(string(a)), parser.S(string(a)))
case parser.REF:
return diffRefs(a, b.(parser.REF))
default:
panic(fmt.Errorf("unknown term type: %v %[1]T", a))
}
Expand Down Expand Up @@ -161,6 +163,23 @@ func diffREs(a, b parser.RE) REDiff {

//-----------------------------------------------------------------------------

type RefDiff struct {
A, B parser.REF
}

func (d RefDiff) Equal() bool {
if d.A.Ident == d.B.Ident {
return (d.A.Default == nil && d.B.Default == nil) || DiffTerms(d.A.Default, d.B.Default).Equal()
}
return false
}

func diffRefs(a, b parser.REF) RefDiff {
return RefDiff{A: a, B: b}
}

//-----------------------------------------------------------------------------

type termsesDiff struct {
Len InterfaceDiff
Terms []TermDiff
Expand Down

0 comments on commit ffdc141

Please sign in to comment.