diff options
| author | Joel Martin <github@martintribe.org> | 2014-10-06 20:36:23 -0500 |
|---|---|---|
| committer | Joel Martin <github@martintribe.org> | 2014-10-06 20:36:23 -0500 |
| commit | af8fdff41e260b1b21be0e127afb536980f43804 (patch) | |
| tree | 6dc9b5d54a38c6197001291cf85cdffc7cf100b7 /go/src/printer/printer.go | |
| parent | 9feb2c9527294d82592bf35b97f8039f61bbec45 (diff) | |
| download | mal-af8fdff41e260b1b21be0e127afb536980f43804.tar.gz mal-af8fdff41e260b1b21be0e127afb536980f43804.zip | |
go: add step4_if_fn_do
Diffstat (limited to 'go/src/printer/printer.go')
| -rw-r--r-- | go/src/printer/printer.go | 18 |
1 files changed, 11 insertions, 7 deletions
diff --git a/go/src/printer/printer.go b/go/src/printer/printer.go index fa1c0fb..8cb4a40 100644 --- a/go/src/printer/printer.go +++ b/go/src/printer/printer.go @@ -9,20 +9,21 @@ import ( "types" ) -func _pr_list(lst []types.MalType, pr bool, start string, end string) string { +func Pr_list(lst []types.MalType, pr bool, + start string, end string, join string) string { str_list := make([]string, 0, len(lst)) for _, e := range lst { str_list = append(str_list, Pr_str(e, pr)) } - return start + strings.Join(str_list, " ") + end + return start + strings.Join(str_list, join) + end } func Pr_str(obj types.MalType, print_readably bool) string { switch tobj := obj.(type) { case types.List: - return _pr_list(tobj.Val, print_readably, "(", ")") + return Pr_list(tobj.Val, print_readably, "(", ")", " ") case types.Vector: - return _pr_list(tobj.Val, print_readably, "[", "]") + return Pr_list(tobj.Val, print_readably, "[", "]", " ") case map[string]types.MalType: str_list := make([]string, 0, len(tobj)*2) for k, v := range tobj { @@ -32,10 +33,13 @@ func Pr_str(obj types.MalType, print_readably bool) string { return "{" + strings.Join(str_list, " ") + "}" case string: if print_readably { - // TODO: quote backslash, quote, and newline - return `"` + fmt.Sprintf("%v", obj) + `"` + return `"` + strings.Replace( + strings.Replace( + strings.Replace(tobj,`\`,`\\`, -1), + `"`, `\"`, -1), + "\n", `\n`, -1) + `"` } else { - return fmt.Sprintf("%v", obj) + return tobj } case types.Symbol: return tobj.Val |
