From 39ea4ac3a4b7663882a83f2ada43c8238f087d9b Mon Sep 17 00:00:00 2001 From: Tom Smeding Date: Thu, 23 Jul 2020 20:15:15 +0200 Subject: Use Pretty for errors and expressions --- ast/CC/Source.hs | 18 +++--------------- 1 file changed, 3 insertions(+), 15 deletions(-) (limited to 'ast/CC/Source.hs') diff --git a/ast/CC/Source.hs b/ast/CC/Source.hs index 80d8f01..81e691b 100644 --- a/ast/CC/Source.hs +++ b/ast/CC/Source.hs @@ -26,21 +26,9 @@ data Expr = Call SourceRange Expr Expr deriving (Show, Read) instance Pretty Type where - pretty = unparse - -class Unparse a where - -- Parentheses are required if precedence of unparsed element is - -- greater than the argument. - unparsePrec :: Int -> a -> String - - unparse :: a -> String - unparse = unparsePrec 0 - -instance Unparse Type where - unparsePrec _ TInt = "Int" - unparsePrec p (TFun a b) = - let s = unparsePrec 3 a ++ " -> " ++ unparsePrec 2 b - in if p > 2 then "(" ++ s ++ ")" else s + prettyPrec _ TInt = "Int" + prettyPrec p (TFun a b) = + precParens p 2 (prettyPrec 3 a ++ " -> " ++ prettyPrec 2 b) instance HasRange Expr where range (Call sr _ _) = sr -- cgit v1.2.3-54-g00ecf