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