diff options
author | Silvan Jegen <s.jegen@gmail.com> | 2017-01-27 20:02:42 +0100 |
---|---|---|
committer | Silvan Jegen <s.jegen@gmail.com> | 2017-01-27 20:04:05 +0100 |
commit | 32e27950115011c00b09d955e34d07d68b60bd6e (patch) | |
tree | 4a3d09c888a42ea412fc26ab1274ace2fafe6d0e /conf | |
parent | 3a586419584a1fbfd9052b5bf43dcfcd657e9cb5 (diff) |
Differentiate between modules and main modules
Allow several modules within a main module.
We also start parsing the output main module (which does not have an
"http" module yet).
Diffstat (limited to 'conf')
-rw-r--r-- | conf/parser.go | 82 |
1 files changed, 50 insertions, 32 deletions
diff --git a/conf/parser.go b/conf/parser.go index 3e351a7..0e19338 100644 --- a/conf/parser.go +++ b/conf/parser.go @@ -4,10 +4,11 @@ // in our configuration. Each module consists of two name-object pairs // that are nested. We don't want to allow limitless recursion here. // -// config = module module module -// module = name object name object +// config = mainmodule mainmodule mainmodule +// mainmodule = name '{' module+ '}' +// module = name object // name = 'input' | 'filter' | 'output' | etc. -// object = '{' keyvalue | keyvalue | ... '}' +// object = '{' keyvalue* '}' // keyvalue = statement '=>' value // statement = name | if // value = literal | '[' literal ']' @@ -55,21 +56,35 @@ func NewConfig(r io.Reader) *Config { } func (p *parser) startparsing() { - inputmdesc := p.module("input") - fmt.Fprintf(os.Stderr, "input moduledesc: %#v\n", inputmdesc) - inputnewfunc, ok := registry.Inputregistry[inputmdesc.name] - if !ok { - fmt.Fprintf(os.Stderr, "input module is not known: %q\n", inputmdesc.name) + inputmdescs := p.mainmodule("input") + fmt.Fprintf(os.Stderr, "input moduledescs: %#v\n", inputmdescs) + for _, idesc := range inputmdescs { + inputnewfunc, ok := registry.Inputregistry[idesc.name] + if !ok { + fmt.Fprintf(os.Stderr, "input module is not known: %q\n", idesc.name) + } + inputnewfunc(nil) } - inputnewfunc(nil) - filtermdesc := p.module("filter") - fmt.Fprintf(os.Stderr, "filter moduledesc: %#v\n", filtermdesc) - filternewfunc, ok := registry.Filterregistry[filtermdesc.name] - if !ok { - fmt.Fprintf(os.Stderr, "filter module is not known: %q\n", filtermdesc.name) + filtermdescs := p.mainmodule("filter") + fmt.Fprintf(os.Stderr, "filter moduledescs: %#v\n", filtermdescs) + for _, fdesc := range filtermdescs { + filternewfunc, ok := registry.Filterregistry[fdesc.name] + if !ok { + fmt.Fprintf(os.Stderr, "filter module is not known: %q\n", fdesc.name) + } + filternewfunc(nil) + } + + outputmdescs := p.mainmodule("output") + fmt.Fprintf(os.Stderr, "output moduledescs: %#v\n", outputmdescs) + for _, odesc := range outputmdescs { + filternewfunc, ok := registry.Outputregistry[odesc.name] + if !ok { + fmt.Fprintf(os.Stderr, "output module is not known: %q\n", odesc.name) + } + filternewfunc(nil) } - filternewfunc(nil) } func (p *parser) advanceOneToken(place string) { @@ -83,34 +98,37 @@ 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) *moduledesc { - ret := moduledesc{keyvalues: make(map[string]string)} +func (p *parser) mainmodule(firstname string) []moduledesc { + var moduledescs []moduledesc + md := moduledesc{keyvalues: make(map[string]string)} - p.advanceOneToken("module") + p.advanceOneToken("mainmodule") if p.cur.Lit != firstname { fmt.Fprintf(os.Stderr, "error when parsing module. We were expecting name %q but got %q at line %d offset %d.\n", firstname, p.cur.Lit, p.cur.LineNr, p.cur.Offset) } - p.advanceOneToken("module") + p.advanceOneToken("mainmodule") if p.cur.Type != ObjectOpen { fmt.Fprintf(os.Stderr, "error when parsing module. We were expecting an opening bracket but got %q at line %d offset %d.\n", p.cur.Lit, p.cur.LineNr, p.cur.Offset) } - p.advanceOneToken("module") - 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) - } - ret.name = p.cur.Lit - - ret.keyvalues = p.object(ret.keyvalues) + for { + p.advanceOneToken("more modules") + if p.cur.Type != Name { + if p.cur.Lit[0] == '}' { + break + } + fmt.Fprintf(os.Stderr, "error when parsing module. We were expecting either a name or the end of the module but got %q at line %d offset %d.\n", p.cur.Lit, p.cur.LineNr, p.cur.Offset) + } + md.name = p.cur.Lit - 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) + md.keyvalues = p.object(md.keyvalues) + moduledescs = append(moduledescs, md) + md = moduledesc{keyvalues: make(map[string]string)} } - return &ret + return moduledescs } func (p *parser) object(kv map[string]string) map[string]string { @@ -141,8 +159,8 @@ 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) + if p.cur.Type != Literal && p.cur.Type != Name { + fmt.Fprintf(os.Stderr, "error when parsing keyvalue. Was expecting a name or a literal but got %q at line %d offset %d.\n", p.cur.Lit, p.cur.LineNr, p.cur.Offset) } lhs := p.cur.Lit |