token.go: better implementation of the function String()

This commit is contained in:
Celestino Amoroso 2024-04-13 04:33:59 +02:00
parent 07ca84170e
commit dda10749d0

View File

@ -27,7 +27,11 @@ func (tk *Token) DevString() string {
func (tk *Token) String() string {
if tk.Value != nil {
return fmt.Sprintf("%#v", tk.Value)
if s, ok := tk.Value.(string); ok {
return fmt.Sprintf("%q", s)
} else {
return fmt.Sprintf("%v", tk.Value)
}
}
return fmt.Sprintf("%s", tk.source)
}