From 7a4713a35318a3884238ca112633817809d4d03f Mon Sep 17 00:00:00 2001 From: Alejandro Mery Date: Fri, 24 Oct 2014 07:34:34 +0200 Subject: [PATCH] scanner.Scanner: add StepBack(), Reset() and Skip() methods Signed-off-by: Alejandro Mery --- scanner/scanner.go | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/scanner/scanner.go b/scanner/scanner.go index 2a2676b..7addb55 100644 --- a/scanner/scanner.go +++ b/scanner/scanner.go @@ -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)) {