parser_tracing.go 539 B

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