go-parsekit/tokenize/cursor.go

23 lines
558 B
Go

package tokenize
// move updates the position of the cursor, based on the provided input string.
// The input string represents the runes that the cursor must be moved over.
// This method will take newlines into account to keep track of line numbers and
// column positions automatically.
func (f *stackFrame) moveCursor(input string) *stackFrame {
for _, r := range input {
f.moveCursorByRune(r)
}
return f
}
func (f *stackFrame) moveCursorByRune(r rune) *stackFrame {
if r == '\n' {
f.column = 0
f.line++
} else {
f.column++
}
return f
}