go-parsekit/tokenize/api_input.go

34 lines
914 B
Go

package tokenize
import (
"fmt"
)
// Input provides input-related functionality for the tokenize API,
// which is not specifically bound to a specific read mode (byte, rune).
type Input struct {
api *API
}
// Cursor returns a string that describes the current read cursor position.
func (i Input) Cursor() string {
if i.api.pointers.line == 0 && i.api.pointers.column == 0 {
return fmt.Sprintf("start of file")
}
return fmt.Sprintf("line %d, column %d", i.api.pointers.line+1, i.api.pointers.column+1)
}
// Flush flushes input data from the read buffer up to the current
// read cursor position of the tokenizer.
//
// Note: in most cases, you won't have to call this method yourself.
// Parsekit will call this method at points where it knows it is a
// safe thing to do.
func (i Input) Flush() {
a := i.api
if a.pointers.offset > 0 {
a.reader.Flush(a.pointers.offset)
a.pointers.offset = 0
}
}