From 14d256467aa8df8a457c9a306989bf7fbf47c36c Mon Sep 17 00:00:00 2001 From: Martin Atkins Date: Mon, 29 May 2017 19:01:37 -0700 Subject: [PATCH] zclsyntax: peeker methods to get next and previous token ranges --- zcl/zclsyntax/peeker.go | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/zcl/zclsyntax/peeker.go b/zcl/zclsyntax/peeker.go index f26f1cc..f6fe48c 100644 --- a/zcl/zclsyntax/peeker.go +++ b/zcl/zclsyntax/peeker.go @@ -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]