summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSilvan Jegen <s.jegen@gmail.com>2016-12-11 20:54:34 +0100
committerSilvan Jegen <s.jegen@gmail.com>2016-12-11 20:54:34 +0100
commit8ab189a57a3cce1db56dde190bf354f0c26e9efa (patch)
treeb3ad8c41bd5853fa782cf720f6b64a7997b7c5be
parent26412f3077698dabcdbdf6a6e40276c56a6f74b5 (diff)
Add config parser skeleton
-rw-r--r--conf/scanner.go66
1 files changed, 66 insertions, 0 deletions
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
+}