summaryrefslogtreecommitdiff
path: root/conf
diff options
context:
space:
mode:
Diffstat (limited to 'conf')
-rw-r--r--conf/parser.go28
-rw-r--r--conf/scanner.go46
2 files changed, 49 insertions, 25 deletions
diff --git a/conf/parser.go b/conf/parser.go
new file mode 100644
index 0000000..21bc604
--- /dev/null
+++ b/conf/parser.go
@@ -0,0 +1,28 @@
+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 {
+ scanner
+}
+
+func NewConfig(r io.Reader) *Config {
+ s := newScanner(r)
+ tt, tok, err := s.Next()
+ for err == nil {
+ fmt.Fprintf(os.Stderr, "tokentype: %d, token: %q, err: %v\n", tt, tok, err)
+ tt, tok, err = s.Next()
+ }
+ fmt.Fprintf(os.Stderr, "Error: tokentype: %d, token: %q, err: %v\n", tt, tok, err)
+
+ return &Config{}
+}
diff --git a/conf/scanner.go b/conf/scanner.go
index fd2a3cf..172103f 100644
--- a/conf/scanner.go
+++ b/conf/scanner.go
@@ -5,62 +5,58 @@ import (
"io"
)
-type token int
+type tokentype int
const (
- Name token = iota
- Delimiter token = iota
- Nothing token = iota
- IfStatement token = iota
+ Name tokentype = iota
+ Literal
+ Delimiter
+ Nothing
+ IfStatement
)
-// Having a Config to Manager function could be nice?
-// Or we could just return a Manager from here.
-type Config struct {
+type token struct {
+ Type tokentype
}
type scanner struct {
r io.Reader
- ss bufio.Scanner
+ bs 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,
+ bs: *ns,
}
return &sc
}
-func getTokenType(s string) token {
+func getTokenType(s string) tokentype {
return Nothing
}
-func (s *scanner) next() (token, string, error) {
- stop := s.ss.Scan()
- if stop {
- return Nothing, "", s.ss.Err()
+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.ss.Text()
+ tokstr := s.bs.Text()
token := getTokenType(tokstr)
return token, tokstr, nil
}
-func (s *scanner) peek() (token, string, error) {
+func (s *scanner) peek() (tokentype, string, error) {
return Nothing, "", nil
}