parser_tracing.go 496 B

12345678910111213141516171819202122232425262728293031323334353637
  1. package parser
  2. import (
  3. "fmt"
  4. "strings"
  5. )
  6. var traceLevel = 0
  7. const traceIndentPlaceholder = "\t"
  8. func indentLevel() string {
  9. return strings.Repeat(traceIndentPlaceholder, traceLevel-1)
  10. }
  11. func tracePrint(fs string) {
  12. fmt.Printf("%s%s\n", indentLevel(), fs)
  13. }
  14. func indentInc() {
  15. traceLevel++
  16. }
  17. func indentDec() {
  18. traceLevel--
  19. }
  20. func trace(msg string) string {
  21. indentInc()
  22. tracePrint("BEGIN " + msg)
  23. return msg
  24. }
  25. func untrace(msg string) {
  26. tracePrint("END " + msg)
  27. indentDec()
  28. }