1package dns 2 3// Implement a simple scanner, return a byte stream from an io reader. 4 5import ( 6 "bufio" 7 "io" 8 "text/scanner" 9) 10 11type scan struct { 12 src *bufio.Reader 13 position scanner.Position 14 eof bool // Have we just seen a eof 15} 16 17func scanInit(r io.Reader) *scan { 18 s := new(scan) 19 s.src = bufio.NewReader(r) 20 s.position.Line = 1 21 return s 22} 23 24// tokenText returns the next byte from the input 25func (s *scan) tokenText() (byte, error) { 26 c, err := s.src.ReadByte() 27 if err != nil { 28 return c, err 29 } 30 // delay the newline handling until the next token is delivered, 31 // fixes off-by-one errors when reporting a parse error. 32 if s.eof == true { 33 s.position.Line++ 34 s.position.Column = 0 35 s.eof = false 36 } 37 if c == '\n' { 38 s.eof = true 39 return c, nil 40 } 41 s.position.Column++ 42 return c, nil 43} 44