diff options
| author | Chouser <chouser@n01se.net> | 2015-01-28 08:27:32 -0500 |
|---|---|---|
| committer | Chouser <chouser@n01se.net> | 2015-01-30 12:54:43 -0500 |
| commit | 16b177329cac77136b236dfb3645e4be4e3df297 (patch) | |
| tree | aa70f831b5f50212ab53e7d6ad8ab89603f89ec9 /ocaml/printer.ml | |
| parent | cc916d9d819d17cc47d34321440bf5a2683eac2e (diff) | |
| download | mal-16b177329cac77136b236dfb3645e4be4e3df297.tar.gz mal-16b177329cac77136b236dfb3645e4be4e3df297.zip | |
Ocaml: fix string escaping and printing
Diffstat (limited to 'ocaml/printer.ml')
| -rw-r--r-- | ocaml/printer.ml | 6 |
1 files changed, 5 insertions, 1 deletions
diff --git a/ocaml/printer.ml b/ocaml/printer.ml index 8e71376..fe025af 100644 --- a/ocaml/printer.ml +++ b/ocaml/printer.ml @@ -19,7 +19,11 @@ let rec pr_str mal_obj print_readably = | T.Bool false -> "false" | T.String s -> if r - then "\"" ^ (Str.global_replace (Str.regexp "\\([\"\\]\\)") "\\\\\\1" s) ^ "\"" + then "\"" ^ (Reader.gsub (Str.regexp "\\([\"\\\n]\\)") + (function + | "\n" -> "\\n" + | x -> "\\" ^ x) + s) ^ "\"" else s | T.List { T.value = xs } -> "(" ^ (String.concat " " (List.map (fun s -> pr_str s r) xs)) ^ ")" |
