NextLine loads the next token only if it is not on the same line as the current token, and returns true if a token was loaded; false otherwise. If false, there is not another token or it is on the same line. It handles imported tokens correctly.
()
| 105 | // loaded; false otherwise. If false, there is not another token |
| 106 | // or it is on the same line. It handles imported tokens correctly. |
| 107 | func (d *Dispenser) NextLine() bool { |
| 108 | if d.cursor < 0 { |
| 109 | d.cursor++ |
| 110 | return true |
| 111 | } |
| 112 | if d.cursor >= len(d.tokens) { |
| 113 | return false |
| 114 | } |
| 115 | if d.cursor < len(d.tokens)-1 && |
| 116 | (d.tokens[d.cursor].File != d.tokens[d.cursor+1].File || |
| 117 | d.tokens[d.cursor].Line+d.numLineBreaks(d.cursor) < d.tokens[d.cursor+1].Line) { |
| 118 | d.cursor++ |
| 119 | return true |
| 120 | } |
| 121 | return false |
| 122 | } |
| 123 | |
| 124 | // NextBlock can be used as the condition of a for loop |
| 125 | // to load the next token as long as it opens a block or |