summaryrefslogtreecommitdiff
path: root/conf
diff options
context:
space:
mode:
Diffstat (limited to 'conf')
-rw-r--r--conf/scanner.go24
1 files changed, 20 insertions, 4 deletions
diff --git a/conf/scanner.go b/conf/scanner.go
index 44301fe..74e66e8 100644
--- a/conf/scanner.go
+++ b/conf/scanner.go
@@ -33,6 +33,8 @@ type scanner struct {
data []byte
offset int
curline int
+
+ peeked *token
}
func newScanner(r io.Reader) *scanner {
@@ -55,9 +57,9 @@ func getTokenType(s []byte) tokentype {
switch s[0] {
case '"', '\'':
return Literal
- case '[':
+ case '[', ']':
return ListDelimiter
- case '{':
+ case '{', '}':
return ObjectDelimiter
}
@@ -68,6 +70,11 @@ func (s *scanner) Scan() (token, error) {
processed := 0
tokenstarted := false
oldline := s.curline
+ if s.peeked != nil {
+ ret := *s.peeked
+ s.peeked = nil
+ return ret, nil
+ }
for {
r, rlen := utf8.DecodeRune(s.data[s.offset+processed:])
if r == utf8.RuneError {
@@ -108,6 +115,15 @@ func (s *scanner) Scan() (token, error) {
return ret, nil
}
-func (s *scanner) peek() (tokentype, string, error) {
- return Nothing, "", nil
+func (s *scanner) Peek() (token, error) {
+ if s.peeked != nil {
+ return *s.peeked, nil
+ }
+
+ tok, err := s.Scan()
+ if err != nil {
+ return token{}, err
+ }
+ s.peeked = &tok
+ return tok, nil
}