From c895aed608183614ac990efda5390dd898f8985d Mon Sep 17 00:00:00 2001 From: Arpad Ryszka Date: Tue, 31 Oct 2017 21:09:30 +0100 Subject: [PATCH] drop tracing --- char.go | 7 +---- choice.go | 18 ++----------- notes.txt | 2 +- parse.go | 6 ++--- sequence.go | 17 ++---------- syntax.go | 12 +-------- trace.go | 74 ----------------------------------------------------- 7 files changed, 10 insertions(+), 126 deletions(-) delete mode 100644 trace.go diff --git a/char.go b/char.go index 750085d..8e100cb 100644 --- a/char.go +++ b/char.go @@ -72,17 +72,12 @@ func (p *charParser) match(t rune) bool { return p.not } -func (p *charParser) parse(t Trace, c *context) { - // t = t.Extend(p.name) - // t.Out1("parsing", c.offset) - +func (p *charParser) parse(c *context) { if tok, ok := c.token(); !ok || !p.match(tok) { - // t.Out1("fail") c.fail(c.offset) return } - // t.Out1("success") c.success(c.offset + 1) for _, includedBy := range p.includedBy { c.store.setMatch(c.offset, includedBy, c.offset+1) diff --git a/choice.go b/choice.go index dff28dc..43ec7a1 100644 --- a/choice.go +++ b/choice.go @@ -162,24 +162,12 @@ func (d *choiceDefinition) builder() builder { func (p *choiceParser) nodeName() string { return p.name } func (p *choiceParser) nodeID() int { return p.id } -func (p *choiceParser) parse(t Trace, c *context) { - // t = t.Extend(p.name) - // t.Out1("parsing choice", c.offset) - - // TODO: don't add documentation - // if p.commit&Documentation != 0 { - // // t.Out1("fail, doc") - // c.fail(c.offset) - // return - // } - +func (p *choiceParser) parse(c *context) { if c.fromStore(p.id) { - // t.Out1("found in store, match:") return } if c.excluded(c.offset, p.id) { - // t.Out1("fail, excluded") c.fail(c.offset) return } @@ -202,7 +190,7 @@ func (p *choiceParser) parse(t Trace, c *context) { // - it is also important to figure why disabling the failed elements breaks the parsing for elementIndex < len(p.elements) { - p.elements[elementIndex].parse(t, c) + p.elements[elementIndex].parse(c) elementIndex++ if !c.match || match && c.offset <= to { @@ -226,11 +214,9 @@ func (p *choiceParser) parse(t Trace, c *context) { if match { c.success(to) c.include(from, p.id) - // t.Out1("choice, success") return } - // t.Out1("fail") c.store.setNoMatch(from, p.id) c.fail(from) c.include(from, p.id) diff --git a/notes.txt b/notes.txt index d783756..da0e080 100644 --- a/notes.txt +++ b/notes.txt @@ -21,7 +21,7 @@ code generation go: - find things that depend on the syntax input - char matches can be generated into switches code generation js -ws and nows flags +documentation flag [problems] can the root be an alias? check the commit mechanism diff --git a/parse.go b/parse.go index 1601a43..5a7d907 100644 --- a/parse.go +++ b/parse.go @@ -20,7 +20,7 @@ type definition interface { type parser interface { nodeName() string nodeID() int - parse(Trace, *context) + parse(*context) } type builder interface { @@ -77,8 +77,8 @@ func sequenceItemNames(items []SequenceItem) []string { return names } -func parse(t Trace, p parser, c *context) error { - p.parse(t, c) +func parse(p parser, c *context) error { + p.parse(c) if c.readErr != nil { return c.readErr } diff --git a/sequence.go b/sequence.go index 9b6d401..68e33e8 100644 --- a/sequence.go +++ b/sequence.go @@ -213,19 +213,9 @@ func (d *sequenceDefinition) builder() builder { func (p *sequenceParser) nodeName() string { return p.name } func (p *sequenceParser) nodeID() int { return p.id } -func (p *sequenceParser) parse(t Trace, c *context) { - // t = t.Extend(p.name) - // t.Out1("parsing sequence", c.offset) - - // if p.commit&Documentation != 0 { - // // t.Out1("fail, doc") - // c.fail(c.offset) - // return - // } - +func (p *sequenceParser) parse(c *context) { if !p.allChars { if c.excluded(c.offset, p.id) { - // t.Out1("fail, excluded") c.fail(c.offset) return } @@ -241,7 +231,7 @@ func (p *sequenceParser) parse(t Trace, c *context) { for itemIndex < len(p.items) { // TODO: is it ok to parse before max range check? what if max=0 - p.items[itemIndex].parse(t, c) + p.items[itemIndex].parse(c) if !c.match { if currentCount < p.ranges[itemIndex][0] { // c.store.setNoMatch(from, p.id) @@ -251,7 +241,6 @@ func (p *sequenceParser) parse(t Trace, c *context) { c.include(from, p.id) } - // t.Out1("fail, not enough items") return } @@ -276,13 +265,11 @@ func (p *sequenceParser) parse(t Trace, c *context) { if !p.allChars { for _, includedBy := range p.includedBy { if c.excluded(from, includedBy) { - // t.Out1("storing included", includedBy) c.store.setMatch(from, includedBy, to) } } } - // t.Out1("success") c.store.setMatch(from, p.id, to) c.success(to) diff --git a/syntax.go b/syntax.go index e6e05cc..31692b8 100644 --- a/syntax.go +++ b/syntax.go @@ -24,7 +24,6 @@ type SequenceItem struct { } type Syntax struct { - trace Trace registry *registry initialized bool initFailed bool @@ -54,16 +53,7 @@ func duplicateDefinition(name string) error { } func NewSyntax() *Syntax { - return NewSyntaxTrace(nil) -} - -func NewSyntaxTrace(t Trace) *Syntax { - if t == nil { - t = NopTrace{} - } - return &Syntax{ - trace: t, registry: newRegistry(), } } @@ -227,7 +217,7 @@ func (s *Syntax) Parse(r io.Reader) (*Node, error) { } c := newContext(bufio.NewReader(r)) - if err := parse(s.trace, s.parser, c); err != nil { + if err := parse(s.parser, c); err != nil { return nil, err } diff --git a/trace.go b/trace.go deleted file mode 100644 index a8a1de2..0000000 --- a/trace.go +++ /dev/null @@ -1,74 +0,0 @@ -package treerack - -import ( - "fmt" - "os" -) - -type Trace interface { - OutN(int, ...interface{}) - Out(...interface{}) - Out1(...interface{}) - Out2(...interface{}) - Out3(...interface{}) - Extend(string) Trace -} - -type DefaultTrace struct { - level int - path string -} - -type NopTrace struct{} - -func NewTrace(level int) *DefaultTrace { - return &DefaultTrace{ - level: level, - path: "/", - } -} - -func (t *DefaultTrace) OutN(level int, a ...interface{}) { - if level > t.level { - return - } - - fmt.Fprintln(os.Stderr, append([]interface{}{t.path}, a...)...) -} - -func (t *DefaultTrace) Out(a ...interface{}) { - t.OutN(0, a...) -} - -func (t *DefaultTrace) Out1(a ...interface{}) { - t.OutN(1, a...) -} - -func (t *DefaultTrace) Out2(a ...interface{}) { - t.OutN(2, a...) -} - -func (t *DefaultTrace) Out3(a ...interface{}) { - t.OutN(3, a...) -} - -func (t *DefaultTrace) Extend(name string) Trace { - var p string - if t.path == "/" { - p = t.path + name - } else { - p = t.path + "/" + name - } - - return &DefaultTrace{ - level: t.level, - path: p, - } -} - -func (NopTrace) OutN(int, ...interface{}) {} -func (NopTrace) Out(...interface{}) {} -func (NopTrace) Out1(...interface{}) {} -func (NopTrace) Out2(...interface{}) {} -func (NopTrace) Out3(...interface{}) {} -func (t NopTrace) Extend(string) Trace { return t }