Out outputs a trace message -- returns true if actually output
(ps *State, pr *Rule, step Steps, pos lexer.Pos, scope lexer.Reg, ast *AST, msg string)
| 106 | |
| 107 | // Out outputs a trace message -- returns true if actually output |
| 108 | func (pt *TraceOptions) Out(ps *State, pr *Rule, step Steps, pos lexer.Pos, scope lexer.Reg, ast *AST, msg string) bool { |
| 109 | if !pt.On { |
| 110 | return false |
| 111 | } |
| 112 | if !pt.CheckRule(pr.Name) { |
| 113 | return false |
| 114 | } |
| 115 | switch step { |
| 116 | case Match: |
| 117 | if !pt.Match { |
| 118 | return false |
| 119 | } |
| 120 | case SubMatch: |
| 121 | if !pt.SubMatch { |
| 122 | return false |
| 123 | } |
| 124 | case NoMatch: |
| 125 | if !pt.NoMatch { |
| 126 | return false |
| 127 | } |
| 128 | case Run: |
| 129 | if !pt.Run { |
| 130 | return false |
| 131 | } |
| 132 | case RunAct: |
| 133 | if !pt.RunAct { |
| 134 | return false |
| 135 | } |
| 136 | } |
| 137 | tokSrc := pos.String() + `"` + string(ps.Src.TokenSrc(pos)) + `"` |
| 138 | plev := ast.ParentLevel(ps.AST) |
| 139 | ind := "" |
| 140 | for i := 0; i < plev; i++ { |
| 141 | ind += "\t" |
| 142 | } |
| 143 | fmt.Fprintf(pt.OutWrite, "%v%v:\t %v\t %v\t tok: %v\t scope: %v\t ast: %v\n", ind, pr.Name, step, msg, tokSrc, scope, ast.Path()) |
| 144 | if pt.ScopeSrc { |
| 145 | scopeSrc := ps.Src.TokenRegSrc(scope) |
| 146 | fmt.Fprintf(pt.OutWrite, "%v\t%v\n", ind, scopeSrc) |
| 147 | } |
| 148 | return true |
| 149 | } |
| 150 | |
| 151 | // CopyOpts copies just the options |
| 152 | func (pt *TraceOptions) CopyOpts(ot *TraceOptions) { |