hcl/zcl/json/peeker.go
Martin Atkins 838a0332e6 json: token peeker
This will help our hand-written recursive-descent parser walk the tokens
with one token of lookahead.
2017-05-15 08:34:00 -07:00

25 lines
330 B
Go

package json
type peeker struct {
tokens []token
pos int
}
func newPeeker(tokens []token) *peeker {
return &peeker{
tokens: tokens,
pos: 0,
}
}
func (p *peeker) Peek() token {
return p.tokens[p.pos]
}
func (p *peeker) Read() token {
if p.tokens[p.pos].Type != tokenEOF {
p.pos++
}
return p.tokens[p.pos]
}