disable tracing

This commit is contained in:
Arpad Ryszka 2017-06-26 00:20:54 +02:00
parent 6a179f7474
commit 2d8d1ae4ef
10 changed files with 61 additions and 57 deletions

10
boot.go
View File

@ -187,8 +187,8 @@ func defineAllBoot(s *Syntax, defs [][]string) error {
return nil
}
func initBoot(t Trace, definitions [][]string) (*Syntax, error) {
s := NewSyntax(t)
func initBoot(definitions [][]string) (*Syntax, error) {
s := NewSyntax()
if err := defineAllBoot(s, definitions); err != nil {
return nil, err
}
@ -196,8 +196,8 @@ func initBoot(t Trace, definitions [][]string) (*Syntax, error) {
return s, s.Init()
}
func bootSyntax(t Trace) (*Syntax, error) {
b, err := initBoot(t, bootDefinitions)
func bootSyntax() (*Syntax, error) {
b, err := initBoot(bootDefinitions)
if err != nil {
return nil, err
}
@ -214,6 +214,6 @@ func bootSyntax(t Trace) (*Syntax, error) {
return nil, err
}
s := NewSyntax(t)
s := NewSyntax()
return s, define(s, doc)
}

View File

@ -6,9 +6,7 @@ import (
)
func TestBoot(t *testing.T) {
var trace Trace
b, err := initBoot(trace, bootDefinitions)
b, err := initBoot(bootDefinitions)
if err != nil {
t.Error(err)
return
@ -28,8 +26,7 @@ func TestBoot(t *testing.T) {
return
}
// trace = NewTrace(1)
s0 := NewSyntax(trace)
s0 := NewSyntax()
if err := define(s0, n0); err != nil {
t.Error(err)
return
@ -58,7 +55,7 @@ func TestBoot(t *testing.T) {
return
}
s1 := NewSyntax(trace)
s1 := NewSyntax()
if err := define(s1, n1); err != nil {
t.Error(err)
return

14
char.go
View File

@ -73,22 +73,22 @@ func (p *charParser) match(t rune) bool {
}
func (p *charParser) parse(t Trace, c *context) {
t = t.Extend(p.name)
t.Out1("parsing char", c.offset)
// t = t.Extend(p.name)
// t.Out1("parsing char", c.offset)
if p.commit&Documentation != 0 {
t.Out1("fail, doc")
// t.Out1("fail, doc")
c.fail(c.offset)
return
}
if m, ok := c.fromCache(p.name); ok {
t.Out1("found in cache, match:", m)
if _, ok := c.fromCache(p.name); ok {
// t.Out1("found in cache, match:", m)
return
}
if tok, ok := c.token(); ok && p.match(tok) {
t.Out1("success", string(tok))
// t.Out1("success", string(tok))
n := newNode(p.name, p.commit, c.offset, c.offset+1)
c.cache.set(c.offset, p.name, n)
for _, includedBy := range p.includedBy {
@ -98,7 +98,7 @@ func (p *charParser) parse(t Trace, c *context) {
c.success(n)
return
} else {
t.Out1("fail", string(tok))
// t.Out1("fail", string(tok))
c.cache.set(c.offset, p.name, nil)
c.fail(c.offset)
return

View File

@ -93,22 +93,22 @@ func (p *choiceParser) cacheIncluded(c *context, n *Node) {
}
func (p *choiceParser) parse(t Trace, c *context) {
t = t.Extend(p.name)
t.Out1("parsing choice", c.offset)
// t = t.Extend(p.name)
// t.Out1("parsing choice", c.offset)
if p.commit&Documentation != 0 {
t.Out1("fail, doc")
// t.Out1("fail, doc")
c.fail(c.offset)
return
}
if m, ok := c.fromCache(p.name); ok {
t.Out1("found in cache, match:", m)
if _, ok := c.fromCache(p.name); ok {
// t.Out1("found in cache, match:", m)
return
}
if c.excluded(c.offset, p.name) {
t.Out1("excluded")
// t.Out1("excluded")
c.fail(c.offset)
return
}
@ -149,12 +149,12 @@ func (p *choiceParser) parse(t Trace, c *context) {
}
if match {
t.Out1("choice, success")
// t.Out1("choice, success")
c.success(node)
return
}
t.Out1("fail")
// t.Out1("fail")
c.cache.set(node.from, p.name, nil)
c.fail(node.from)
}

View File

@ -727,7 +727,7 @@ func TestEskip(t *testing.T) {
r := generateEskip(1 << 9)
e := eskip.Print(true, r...)
b := bytes.NewBufferString(e)
s, err := testSyntax("eskip.parser", 0)
s, err := testSyntax("eskip.parser", -1)
if err != nil {
t.Error(err)
return

View File

@ -509,7 +509,7 @@ func TestRandomJSON(t *testing.T) {
buf := bytes.NewBuffer(b)
s, err := testSyntax("json.parser", 0)
s, err := testSyntax("json.parser", -1)
if err != nil {
t.Error(err)
return

View File

@ -18,9 +18,7 @@ type testItem struct {
}
func testSyntaxReader(r io.Reader, traceLevel int) (*Syntax, error) {
trace := NewTrace(0)
b, err := bootSyntax(trace)
b, err := bootSyntax()
if err != nil {
return nil, err
}
@ -30,8 +28,12 @@ func testSyntaxReader(r io.Reader, traceLevel int) (*Syntax, error) {
return nil, err
}
trace = NewTrace(traceLevel)
s := NewSyntax(trace)
var trace Trace = NopTrace{}
if traceLevel >= 0 {
trace = NewTrace(traceLevel)
}
s := NewSyntaxTrace(trace)
if err := define(s, doc); err != nil {
return nil, err
}
@ -189,7 +191,7 @@ func testStringTrace(t *testing.T, s string, traceLevel int, tests []testItem) {
}
func testString(t *testing.T, s string, tests []testItem) {
testStringTrace(t, s, 0, tests)
testStringTrace(t, s, -1, tests)
}
func testTrace(t *testing.T, file, rootName string, traceLevel int, tests []testItem) {
@ -204,7 +206,7 @@ func testTrace(t *testing.T, file, rootName string, traceLevel int, tests []test
}
func test(t *testing.T, file, rootName string, tests []testItem) {
testTrace(t, file, rootName, 0, tests)
testTrace(t, file, rootName, -1, tests)
}
func TestRecursion(t *testing.T) {
@ -358,10 +360,9 @@ func TestSequence(t *testing.T) {
}},
)
testStringTrace(
testString(
t,
`A = "a" | (A?)*`,
1,
[]testItem{{
msg: "sequence in choice with redundant quantifier",
text: "aaa",

View File

@ -114,17 +114,17 @@ func (p *sequenceParser) cacheIncluded(c *context, n *Node) {
}
func (p *sequenceParser) parse(t Trace, c *context) {
t = t.Extend(p.name)
t.Out1("parsing sequence", c.offset)
// t = t.Extend(p.name)
// t.Out1("parsing sequence", c.offset)
if p.commit&Documentation != 0 {
t.Out1("fail, doc")
// t.Out1("fail, doc")
c.fail(c.offset)
return
}
if c.excluded(c.offset, p.name) {
t.Out1("excluded")
// t.Out1("excluded")
c.fail(c.offset)
return
}
@ -140,7 +140,7 @@ func (p *sequenceParser) parse(t Trace, c *context) {
for len(items) > 0 {
m, ok := c.fromCache(items[0].nodeName())
if ok {
t.Out1("sequence item found in cache, match:", m, items[0].nodeName(), c.offset)
// t.Out1("sequence item found in cache, match:", m, items[0].nodeName(), c.offset)
} else {
items[0].parse(t, c)
m = c.match
@ -148,7 +148,7 @@ func (p *sequenceParser) parse(t Trace, c *context) {
if !m {
if currentCount < ranges[0][0] {
t.Out1("fail, item failed")
// t.Out1("fail, item failed")
c.cache.set(node.from, p.name, nil)
c.fail(node.from)
return
@ -172,7 +172,7 @@ func (p *sequenceParser) parse(t Trace, c *context) {
}
}
t.Out1("success, items parsed")
// t.Out1("success, items parsed")
c.cache.set(node.from, p.name, node)
for _, includedBy := range p.includedBy {

View File

@ -46,9 +46,13 @@ func duplicateDefinition(name string) error {
return fmt.Errorf("duplicate definition: %s", name)
}
func NewSyntax(t Trace) *Syntax {
func NewSyntax() *Syntax {
return NewSyntaxTrace(nil)
}
func NewSyntaxTrace(t Trace) *Syntax {
if t == nil {
t = NewTrace(0)
t = NopTrace{}
}
return &Syntax{

View File

@ -6,6 +6,7 @@ import (
)
type Trace interface {
OutN(int, ...interface{})
Out(...interface{})
Out1(...interface{})
Out2(...interface{})
@ -27,8 +28,8 @@ func NewTrace(level int) *DefaultTrace {
}
}
func (t *DefaultTrace) printlnLevel(l int, a ...interface{}) {
if l > t.level {
func (t *DefaultTrace) OutN(level int, a ...interface{}) {
if level > t.level {
return
}
@ -36,19 +37,19 @@ func (t *DefaultTrace) printlnLevel(l int, a ...interface{}) {
}
func (t *DefaultTrace) Out(a ...interface{}) {
t.printlnLevel(0, a...)
t.OutN(0, a...)
}
func (t *DefaultTrace) Out1(a ...interface{}) {
t.printlnLevel(1, a...)
t.OutN(1, a...)
}
func (t *DefaultTrace) Out2(a ...interface{}) {
t.printlnLevel(2, a...)
t.OutN(2, a...)
}
func (t *DefaultTrace) Out3(a ...interface{}) {
t.printlnLevel(3, a...)
t.OutN(3, a...)
}
func (t *DefaultTrace) Extend(name string) Trace {
@ -65,8 +66,9 @@ func (t *DefaultTrace) Extend(name string) Trace {
}
}
func (NopTrace) Out(...interface{}) {}
func (NopTrace) Out1(...interface{}) {}
func (NopTrace) Out2(...interface{}) {}
func (NopTrace) Out3(...interface{}) {}
func (t NopTrace) Extend(string) Trace { return t }
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 }