shithub: MicroHs

Download patch

ref: c4ba9a949536b44d71891791b7486548a3c3c213
parent: 98b9766e697d613874e67aaa1503d9accc94ae59
author: Lennart Augustsson <lennart@augustsson.net>
date: Thu Nov 2 10:26:20 EDT 2023

Fix quoting problem.

--- a/lib/Data/Char.hs
+++ b/lib/Data/Char.hs
@@ -84,10 +84,13 @@
           | True = c
 
 instance Show Char where
+  showsPrec _ '\'' = showString "'\\''"
   showsPrec _ c = showChar '\'' . showString (encodeChar c) . showChar '\''
   showList    s = showChar '"'  . f s
     where f [] = showChar '"'
-          f (c:cs) = showString (encodeChar c) . f cs
+          f (c:cs) =
+            if c == '"' then showString "\\\"" . f cs
+            else showString (encodeChar c) . f cs
 
 -- XXX should not export this
 encodeChar :: Char -> String
@@ -94,7 +97,7 @@
 encodeChar c =
   let
     spec = [('\n', "\\n"), ('\r', "\\r"), ('\t', "\\t"), ('\b', "\\b"),
-            ('\\', "\\\\"), ('\'', "\\'"), ('"', "\"")]
-    look [] = if isPrint c then [c] else "XXX"  -- "'\\" ++ showInt (ord c) ++ "'"
+            ('\\', "\\\\")]
+    look [] = if isPrint c then [c] else "'\\" ++ show (ord c) ++ "'"
     look ((d,s):xs) = if d == c then s else look xs
   in look spec
--