Commit cb6e9d7e authored by bbr's avatar bbr
Browse files

instance show string repaired

parent 00fb0f56
......@@ -93,12 +93,12 @@ showQStandardList xs = showChar '[' .
foldr (.) (showChar ']')
(intersperse (showChar ',') (map (showQ 0) xs))
fourToInt :: C_Four -> Int
fourToInt C_F0 = 0
fourToInt C_F1 = 1
fourToInt C_F2 = 2
fourToInt C_F3 = 3
fourToInt x = error $ "fourToInt "++show x
fourToInt :: C_Four -> Either String Int
fourToInt C_F0 = Right 0
fourToInt C_F1 = Right 1
fourToInt C_F2 = Right 2
fourToInt C_F3 = Right 3
fourToInt x@(C_FourOr _ _) = Left (show x)
intToFour :: Int -> C_Four
intToFour 0 = C_F0
......@@ -106,8 +106,18 @@ intToFour 1 = C_F1
intToFour 2 = C_F2
intToFour 3 = C_F3
scToChar :: C_Four -> C_Four -> C_Four -> C_Four -> Char
scToChar f1 f2 f3 f4 = chr ((fourToInt f1)*64+(fourToInt f2)*16+(fourToInt f3)*4+(fourToInt f4))
scToChar :: C_Four -> C_Four -> C_Four -> C_Four -> Either String Char
scToChar f1 f2 f3 f4
= chr' ((fourToInt f1**64)+++(fourToInt f2**16)+++(fourToInt f3**4)+++fourToInt f4)
where
Left s ** _ = Left s
Right i ** j = Right (i*j)
Left s +++ _ = Left s
Right i +++ Left s = Left s
Right i +++ Right j = Right (i+j)
chr' (Right i) = Right (chr i)
chr' (Left s) = Left s
charToSc :: Char -> C_Char
charToSc c = SearchChar (intToFour d64) (intToFour d16) (intToFour d4) (intToFour m4)
......@@ -124,7 +134,8 @@ instance Show C_Four where
instance Show C_Char where
show (C_Char c) = show c
show (SearchChar f1 f2 f3 f4) = show (scToChar f1 f2 f3 f4)
show (SearchChar f1 f2 f3 f4)
= either id show (scToChar f1 f2 f3 f4)
show (C_CharOr r _) = '_':show (deref r)
showList cs = if any isFreeChar cs
......@@ -142,14 +153,16 @@ instance Show C_Char where
| oc <= 126 = showLitChar c . showl cs
| otherwise = showString "\\" . shows oc . showl cs
where oc = ord c
showl (SearchChar f1 f2 f3 f4:cs) = showLitChar (scToChar f1 f2 f3 f4) . showl cs
showl (SearchChar f1 f2 f3 f4:cs) =
either showString showLitChar (scToChar f1 f2 f3 f4) . showl cs
showFreel [] = showString "]"
showFreel [C_Char c] = showString (show c) . showString "]"
showFreel (C_Char c:cs) = showString (show c++",") . showFreel cs
showFreel (c@(SearchChar _ _ _ _):cs) = showString (show c++",") . showFreel cs
isFreeChar c = False
showFreel [c] = showString (show c) . showString "]"
showFreel (c:cs) = showString (show c++",") . showFreel cs
isFreeChar (SearchChar f1 f2 f3 f4) =
any ((==Branching) . consKind) [f1,f2,f3,f4]
isFreeChar _ = False
protectEsc p f = f . cont
where cont s@(c:_) | p c = "\\&" ++ s
......@@ -422,7 +435,8 @@ isC_True _ = False
instance ConvertCH C_Char Char where
fromCurry (C_Char c) = c
fromCurry (SearchChar f0 f1 f2 f3) = scToChar f0 f1 f2 f3
fromCurry (SearchChar f0 f1 f2 f3) =
either (error "convert to char") id (scToChar f0 f1 f2 f3)
toCurry c = C_Char c
instance (ConvertCH a b) => ConvertCH (List a) [b] where
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment