From 6dfe33a83a67d8fb9e431290e0c4ca86675f1b8f Mon Sep 17 00:00:00 2001 From: Silvan Jegen Date: Wed, 18 Jan 2017 18:53:05 +0100 Subject: Don't loop in advanceOneToken --- conf/parser.go | 14 +++++--------- 1 file changed, 5 insertions(+), 9 deletions(-) diff --git a/conf/parser.go b/conf/parser.go index 3d584f6..b22e6aa 100644 --- a/conf/parser.go +++ b/conf/parser.go @@ -59,19 +59,15 @@ func (p *parser) advanceOneToken(place string) { p.last = p.cur p.cur, err = p.s.Scan() - for err == nil { - fmt.Fprintf(os.Stderr, "tokentype: %v, 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() + if err != nil { + fmt.Fprintf(os.Stderr, "Error: tokentype: %v, token: %q, err: %v\n", p.cur.Type, p.cur.Lit, err) } - fmt.Fprintf(os.Stderr, "Error: tokentype: %v, token: %q, err: %v\n", p.cur.Type, p.cur.Lit, err) + fmt.Fprintf(os.Stderr, "tokentype: %v, token: %q\n", p.cur.Type, p.cur.Lit) } func (p *parser) module(firstname string) { p.advanceOneToken("module") - fmt.Fprintf(os.Stderr, "tokentype: %d, token: %q\n", p.cur.Type, p.cur.Lit) - 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) } @@ -117,7 +113,7 @@ func (p *parser) object() { func (p *parser) keyvalue() bool { p.advanceOneToken("keyvalue") - fmt.Fprintf(os.Stderr, "keyvalue: tokentype: %d, token: %q\n", p.cur.Type, p.cur.Lit) + 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) } @@ -138,7 +134,7 @@ func (p *parser) keyvalue() bool { return false } - fmt.Fprintf(os.Stderr, "peeked %q (type %d) at line %d offset %d.\n", tok.Lit, tok.Type, tok.LineNr, tok.Offset) + 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 -- cgit v1.2.3