-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Added a file tracer.go for functions that handle code tracing for the parser - Added statements in the parsers to view the trace if the global traceOn value is set
- Loading branch information
1 parent
1ee88f6
commit d599d20
Showing
2 changed files
with
59 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
package parser | ||
|
||
import ( | ||
"fmt" | ||
"strings" | ||
) | ||
|
||
var traceLevel int = 0 | ||
|
||
const traceIdentPlaceholder string = "\t" | ||
|
||
func identLevel() string { | ||
return strings.Repeat(traceIdentPlaceholder, traceLevel-1) | ||
} | ||
|
||
func tracePrint(fs string) { | ||
fmt.Printf("%s%s\n", identLevel(), fs) | ||
} | ||
|
||
func incIdent() { traceLevel = traceLevel + 1 } | ||
func decIdent() { traceLevel = traceLevel - 1 } | ||
|
||
func trace(msg string) string { | ||
incIdent() | ||
tracePrint("BEGIN " + msg) | ||
return msg | ||
} | ||
|
||
func untrace(msg string) { | ||
tracePrint("END " + msg) | ||
decIdent() | ||
} |