diff options
author | Silvan Jegen <s.jegen@gmail.com> | 2016-12-25 19:29:55 +0100 |
---|---|---|
committer | Silvan Jegen <s.jegen@gmail.com> | 2016-12-25 19:29:55 +0100 |
commit | 5d73aea0169c691b4c96d85353b1dccc5c1199e2 (patch) | |
tree | 997b5e9be454fd205628b585e723b6c80c225a1a /conf | |
parent | 0ad0f3a85145f2b64cf5cbffa57cdb779180b724 (diff) |
Start writing the parser
Diffstat (limited to 'conf')
-rw-r--r-- | conf/parser.go | 49 | ||||
-rw-r--r-- | conf/scanner.go | 4 |
2 files changed, 44 insertions, 9 deletions
diff --git a/conf/parser.go b/conf/parser.go index 85d9b11..75f610c 100644 --- a/conf/parser.go +++ b/conf/parser.go @@ -1,3 +1,14 @@ +// grammar of the config file +// +// config = module module module +// module = name object +// name = 'input' | 'filter' | 'etc.' +// object = '{' keyvalue | keyvalue | ... '}' +// keyvalue = statement '=>' value +// statement = name | if +// value = literal | '[' literal ']' +// literal = '"' name '"' + package conf import ( @@ -12,17 +23,41 @@ type Config struct { } type parser struct { - scanner + s scanner + last token + cur token +} + +func newParser(s *scanner) *parser { + p := &parser{ + s: *s, + } + + return p } func NewConfig(r io.Reader) *Config { - s := newScanner(r) - tok, err := s.Scan() + p := newParser(newScanner(r)) + p.startparsing() + + return &Config{} +} + +func (p *parser) startparsing() { + var err error + + p.last = p.cur + p.cur, err = p.s.Scan() for err == nil { - fmt.Fprintf(os.Stderr, "tokentype: %d, token: %q offset: %d, line: %d\n", tok.Type, tok.Lit, tok.Offset, tok.LineNr) - tok, err = s.Scan() + fmt.Fprintf(os.Stderr, "tokentype: %d, token: %q offset: %d, line: %d\n", p.cur.Type, p.cur.Lit, p.cur.Offset, p.cur.LineNr) + p.last = p.cur + p.cur, err = p.s.Scan() } - fmt.Fprintf(os.Stderr, "Error: tokentype: %d, token: %q, err: %v\n", tok.Type, tok.Lit, err) + fmt.Fprintf(os.Stderr, "Error: tokentype: %d, token: %q, err: %v\n", p.cur.Type, p.cur.Lit, err) +} - return &Config{} +func (p *parser) module(name string) { +} + +func (p *parser) object() { } diff --git a/conf/scanner.go b/conf/scanner.go index 3d83534..9bd7a4b 100644 --- a/conf/scanner.go +++ b/conf/scanner.go @@ -14,7 +14,8 @@ type tokentype int const ( Name tokentype = iota Literal - Delimiter + DeliOpen + DeliClose Nothing IfStatement ) @@ -27,7 +28,6 @@ type token struct { } type scanner struct { - r io.Reader data []byte offset int curline int |