module Main where import Data.List vToDot :: String -> String vToDot ls = "digraph {\n" ++ (snd $ vToDotP (lines ls, "")) ++ "}\n" type Parser = ([String], String) -> ([String], String) vToDotP :: Parser vToDotP ([], t) = ([], t) vToDotP (l:ls, t) = case (isPrefixOf "package" l) && (isInfixOf "unusable" l) of True -> vToDotP $ unusableP (l:ls, t) False -> vToDotP (ls, t) unusableP :: Parser unusableP (l:ls, t) = (sls, t ++ ('\n' : l') ++ "{\n" ++ st ++ "\n }\n") where (sls, st) = spacesP (ls, t) l' = '"' : (words l !! 1) ++ "\" -> " spacesP :: Parser spacesP (l:ls, _) = case (isPrefixOf " " l) of True -> (ls, wrap l) False -> (l:ls, "") where wrap xs = intercalate ",\n" $ map (\x -> " \"" ++ x ++ "\"") (words xs) main :: IO () main = interact vToDot