summaryrefslogtreecommitdiff
path: root/conf/parser.go
blob: 4f5871304a9cf7bd8581744ca217e28e45401f67 (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
63
// grammar of the config file
//
// config = module module module
// module = name object
// name = 'input' | 'filter' | 'etc.'
// object = '{' keyvalue | keyvalue | ... '}'
// keyvalue = statement '=>' value
// statement = name | if
// value = literal | '[' literal ']'
// literal = '"' name '"'

package conf

import (
	"fmt"
	"io"
	"os"
)

// Having a Config to Manager function could be nice?
// Or we could just return a Manager from here.
type Config struct {
}

type parser struct {
	s    scanner
	last token
	cur  token
}

func newParser(s *scanner) *parser {
	p := &parser{
		s: *s,
	}

	return p
}

func NewConfig(r io.Reader) *Config {
	p := newParser(newScanner(r))
	p.startparsing()

	return &Config{}
}

func (p *parser) startparsing() {
	var err error

	p.last = p.cur
	p.cur, err = p.s.Scan()
	for err == nil {
		fmt.Fprintf(os.Stderr, "tokentype: %v, token: %q offset: %d, line: %d\n", p.cur.Type, p.cur.Lit, p.cur.Offset, p.cur.LineNr)
		p.last = p.cur
		p.cur, err = p.s.Scan()
	}
	fmt.Fprintf(os.Stderr, "Error: tokentype: %v, token: %q, err: %v\n", p.cur.Type, p.cur.Lit, err)
}

func (p *parser) module(name string) {
}

func (p *parser) object() {
}