-
Notifications
You must be signed in to change notification settings - Fork 2
/
debug.go
54 lines (47 loc) · 1.03 KB
/
debug.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
//go:build debug
// +build debug
package shapes
import (
"fmt"
"io"
"log"
)
// logstate prints the current state in a tab separated table that looks like this
// | current token | stack | infix stack |
// |---------------|--------|-------------|
func (p *parser) logstate(name ...interface{}) {
if p.log == nil {
return
}
var cur tok = tok{}
if p.qptr < len(p.queue) {
cur = p.queue[p.qptr]
}
// print current token if no name given
if len(name) > 0 {
n := fmt.Sprintf(name[0].(string), name[1:]...)
fmt.Fprintf(p.log, "%v\t[", n)
} else {
fmt.Fprintf(p.log, "%v\t[", cur)
}
// print stack
for _, item := range p.stack {
fmt.Fprintf(p.log, "%v;", item)
}
// print infix stack
fmt.Fprintf(p.log, "]\t[")
for _, item := range p.infixStack {
fmt.Fprintf(p.log, "%q ", item.v)
}
fmt.Fprintf(p.log, "]\n")
}
func (p *parser) printTab(w io.Writer) {
if p.log == nil {
return
}
if w == nil {
w = log.Default().Writer()
}
w.Write([]byte("Current Token\tStack\tInfix Stack\n"))
w.Write([]byte(p.log.String()))
}