scanner.Scanner: add StepBack(), Reset() and Skip() methods

Signed-off-by: Alejandro Mery <amery@geeks.cl>
This commit is contained in:
2014-10-24 07:34:34 +02:00
parent d4dbc28aee
commit 7a4713a353
+20
View File
@@ -54,6 +54,26 @@ func (l *Scanner) StepForth(runes, bytes uint) {
l.runes += runes
}
// Move cursor backward
func (l *Scanner) StepBack(runes, bytes uint) {
l.cursor.Offset -= bytes
// FIXME: what if column goes < 1?
l.cursor.Column -= runes
l.runes -= runes
}
// Moves the cursor back to the back
func (l *Scanner) Reset() {
l.cursor = l.base
l.runes = 0
}
// Trashes everything up to the cursor
func (l *Scanner) Skip() {
l.base = l.cursor
l.runes = 0
}
// Return the next rune but not moving the cursor
func (l *Scanner) Peek() (rune, uint) {
if l.cursor.Offset == uint(len(l.input)) {