Esempio n. 1
0
func (l *Lexer) next() (r rune) {
	if l.pos >= len(l.input) {
		l.tokens <- tokens.NewToken(tokens.T_EOF, "", 0, 0)
		l.width = 0
		return 0
	}

	r, l.width = utf8.DecodeRuneInString(l.input[l.pos:])
	l.pos += l.width

	if r == '\n' {
		l.column = 0
		l.line++
	} else {
		l.column++
	}

	return r
}
Esempio n. 2
0
func (l *Lexer) emit(t tokens.TokenType) {
	token := tokens.NewToken(t, l.input[l.start:(l.pos-1)], l.line, l.column)
	l.tokens <- token
	l.start = l.pos
}