X-Git-Url: https://git.stderr.nl/gitweb?a=blobdiff_plain;f=Parser.hs;h=44b77ebd4030c18a709d419f5d6373870d229952;hb=dcf9dd6d86a5f256c1129146a977620ab6d8d466;hp=d2bd6515e9db2c476e13b22fe4e733ab844b3e46;hpb=d49dfd213e2cd384bceb38dc70eb122711d4f996;p=matthijs%2Fmaster-project%2Fc%CE%BBash.git diff --git a/Parser.hs b/Parser.hs index d2bd651..44b77eb 100644 --- a/Parser.hs +++ b/Parser.hs @@ -5,27 +5,27 @@ import Language.Haskell.Parser import GHC main = - do - let filename = "adder.hs" - -- Read the file - file <- readFile filename - -- Parse the file - let mode = ParseMode {parseFilename = filename} - ParseOk mod = parseModuleWithMode mode file - -- Print funky stuff - --putStr $ foldl (\s d -> s ++ (show d) ++ "\n\n") "" (decls mod) - putList (findfunc "exp_adder" (decls mod)) + do + let filename = "adder.hs" + -- Read the file + file <- readFile filename + -- Parse the file + let mode = ParseMode {parseFilename = filename} + ParseOk mod = parseModuleWithMode mode file + -- Print funky stuff + --putStr $ foldl (\s d -> s ++ (show d) ++ "\n\n") "" (decls mod) + putList (findfunc "exp_adder" (decls mod)) decls (HsModule _ _ _ _ decls) = - decls + decls name (HsModule _ n _ _ _) = - n + n findfunc :: String -- Function name to find -> [HsDecl] -- Decls to search - -> [HsMatch] + -> [HsMatch] findfunc name decls = foldl (findmatches name) [] decls @@ -35,39 +35,41 @@ findmatches name res _ = res -- Look at a single match and see if it has the sought name filtermatch name (HsMatch _ (HsIdent n) _ _ _) = - n == name + n == name -- Print a list of showable things, separated by newlines instead of , -- Also pretty prints them putList :: (Show a, Pretty a) => [a] -> IO () putList (x:xs) = - do - indent 0 (show x) - putStr "\n" - putStr $ prettyPrint x - putStr "\n\n" - putList xs + do + indent 0 (show x) + putStr "\n" + putStr $ prettyPrint x + putStr "\n\n" + putList xs putList [] = - do return () + do return () -- Add indentations to the given string indent :: Int -> String -> IO () indent n (x:xs) = do - if x `elem` "[(" - then do - putChar x - putStr "\n" - putStr (replicate (n + 1) ' ') - indent (n + 1) xs - else if x `elem` "])" - then do - putStr "\n" - putStr (replicate (n - 1) ' ') - putChar x - indent (n - 1) xs - else do - putChar x - indent n xs + if x `elem` "[(" + then do + putChar x + putStr "\n" + putStr (replicate (n + 1) ' ') + indent (n + 1) xs + else if x `elem` "])" + then do + putStr "\n" + putStr (replicate (n - 1) ' ') + putChar x + indent (n - 1) xs + else do + putChar x + indent n xs indent n [] = do return () + +-- vim: set ts=8 sw=2 sts=2 expandtab: