Document and enforce parser invariants

After considering fragment parsing, it made sense to change the
invariant estabilished in the previous commit. Specifically, parser
functions now assume they are call on the first line of their object and
return with the parser on the first line after their object. This means
code can call parse function immediately after each other without
advancing the parser in between.

It's possible this will change back later on... there seem to be
annoying edge cases with either choice, but I think making the functions
consistent is important.
This commit is contained in:
Billy Keyes
2019-03-27 22:41:37 -07:00
parent e04aad2256
commit 9b0fc30459
5 changed files with 110 additions and 78 deletions
+6
View File
@@ -1,6 +1,7 @@
package gitdiff
import (
"fmt"
"os"
)
@@ -35,3 +36,8 @@ type Fragment struct {
NewPosition int64
NewLines int64
}
// Header returns the cannonical header of this fragment.
func (f *Fragment) Header() string {
return fmt.Sprintf("@@ -%d,%d +%d,%d @@ %s", f.OldPosition, f.OldLines, f.NewPosition, f.NewLines, f.Comment)
}