on master help sign in
Merge pull request #669 from Melvar/showstring
4f1b604Edwin Brady
idris.cabal+1−1
@@ -395,7 +395,7 @@ Executable idris
395 , directory >= 1.2
395 , directory >= 1.2
396 , filepath
396 , filepath
397 , haskeline >= 0.7
397 , haskeline >= 0.7
398− , language-java >= 0.2.2
398+ , language-java >= 0.2.6
399 , mtl
399 , mtl
400 --, parsec >= 3
400 --, parsec >= 3
401 , parsers == 0.9
401 , parsers == 0.9
libs/prelude/Prelude.idr+39−2
@@ -40,11 +40,48 @@ instance Show Integer where
40instance Show Float where
40instance Show Float where
41 show = prim__floatToStr
41 show = prim__floatToStr
42
42
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"]
48+
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
53+
54+protectEsc : (Char -> Bool) -> String -> String -> String
55+protectEsc p f s = f ++ (if firstCharIs p s then "\\&" else "") ++ s
56+
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))
72+ else strCons c
73+
74+showLitString : List Char -> String -> String
75+showLitString [] = id
76+showLitString ('"'::cs) = ("\\\"" ++) . showLitString cs
77+showLitString (c ::cs) = showLitChar c . showLitString cs
78+
43instance Show Char where
79instance Show Char where
44− show x = strCons x ""
80+ show '\'' = "'\\''"
81+ show c = strCons '\'' (showLitChar c "'")
45
82
46instance Show String where
83instance Show String where
47− show = id
84+ show cs = strCons '"' (showLitString (cast cs) "\"")
48
85
49instance Show Nat where
86instance Show Nat where
50 show n = show (the Integer (cast n))
87 show n = show (the Integer (cast n))
src/IRTS/CodegenC.hs+1−1
@@ -201,7 +201,7 @@ bcc i (CONSTCASE r code def)
201 indent i ++ "if (GETINT(" ++ v ++ ") == " ++ show b ++ ") {\n"
201 indent i ++ "if (GETINT(" ++ v ++ ") == " ++ show b ++ ") {\n"
202 ++ concatMap (bcc (i+1)) bc ++ indent i ++ "} else\n"
202 ++ concatMap (bcc (i+1)) bc ++ indent i ++ "} else\n"
203 iCase v (Ch b, bc) =
203 iCase v (Ch b, bc) =
204− indent i ++ "if (GETINT(" ++ v ++ ") == " ++ show b ++ ") {\n"
204+ indent i ++ "if (GETINT(" ++ v ++ ") == " ++ show (fromEnum b) ++ ") {\n"
205 ++ concatMap (bcc (i+1)) bc ++ indent i ++ "} else\n"
205 ++ concatMap (bcc (i+1)) bc ++ indent i ++ "} else\n"
206
206
207 showCase i (t, bc) = indent i ++ "case " ++ show t ++ ":\n"
207 showCase i (t, bc) = indent i ++ "case " ++ show t ++ ":\n"
src/IRTS/Java/JTypes.hs+1
@@ -218,6 +218,7 @@ opName x
218 | (LTrunc _ to) <- x = "LTrunc" ++ (suffixFor to)
218 | (LTrunc _ to) <- x = "LTrunc" ++ (suffixFor to)
219 | (LFloatInt to) <- x = "LFloatInt" ++ (suffixFor to)
219 | (LFloatInt to) <- x = "LFloatInt" ++ (suffixFor to)
220 | (LStrInt to) <- x = "LStrInt" ++ (suffixFor to)
220 | (LStrInt to) <- x = "LStrInt" ++ (suffixFor to)
221+ | (LChInt to) <- x = "LChInt" ++ (suffixFor to)
221 | otherwise = takeWhile ((/=) ' ') $ show x
222 | otherwise = takeWhile ((/=) ' ') $ show x
222 where
223 where
223 suffixFor (ITFixed nt) = show nt
224 suffixFor (ITFixed nt) = show nt
test/reg005/reg005.idr+1−1
@@ -30,7 +30,7 @@ compress xs with (rle xs)
30 compress Nil | REnd = ""
30 compress Nil | REnd = ""
31 compress (rep (S n) x ++ xs) | RChar _ _ rs
31 compress (rep (S n) x ++ xs) | RChar _ _ rs
32 = let ni : Integer = cast (S n) in
32 = let ni : Integer = cast (S n) in
33− show ni ++ show x ++ compress xs
33+ show ni ++ strCons x (compress xs)
34
34
35compressString : String -> String
35compressString : String -> String
36compressString xs = compress (fromList (unpack xs))
36compressString xs = compress (fromList (unpack xs))
test/reg024/reg024.idr+1−1
@@ -28,4 +28,4 @@ test : String
28test = printf "The %s is %d" "answer" 42
28test = printf "The %s is %d" "answer" 42
29
29
30main : IO ()
30main : IO ()
31−main = print test
31+main = putStrLn test
test/reg025/reg025.idr+2−2
@@ -70,6 +70,6 @@ emptyCell (MkBoard rs) =
70main : IO ()
70main : IO ()
71main =
71main =
72 case emptyCell (emptyBoard {n=0}) of
72 case emptyCell (emptyBoard {n=0}) of
73− Left _ => print "l"
73+ Left _ => putStrLn "l"
74− Right _ => print "r"
74+ Right _ => putStrLn "r"
75
75
test/test003/expected+3−3
@@ -1,7 +1,7 @@
1./test003a.lidr:1:0:Program line next to comment
1./test003a.lidr:1:0:Program line next to comment
2−a
2+'a'
3−d
3+'d'
4zabcdefg
4zabcdefg
5gfedcba
5gfedcba
6−[g, f, e, d, c, b, a]
6+['g', 'f', 'e', 'd', 'c', 'b', 'a']
7abcdefg
7abcdefg
test/test005/expected+2−2
@@ -1,6 +1,6 @@
18
18
21
21
3−(abc, 123)
3+("abc", "123")
4−(abc, 123)
4+("abc", "123")
5([1, 2], [3, 4, 5])
5([1, 2], [3, 4, 5])
6([1, 2], [3, 4, 5])
6([1, 2], [3, 4, 5])
test/test008/test008.idr+1−1
@@ -18,7 +18,7 @@ ioVals = do { return ("First", "second") }
18
18
19main : IO ()
19main : IO ()
20main = do (a, b) <- ioVals
20main = do (a, b) <- ioVals
21− putStr (show a ++ " and " ++ show b ++ "? ")
21+ putStr (a ++ " and " ++ b ++ "? ")
22 let x = "bar"
22 let x = "bar"
23 putStrLn (show (getVal x 7 testlist))
23 putStrLn (show (getVal x 7 testlist))
24 let ((y, z) :: _) = testlist
24 let ((y, z) :: _) = testlist
test/test011/expected+3−3
@@ -1,5 +1,5 @@
1−foo
1+"foo"
2−Fred
2+"Fred"
3[1, 2, 3]
3[1, 2, 3]
4−[b, a]
4+["b", "a"]
525
525
test/test020/expected+1−1
@@ -11,4 +11,4 @@ Specifically:
11 List a
11 List a
12
12
13[3, 2, 1]
13[3, 2, 1]
14−Number 42
14+"Number 42"
test/test021/expected+1−3
@@ -1,6 +1,4 @@
1−[HELLO!!!
1+["HELLO!!!\n", "WORLD!!!\n", ""]
2−, WORLD!!!
3−, ]
43
23
515
315
6Answer: 99
4Answer: 99
test/test028/test028.idr+1−1
@@ -2,4 +2,4 @@
2module Main
2module Main
3--
3--
4main : IO ()
4main : IO ()
5−main = print "hello, world!"
5+main = putStrLn "hello, world!"
test/test034/expected+1−1
@@ -1,5 +1,5 @@
1prim__floatToStr 0.0
1prim__floatToStr 0.0
2−0.0
2+"0.0"
3prim__strToFloat "0.0"
3prim__strToFloat "0.0"
40.0
40.0
5prim__addFloat 1.0 1.0
5prim__addFloat 1.0 1.0