Skip to content

Commit

Permalink
fix: prevent big nums to be printed as scientific notation
Browse files Browse the repository at this point in the history
  • Loading branch information
pmqueiroz committed Dec 2, 2024
1 parent 541865a commit 6427cf0
Showing 1 changed file with 10 additions and 7 deletions.
17 changes: 10 additions & 7 deletions interpreter/interpreter.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,13 +70,16 @@ func Interpret(statement ast.Statement, env *environment.Environment) error {

var output string

if str, ok := value.(string); ok {
str = strings.ReplaceAll(str, "\\n", "\n")
str = strings.ReplaceAll(str, "\\t", "\t")
str = strings.ReplaceAll(str, "\\\"", "\"")
str = strings.ReplaceAll(str, "\\\\", "\\")
output = fmt.Sprint(str)
} else {
switch v := value.(type) {
case string:
v = strings.ReplaceAll(v, "\\n", "\n")
v = strings.ReplaceAll(v, "\\t", "\t")
v = strings.ReplaceAll(v, "\\\"", "\"")
v = strings.ReplaceAll(v, "\\\\", "\\")
output = fmt.Sprint(v)
case float64:
output = fmt.Sprintf("%.f", v)
default:
output = fmt.Sprint(value)
}
channel.Write([]byte(output))
Expand Down

0 comments on commit 6427cf0

Please sign in to comment.