module Type where
import HSE.All
import Data.Char
import Language.Haskell.HsColour.TTY
import Language.Haskell.HsColour.Colourise
data Rank = Ignore | Warning | Error
deriving (Eq,Ord,Show)
type FuncName = (String,String)
data Setting
= Classify {rankS :: Rank, hintS :: String, funcS :: FuncName}
| MatchExp {rankS :: Rank, hintS :: String, lhs :: Exp_, rhs :: Exp_, side :: Maybe Exp_}
| Builtin String
deriving Show
data Idea
= Idea {func :: FuncName, rank :: Rank, hint :: String, loc :: SrcLoc, from :: String, to :: String}
| ParseError {rank :: Rank, hint :: String, loc :: SrcLoc, msg :: String, from :: String}
deriving Eq
isClassify Classify{} = True; isClassify _ = False
isMatchExp MatchExp{} = True; isMatchExp _ = False
isParseError ParseError{} = True; isParseError _ = False
instance Show Idea where
show = showEx id
showANSI :: IO (Idea -> String)
showANSI = do
prefs <- readColourPrefs
return $ showEx (hscolour prefs)
showEx :: (String -> String) -> Idea -> String
showEx tt Idea{..} = unlines $
[showSrcLoc loc ++ " " ++ show rank ++ ": " ++ hint] ++ f "Found" from ++ f "Why not" to
where f msg x = (msg ++ ":") : map (" "++) (lines $ tt x)
showEx tt ParseError{..} = unlines $
[showSrcLoc loc ++ " Parse error","Error message:"," " ++ msg,"Code:"] ++ map (" "++) (lines $ tt from)
rawIdea = Idea ("","")
idea rank hint from to = rawIdea rank hint (toSrcLoc $ ann from) (f from) (f to)
where f = dropWhile isSpace . prettyPrint
warn = idea Warning
err = idea Error
isUnifyVar :: String -> Bool
isUnifyVar [x] = x == '?' || isAlpha x
isUnifyVar _ = False