@@ -40,11 +40,48 @@ instance Show Integer where
40instance Show Float where
40instance Show Float where
41 show = prim__floatToStr
41 show = prim__floatToStr
43+asciiTab : Vect 32 String
44+asciiTab = ["NUL", "SOH", "STX", "ETX", "EOT", "ENQ", "ACK", "BEL",
45+ "BS", "HT", "LF", "VT", "FF", "CR", "SO", "SI",
46+ "DLE", "DC1", "DC2", "DC3", "DC4", "NAK", "SYN", "ETB",
47+ "CAN", "EM", "SUB", "ESC", "FS", "GS", "RS", "US"]
49+firstCharIs : (Char -> Bool) -> String -> Bool
50+firstCharIs p s with (strM s)
51+ firstCharIs p "" | StrNil = False
52+ firstCharIs p (strCons c cs) | StrCons c cs = p c
54+protectEsc : (Char -> Bool) -> String -> String -> String
55+protectEsc p f s = f ++ (if firstCharIs p s then "\\&" else "") ++ s
57+showLitChar : Char -> String -> String
58+showLitChar '\a' = ("\\a" ++)
59+showLitChar '\b' = ("\\b" ++)
60+showLitChar '\f' = ("\\f" ++)
61+showLitChar '\n' = ("\\n" ++)
62+showLitChar '\r' = ("\\r" ++)
63+showLitChar '\t' = ("\\t" ++)
64+showLitChar '\v' = ("\\v" ++)
65+showLitChar '\SO' = protectEsc (== 'H') "\\SO"
66+showLitChar '\DEL' = ("\\DEL" ++)
67+showLitChar '\\' = ("\\\\" ++)
68+showLitChar c = case (integerToFin (cast (cast {to=Int} c)) 32) of
69+ Just k => strCons '\\' . ((index k asciiTab) ++)
70+ Nothing => if (c > '\DEL')
71+ then strCons '\\' . protectEsc isDigit (show (cast {to=Int} c))
74+showLitString : List Char -> String -> String
76+showLitString ('"'::cs) = ("\\\"" ++) . showLitString cs
77+showLitString (c ::cs) = showLitChar c . showLitString cs
43instance Show Char where
79instance Show Char where
44− show x = strCons x ""
80+ show '\'' = "'\\''"
81+ show c = strCons '\'' (showLitChar c "'")
46instance Show String where
83instance Show String where
47− show = id
84+ show cs = strCons '"' (showLitString (cast cs) "\"")
49instance Show Nat where
86instance Show Nat where
50 show n = show (the Integer (cast n))
87 show n = show (the Integer (cast n))