While looking through the code, I noticed that the lexer runs its main loop its own goroutine:
func lex(input string) (*lexer, error) {
...
l := &lexer{
input: input,
items: make(chan item),
}
go l.run()
return l, nil
}
Items are then received from the unbuffered channel l.items , thus making the code run fully sequential again.
Is there any other good reason to run it in it's own goroutine? If not, the overhead for synchronization and context switches could be avoided.