From ca906622c2fc0365c1182f935bd503c697116b57 Mon Sep 17 00:00:00 2001 From: Fatih Arslan Date: Sat, 3 Oct 2015 20:33:51 +0300 Subject: [PATCH] lexer: add peek() method --- parser/lexer.go | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/parser/lexer.go b/parser/lexer.go index 95625b9..98e7165 100644 --- a/parser/lexer.go +++ b/parser/lexer.go @@ -38,6 +38,14 @@ func (l *Lexer) next() rune { // unread places the previously read rune back on the reader. func (l *Lexer) unread() { _ = l.src.UnreadRune() } +func (l *Lexer) peek() rune { + prev := l.ch + peekCh := l.next() + l.unread() + l.ch = prev + return peekCh +} + // Scan scans the next token and returns the token and it's literal string. func (l *Lexer) Scan() (tok Token, lit string) { ch := l.next()