40 lines
999 B
Go
40 lines
999 B
Go
package tokenize
|
|
|
|
import (
|
|
"fmt"
|
|
|
|
"git.makaay.nl/mauricem/go-parsekit/read"
|
|
)
|
|
|
|
// 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
|
|
reader *read.Buffer // the buffered input reader
|
|
}
|
|
|
|
// Cursor returns a string that describes the current read cursor position.
|
|
func (i Input) Cursor() string {
|
|
f := i.api.stackFrame
|
|
if f.line == 0 && f.column == 0 {
|
|
return fmt.Sprintf("start of file")
|
|
}
|
|
return fmt.Sprintf("line %d, column %d", f.line+1, f.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() bool {
|
|
f := i.api.stackFrame
|
|
if f.offset > 0 {
|
|
i.reader.Flush(f.offset)
|
|
f.offset = 0
|
|
return true
|
|
}
|
|
return false
|
|
}
|