31 lines
655 B
Go
31 lines
655 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) {
|
|
if r == '\n' {
|
|
f.column = 0
|
|
f.line++
|
|
} else {
|
|
f.column++
|
|
}
|
|
}
|
|
|
|
func (f *stackFrame) moveCursorByByte(b byte) {
|
|
if b == '\n' {
|
|
f.column = 0
|
|
f.line++
|
|
} else {
|
|
f.column++
|
|
}
|
|
}
|