lexer: add Lexer.AtLeast() to gather input data from the Feeder

Signed-off-by: Alejandro Mery <amery@jpi.io>
This commit is contained in:
2021-07-04 00:40:22 +01:00
parent 36427e059f
commit 3edf777c68
+17
View File
@@ -16,6 +16,8 @@ type Lexer interface {
Position() TokenPosition // base for the next token
Tokens() <-chan Token // tokens output
AtLeast(n int) ([]rune, error)
NewLine()
Step(n int)
@@ -51,6 +53,21 @@ func (lex *lexer) Run() {
}
}
func (lex *lexer) AtLeast(n int) ([]rune, error) {
min := lex.cursor
if n > 0 {
min += n
}
s, err := lex.in.AtLeast(min)
if len(s) > lex.cursor {
s = s[lex.cursor:]
} else {
s = nil
}
return s, err
}
func (lex *lexer) Position() TokenPosition {
return lex.pos
}