Next advances the parser by one line. It returns any error encountered while reading the line, including io.EOF when the end of stream is reached.
()
| 93 | // Next advances the parser by one line. It returns any error encountered while |
| 94 | // reading the line, including io.EOF when the end of stream is reached. |
| 95 | func (p *parser) Next() error { |
| 96 | if p.eof { |
| 97 | return io.EOF |
| 98 | } |
| 99 | |
| 100 | if p.lineno == 0 { |
| 101 | // on first call to next, need to shift in all lines |
| 102 | for i := 0; i < len(p.lines)-1; i++ { |
| 103 | if err := p.shiftLines(); err != nil && err != io.EOF { |
| 104 | return err |
| 105 | } |
| 106 | } |
| 107 | } |
| 108 | |
| 109 | err := p.shiftLines() |
| 110 | if err != nil && err != io.EOF { |
| 111 | return err |
| 112 | } |
| 113 | |
| 114 | p.lineno++ |
| 115 | if p.lines[0] == "" { |
| 116 | p.eof = true |
| 117 | return io.EOF |
| 118 | } |
| 119 | return nil |
| 120 | } |
| 121 | |
| 122 | func (p *parser) shiftLines() (err error) { |
| 123 | for i := 0; i < len(p.lines)-1; i++ { |