summaryrefslogtreecommitdiff
path: root/conf/scanner.go
blob: 172103f173caaf4de4c40535149a5f73b07d7a5d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
package conf

import (
	"bufio"
	"io"
)

type tokentype int

const (
	Name tokentype = iota
	Literal
	Delimiter
	Nothing
	IfStatement
)

type token struct {
	Type tokentype
}

type scanner struct {
	r    io.Reader
	bs   bufio.Scanner
	prev token
	cur  token
}

func newScanner(r io.Reader) *scanner {
	ns := bufio.NewScanner(r)
	ns.Split(bufio.ScanWords)

	sc := scanner{
		r:  r,
		bs: *ns,
	}

	return &sc
}

func getTokenType(s string) tokentype {
	return Nothing
}

func (s *scanner) Next() (tokentype, string, error) {
	more := s.bs.Scan()
	if !more {
		err := s.bs.Err()
		if err != nil {
			return Nothing, "", err
		}
		return Nothing, "", io.EOF
	}
	tokstr := s.bs.Text()
	token := getTokenType(tokstr)

	return token, tokstr, nil
}

func (s *scanner) peek() (tokentype, string, error) {
	return Nothing, "", nil
}