package tokenize import ( "fmt" "runtime" "strings" ) func callerPanic(depth int, f string, args ...interface{}) { filepos := callerFilepos(depth + 1) m := fmt.Sprintf(f, args...) m = strings.Replace(m, "{caller}", filepos, 1) panic(m) } func callerFilepos(depth int) string { // No error handling, because we call this method ourselves with safe depth values. _, file, line, _ := runtime.Caller(depth + 1) return fmt.Sprintf("%s:%d", file, line) }