From 8ab189a57a3cce1db56dde190bf354f0c26e9efa Mon Sep 17 00:00:00 2001 From: Silvan Jegen Date: Sun, 11 Dec 2016 20:54:34 +0100 Subject: Add config parser skeleton --- conf/scanner.go | 66 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 66 insertions(+) create mode 100644 conf/scanner.go diff --git a/conf/scanner.go b/conf/scanner.go new file mode 100644 index 0000000..fd2a3cf --- /dev/null +++ b/conf/scanner.go @@ -0,0 +1,66 @@ +package conf + +import ( + "bufio" + "io" +) + +type token int + +const ( + Name token = iota + Delimiter token = iota + Nothing token = iota + IfStatement token = iota +) + +// Having a Config to Manager function could be nice? +// Or we could just return a Manager from here. +type Config struct { +} + +type scanner struct { + r io.Reader + ss bufio.Scanner + prev token + cur token +} + +func NewConfig(r io.Reader) *Config { + br := bufio.NewReader(r) + s := newScanner(br) + s.next() + + return &Config{} +} + +func newScanner(r io.Reader) *scanner { + ns := bufio.NewScanner(r) + ns.Split(bufio.ScanWords) + + sc := scanner{ + r: r, + ss: *ns, + } + + return &sc +} + +func getTokenType(s string) token { + return Nothing +} + +func (s *scanner) next() (token, string, error) { + stop := s.ss.Scan() + if stop { + return Nothing, "", s.ss.Err() + } + tokstr := s.ss.Text() + token := getTokenType(tokstr) + + return token, tokstr, nil +} + +func (s *scanner) peek() (token, string, error) { + return Nothing, "", nil +} -- cgit v1.2.3