zclsyntax: peeker methods to get next and previous token ranges

This commit is contained in:
Martin Atkins 2017-05-29 19:01:37 -07:00
parent 23cb83ef3e
commit 14d256467a

View File

@ -1,5 +1,9 @@
package zclsyntax
import (
"github.com/zclconf/go-zcl/zcl"
)
type peeker struct {
Tokens Tokens
NextIndex int
@ -28,6 +32,18 @@ func (p *peeker) Read() Token {
return ret
}
func (p *peeker) NextRange() zcl.Range {
return p.Peek().Range
}
func (p *peeker) PrevRange() zcl.Range {
if p.NextIndex == 0 {
return p.NextRange()
}
return p.Tokens[p.NextIndex-1].Range
}
func (p *peeker) nextToken() (Token, int) {
for i := p.NextIndex; i < len(p.Tokens); i++ {
tok := p.Tokens[i]