From 3aa2d9a6b0d89672c29e2745114ac93171429b77 Mon Sep 17 00:00:00 2001 From: Arpad Ryszka Date: Sat, 29 Jul 2017 22:31:16 +0200 Subject: [PATCH] enable tracing, disable storing included --- char.go | 5 +++++ choice.go | 15 +++++++++++++-- mml_test.go | 2 +- sequence.go | 11 ++++++++++- 4 files changed, 29 insertions(+), 4 deletions(-) diff --git a/char.go b/char.go index 54e562c..b0c833a 100644 --- a/char.go +++ b/char.go @@ -69,11 +69,16 @@ func (p *charParser) match(t rune) bool { } func (p *charParser) parse(t Trace, c *context) { + t = t.Extend(p.name) + t.Out1("parsing", c.offset) + 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 e759f80..9c78e13 100644 --- a/choice.go +++ b/choice.go @@ -144,16 +144,22 @@ 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", c.offset) + + // TODO: don't add documentation if p.commit&Documentation != 0 { c.fail(c.offset) return } - if _, ok := c.fromStore(p.id); ok { + if m, ok := c.fromStore(p.id); ok { + t.Out1("found in cache", m) return } if c.excluded(c.offset, p.id) { + t.Out1("fail, excluded") c.fail(c.offset) return } @@ -186,7 +192,10 @@ func (p *choiceParser) parse(t Trace, c *context) { c.store.setMatch(from, p.id, to) for _, includedBy := range p.includedBy { - c.store.setMatch(from, includedBy, to) + if !c.excluded(from, includedBy) { + t.Out1("storing included", includedBy) + // c.store.setMatch(from, includedBy, to) + } } } @@ -198,9 +207,11 @@ func (p *choiceParser) parse(t Trace, c *context) { if match { c.success(to) c.include(from, p.id) + t.Out1("success") return } + t.Out1("fail") c.store.setNoMatch(from, p.id) c.fail(from) c.include(from, p.id) diff --git a/mml_test.go b/mml_test.go index fb519a5..0921296 100644 --- a/mml_test.go +++ b/mml_test.go @@ -9,7 +9,7 @@ import ( ) func TestMML(t *testing.T) { - testTrace(t, "mml.parser", "mml", 1, []testItem{{ + testTrace(t, "mml.parser", "mml", 0, []testItem{{ msg: "empty", node: &Node{Name: "mml"}, }, { diff --git a/sequence.go b/sequence.go index 623327f..a86cc3b 100644 --- a/sequence.go +++ b/sequence.go @@ -171,12 +171,16 @@ 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", c.offset) + if p.commit&Documentation != 0 { c.fail(c.offset) return } if c.excluded(c.offset, p.id) { + t.Out1("fail, excluded") c.fail(c.offset) return } @@ -200,6 +204,7 @@ func (p *sequenceParser) parse(t Trace, c *context) { // c.store.setNoMatch(from, p.id) c.fail(from) c.include(from, p.id) + t.Out1("fail, not enough items") return } @@ -222,9 +227,13 @@ func (p *sequenceParser) parse(t Trace, c *context) { } for _, includedBy := range p.includedBy { - c.store.setMatch(from, includedBy, to) + 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) c.include(from, p.id)