// 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: %d, 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: %d, token: %q, err: %v\n", p.cur.Type, p.cur.Lit, err) } func (p *parser) module(name string) { } func (p *parser) object() { }