mirror of
https://github.com/hanzoai/eval.git
synced 2026-09-30 21:47:09 +00:00
Module path renamed to github.com/hanzoai/eval and the Go package renamed from govaluate to eval. Evaluation, parsing, lexing, and operator behavior are unchanged; MIT license and George Lester attribution retained. See NOTICE for lineage.
38 lines
623 B
Go
38 lines
623 B
Go
package eval
|
|
|
|
type lexerStream struct {
|
|
source []rune
|
|
position int
|
|
length int
|
|
}
|
|
|
|
func newLexerStream(source string) *lexerStream {
|
|
|
|
var ret *lexerStream
|
|
var runes []rune
|
|
|
|
for _, character := range source {
|
|
runes = append(runes, character)
|
|
}
|
|
|
|
ret = new(lexerStream)
|
|
ret.source = runes
|
|
ret.length = len(runes)
|
|
return ret
|
|
}
|
|
|
|
func (this *lexerStream) readCharacter() rune {
|
|
|
|
character := this.source[this.position]
|
|
this.position += 1
|
|
return character
|
|
}
|
|
|
|
func (this *lexerStream) rewind(amount int) {
|
|
this.position -= amount
|
|
}
|
|
|
|
func (this lexerStream) canRead() bool {
|
|
return this.position < this.length
|
|
}
|