From 23577d7274c781361b2755f7207dd2dc8b5cfcb4 Mon Sep 17 00:00:00 2001 From: Gregory Eremin Date: Wed, 18 Feb 2015 23:05:45 +0700 Subject: [PATCH] Parser verbose mode --- parser/parser.go | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/parser/parser.go b/parser/parser.go index 4c3b94d..d33709f 100644 --- a/parser/parser.go +++ b/parser/parser.go @@ -12,10 +12,11 @@ import ( type ( // Holds the state of parser Parser struct { - lex *lexer.Lexer - ctx *context - sels map[string]*context - res chan Match + lex *lexer.Lexer + ctx *context + sels map[string]*context + res chan Match + verbose bool } Match struct { Sel string @@ -35,6 +36,10 @@ func New(buf buffer.Bufferer, sels []string) *Parser { } } +func (p *Parser) Debug() { + p.verbose = true +} + // Parse all and return matches func (p *Parser) Parse() map[string][]interface{} { p.ParseStream() @@ -166,7 +171,9 @@ func (p *Parser) next() lexer.Item { panic(item) } - fmt.Println(item) + if p.verbose { + fmt.Println(item) + } return item } else { panic("EOF reached")