Browse Source

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

Signed-off-by: Alejandro Mery <amery@jpi.io>
v0.2.x
Alejandro Mery 4 years ago
parent
commit
3edf777c68
  1. 17
      lexer/lexer.go

17
lexer/lexer.go

@ -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
}

Loading…
Cancel
Save