summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--conf/parser.go37
-rw-r--r--output/interface.go2
2 files changed, 28 insertions, 11 deletions
diff --git a/conf/parser.go b/conf/parser.go
index b22e6aa..dfaa8dc 100644
--- a/conf/parser.go
+++ b/conf/parser.go
@@ -32,6 +32,11 @@ type parser struct {
cur token
}
+type moduledesc struct {
+ name string
+ keyvalues map[string]string
+}
+
func newParser(s *scanner) *parser {
p := &parser{
s: *s,
@@ -48,7 +53,8 @@ func NewConfig(r io.Reader) *Config {
}
func (p *parser) startparsing() {
- p.module("input")
+ mdesc := p.module("input")
+ fmt.Fprintf(os.Stderr, "moduledesc: %#v\n", mdesc)
p.module("filter")
@@ -65,7 +71,9 @@ func (p *parser) advanceOneToken(place string) {
fmt.Fprintf(os.Stderr, "tokentype: %v, token: %q\n", p.cur.Type, p.cur.Lit)
}
-func (p *parser) module(firstname string) {
+func (p *parser) module(firstname string) *moduledesc {
+ ret := moduledesc{keyvalues: make(map[string]string)}
+
p.advanceOneToken("module")
if p.cur.Lit != firstname {
@@ -81,16 +89,21 @@ func (p *parser) module(firstname string) {
if p.cur.Type != Name {
fmt.Fprintf(os.Stderr, "error when parsing module. We were expecting another name but got %q at line %d offset %d.\n", p.cur.Lit, p.cur.LineNr, p.cur.Offset)
}
- p.object()
+ ret.name = p.cur.Lit
+
+ ret.keyvalues = p.object(ret.keyvalues)
p.advanceOneToken("module")
if p.cur.Lit[0] != '}' {
fmt.Fprintf(os.Stderr, "error when parsing module. Was expecting a closing bracket but got %s at line %d offset %d.\n", p.cur.Lit, p.cur.LineNr, p.cur.Offset)
}
+ return &ret
}
-func (p *parser) object() {
+func (p *parser) object(kv map[string]string) map[string]string {
+ var more bool
+
p.advanceOneToken("object")
if p.cur.Lit[0] != '{' {
@@ -99,24 +112,27 @@ func (p *parser) object() {
// hack to deal with case where there is no white space between
// the delimiters.
if p.cur.Lit == "{}" {
- return
+ return kv
}
for {
- more := p.keyvalue()
+ more, kv = p.keyvalue(kv)
if !more {
break
}
}
+
+ return kv
}
-func (p *parser) keyvalue() bool {
+func (p *parser) keyvalue(kv map[string]string) (bool, map[string]string) {
p.advanceOneToken("keyvalue")
fmt.Fprintf(os.Stderr, "keyvalue: tokentype: %v, token: %q\n", p.cur.Type, p.cur.Lit)
if p.cur.Type != Literal {
fmt.Fprintf(os.Stderr, "error when parsing keyvalue. Was expecting a name but got %q at line %d offset %d.\n", p.cur.Lit, p.cur.LineNr, p.cur.Offset)
}
+ lhs := p.cur.Lit
p.advanceOneToken("keyvalue")
if p.cur.Lit != "=>" {
@@ -127,18 +143,19 @@ func (p *parser) keyvalue() bool {
if p.cur.Type != Literal && p.cur.Type != Name {
fmt.Fprintf(os.Stderr, "error when parsing keyvalue. Was expecting a literal or a name but got %q at line %d offset %d.\n", p.cur.Lit, p.cur.LineNr, p.cur.Offset)
}
+ kv[lhs] = p.cur.Lit
tok, err := p.s.Peek()
if err != nil {
fmt.Fprintf(os.Stderr, "error when parsing keyvalue. Got an error when checking if there are more keyvalues: %v.\n", err)
- return false
+ return false, kv
}
fmt.Fprintf(os.Stderr, "peeked %q (type %v) at line %d offset %d.\n", tok.Lit, tok.Type, tok.LineNr, tok.Offset)
if tok.Type == ObjectClose {
p.advanceOneToken("keyvaluelast")
- return false
+ return false, kv
}
- return true
+ return true, kv
}
diff --git a/output/interface.go b/output/interface.go
index c6ee3f6..8f1137a 100644
--- a/output/interface.go
+++ b/output/interface.go
@@ -3,5 +3,5 @@ package output
import "github.com/Shugyousha/stasher/work"
type Output interface {
- Output(*work.Work)
+ Output(*work.Work)
}