From c003fdf2182432a25892467bf1a456049f4b1c1d Mon Sep 17 00:00:00 2001 From: Silvan Jegen Date: Sun, 15 Jan 2017 20:04:53 +0100 Subject: Implement Stringer interface for the token type --- conf/parser.go | 4 ++-- conf/scanner.go | 8 ++++++++ 2 files changed, 10 insertions(+), 2 deletions(-) (limited to 'conf') diff --git a/conf/parser.go b/conf/parser.go index 75f610c..4f58713 100644 --- a/conf/parser.go +++ b/conf/parser.go @@ -49,11 +49,11 @@ func (p *parser) startparsing() { 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", p.cur.Type, p.cur.Lit, p.cur.Offset, p.cur.LineNr) + 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() } - fmt.Fprintf(os.Stderr, "Error: tokentype: %d, 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) } func (p *parser) module(name string) { diff --git a/conf/scanner.go b/conf/scanner.go index 9bd7a4b..54546aa 100644 --- a/conf/scanner.go +++ b/conf/scanner.go @@ -20,6 +20,14 @@ const ( IfStatement ) +var tokentypestrings []string = []string{Name: "Name", Literal: "Literal", + DeliOpen: "Opening delimiter", DeliClose: "Closing delimiter", + Nothing: "Nothing", IfStatement: "If statement"} + +func (tt tokentype) String() string { + return tokentypestrings[tt] +} + type token struct { Type tokentype Offset int -- cgit v1.2.3