2017-05-15 15:34:00 +00:00
|
|
|
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 {
|
2017-05-16 02:37:33 +00:00
|
|
|
ret := p.tokens[p.pos]
|
|
|
|
if ret.Type != tokenEOF {
|
2017-05-15 15:34:00 +00:00
|
|
|
p.pos++
|
|
|
|
}
|
2017-05-16 02:37:33 +00:00
|
|
|
return ret
|
2017-05-15 15:34:00 +00:00
|
|
|
}
|