Understand position tracking with go/token.Pos
maingopatch uses the standard Go go/token package for position tracking.
- FileSet: A collection of files. It tracks the total length of all files combined.
- Pos: An
int64that acts as a pointer into aFileSet. It provides a cheap way to identify a file, line number, and column number.
Because Pos is an integer, gopatch can perform arithmetic on it to move between offsets. When transformations add or remove characters, gopatch generates PosAdjustments to ensure that subsequent parsing logic correctly maps positions back to the original source code.