drop tracing

This commit is contained in:
Arpad Ryszka 2017-10-31 21:09:30 +01:00
parent 066fd28cda
commit c895aed608
7 changed files with 10 additions and 126 deletions

View File

@ -72,17 +72,12 @@ func (p *charParser) match(t rune) bool {
return p.not return p.not
} }
func (p *charParser) parse(t Trace, c *context) { func (p *charParser) parse(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

@ -162,24 +162,12 @@ func (d *choiceDefinition) builder() builder {
func (p *choiceParser) nodeName() string { return p.name } 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(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
// }
if c.fromStore(p.id) { if c.fromStore(p.id) {
// t.Out1("found in store, match:")
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
} }
@ -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 // - it is also important to figure why disabling the failed elements breaks the parsing
for elementIndex < len(p.elements) { for elementIndex < len(p.elements) {
p.elements[elementIndex].parse(t, c) p.elements[elementIndex].parse(c)
elementIndex++ elementIndex++
if !c.match || match && c.offset <= to { if !c.match || match && c.offset <= to {
@ -226,11 +214,9 @@ 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("choice, 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

@ -21,7 +21,7 @@ code generation go:
- find things that depend on the syntax input - find things that depend on the syntax input
- char matches can be generated into switches - char matches can be generated into switches
code generation js code generation js
ws and nows flags documentation flag
[problems] [problems]
can the root be an alias? check the commit mechanism can the root be an alias? check the commit mechanism

View File

@ -20,7 +20,7 @@ type definition interface {
type parser interface { type parser interface {
nodeName() string nodeName() string
nodeID() int nodeID() int
parse(Trace, *context) parse(*context)
} }
type builder interface { type builder interface {
@ -77,8 +77,8 @@ func sequenceItemNames(items []SequenceItem) []string {
return names return names
} }
func parse(t Trace, p parser, c *context) error { func parse(p parser, c *context) error {
p.parse(t, c) p.parse(c)
if c.readErr != nil { if c.readErr != nil {
return c.readErr return c.readErr
} }

View File

@ -213,19 +213,9 @@ func (d *sequenceDefinition) builder() builder {
func (p *sequenceParser) nodeName() string { return p.name } 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(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
// }
if !p.allChars { if !p.allChars {
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
} }
@ -241,7 +231,7 @@ func (p *sequenceParser) parse(t Trace, c *context) {
for itemIndex < len(p.items) { for itemIndex < len(p.items) {
// TODO: is it ok to parse before max range check? what if max=0 // 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 !c.match {
if currentCount < p.ranges[itemIndex][0] { if currentCount < p.ranges[itemIndex][0] {
// c.store.setNoMatch(from, p.id) // c.store.setNoMatch(from, p.id)
@ -251,7 +241,6 @@ func (p *sequenceParser) parse(t Trace, c *context) {
c.include(from, p.id) c.include(from, p.id)
} }
// t.Out1("fail, not enough items")
return return
} }
@ -276,13 +265,11 @@ func (p *sequenceParser) parse(t Trace, c *context) {
if !p.allChars { if !p.allChars {
for _, includedBy := range p.includedBy { for _, includedBy := range p.includedBy {
if c.excluded(from, includedBy) { if c.excluded(from, includedBy) {
// t.Out1("storing included", includedBy)
c.store.setMatch(from, includedBy, to) 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)

View File

@ -24,7 +24,6 @@ type SequenceItem struct {
} }
type Syntax struct { type Syntax struct {
trace Trace
registry *registry registry *registry
initialized bool initialized bool
initFailed bool initFailed bool
@ -54,16 +53,7 @@ func duplicateDefinition(name string) error {
} }
func NewSyntax() *Syntax { func NewSyntax() *Syntax {
return NewSyntaxTrace(nil)
}
func NewSyntaxTrace(t Trace) *Syntax {
if t == nil {
t = NopTrace{}
}
return &Syntax{ return &Syntax{
trace: t,
registry: newRegistry(), registry: newRegistry(),
} }
} }
@ -227,7 +217,7 @@ func (s *Syntax) Parse(r io.Reader) (*Node, error) {
} }
c := newContext(bufio.NewReader(r)) 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 return nil, err
} }

View File

@ -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 }