enable tracing, disable storing included

This commit is contained in:
Arpad Ryszka 2017-07-29 22:31:16 +02:00
parent 85cd8f1729
commit 3aa2d9a6b0
4 changed files with 29 additions and 4 deletions

View File

@ -69,11 +69,16 @@ func (p *charParser) match(t rune) bool {
} }
func (p *charParser) parse(t Trace, c *context) { 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) { if tok, ok := c.token(); !ok || !p.match(tok) {
t.Out1("fail")
c.fail(c.offset) c.fail(c.offset)
return return
} }
t.Out1("success")
c.success(c.offset + 1) c.success(c.offset + 1)
for _, includedBy := range p.includedBy { for _, includedBy := range p.includedBy {
c.store.setMatch(c.offset, includedBy, c.offset+1) c.store.setMatch(c.offset, includedBy, c.offset+1)

View File

@ -144,16 +144,22 @@ func (p *choiceParser) nodeName() string { return p.name }
func (p *choiceParser) nodeID() int { return p.id } func (p *choiceParser) nodeID() int { return p.id }
func (p *choiceParser) parse(t Trace, c *context) { 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 { if p.commit&Documentation != 0 {
c.fail(c.offset) c.fail(c.offset)
return return
} }
if _, ok := c.fromStore(p.id); ok { if m, ok := c.fromStore(p.id); ok {
t.Out1("found in cache", m)
return return
} }
if c.excluded(c.offset, p.id) { if c.excluded(c.offset, p.id) {
t.Out1("fail, excluded")
c.fail(c.offset) c.fail(c.offset)
return return
} }
@ -186,7 +192,10 @@ func (p *choiceParser) parse(t Trace, c *context) {
c.store.setMatch(from, p.id, to) c.store.setMatch(from, p.id, to)
for _, includedBy := range p.includedBy { 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 { if match {
c.success(to) c.success(to)
c.include(from, p.id) c.include(from, p.id)
t.Out1("success")
return return
} }
t.Out1("fail")
c.store.setNoMatch(from, p.id) c.store.setNoMatch(from, p.id)
c.fail(from) c.fail(from)
c.include(from, p.id) c.include(from, p.id)

View File

@ -9,7 +9,7 @@ import (
) )
func TestMML(t *testing.T) { func TestMML(t *testing.T) {
testTrace(t, "mml.parser", "mml", 1, []testItem{{ testTrace(t, "mml.parser", "mml", 0, []testItem{{
msg: "empty", msg: "empty",
node: &Node{Name: "mml"}, node: &Node{Name: "mml"},
}, { }, {

View File

@ -171,12 +171,16 @@ func (p *sequenceParser) nodeName() string { return p.name }
func (p *sequenceParser) nodeID() int { return p.id } func (p *sequenceParser) nodeID() int { return p.id }
func (p *sequenceParser) parse(t Trace, c *context) { func (p *sequenceParser) parse(t Trace, c *context) {
t = t.Extend(p.name)
t.Out1("parsing", c.offset)
if p.commit&Documentation != 0 { if p.commit&Documentation != 0 {
c.fail(c.offset) c.fail(c.offset)
return return
} }
if c.excluded(c.offset, p.id) { if c.excluded(c.offset, p.id) {
t.Out1("fail, excluded")
c.fail(c.offset) c.fail(c.offset)
return return
} }
@ -200,6 +204,7 @@ func (p *sequenceParser) parse(t Trace, c *context) {
// c.store.setNoMatch(from, p.id) // c.store.setNoMatch(from, p.id)
c.fail(from) c.fail(from)
c.include(from, p.id) c.include(from, p.id)
t.Out1("fail, not enough items")
return return
} }
@ -222,9 +227,13 @@ func (p *sequenceParser) parse(t Trace, c *context) {
} }
for _, includedBy := range p.includedBy { 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.store.setMatch(from, p.id, to)
c.success(to) c.success(to)
c.include(from, p.id) c.include(from, p.id)