code: func (p *Lexer) fill() {
  
  	if p.r >= 0 && p.r < bufSize {
  		return
  	}
  
  	// Read new data: try a limited number of times.
  	// The first time read the full buffer, else only half.
  	offset := 0
  	if p.r >= 0 {
  		copy(p.buf, p.buf[halfSize:])
  		p.r = halfSize
  		offset = halfSize
  	} else {
  		p.r = 0
  	}
  
  	for i := maxConsecutiveEmptyReads; i > 0; i-- {
  		n, err := p.rd.Read(p.buf[offset:])
  		if n < 0 {
  			panic(errNegativeRead)
  		}
  		if err != nil {
  			p.err = err
  			break
  		}
  
  		offset += n
  		if offset >= halfSize {
  			break
  		}
  	}
  
  	p.lastByte = offset
  }
docs: // fill reads a new chunk into the buffer.
  //
  // The first time, the buffer is filled completely. After reading the last byte from
  // the buffer, the last half is preserved and moved to the start, and the other
  // half filled with new bytes, if available.