lexer: add Lexer.AtLeast() to gather input data from the Feeder
Signed-off-by: Alejandro Mery <amery@jpi.io>
This commit is contained in:
@@ -16,6 +16,8 @@ type Lexer interface {
|
|||||||
Position() TokenPosition // base for the next token
|
Position() TokenPosition // base for the next token
|
||||||
Tokens() <-chan Token // tokens output
|
Tokens() <-chan Token // tokens output
|
||||||
|
|
||||||
|
AtLeast(n int) ([]rune, error)
|
||||||
|
|
||||||
NewLine()
|
NewLine()
|
||||||
Step(n int)
|
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 {
|
func (lex *lexer) Position() TokenPosition {
|
||||||
return lex.pos
|
return lex.pos
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user