diff options
author | Jasper Van der Jeugt <m@jaspervdj.be> | 2012-05-25 13:19:09 +0200 |
---|---|---|
committer | Jasper Van der Jeugt <m@jaspervdj.be> | 2012-05-25 13:19:09 +0200 |
commit | b9a5999560993cd5f9ea368ba4115ff370ecc1ac (patch) | |
tree | a513eb47c00c396aa6a341517d7b778343077b8e /src/Main.hs | |
parent | ae037aa1c03e63c66a003f02f30bceddd8de2297 (diff) | |
download | stylish-haskell-b9a5999560993cd5f9ea368ba4115ff370ecc1ac.tar.gz |
Use haskell-src-exts
Diffstat (limited to 'src/Main.hs')
-rw-r--r-- | src/Main.hs | 27 |
1 files changed, 20 insertions, 7 deletions
diff --git a/src/Main.hs b/src/Main.hs index 7a325f3..d975f5f 100644 --- a/src/Main.hs +++ b/src/Main.hs @@ -1,21 +1,34 @@ +-------------------------------------------------------------------------------- module Main ( main ) where -------------------------------------------------------------------------------- -import Control.Monad ((>=>)) -import System.Environment (getArgs) +import Control.Applicative ((<$>)) +import Data.Maybe (listToMaybe) +import System.Environment (getArgs) + + +-------------------------------------------------------------------------------- +import StylishHaskell.Editor +import StylishHaskell.Imports +import StylishHaskell.Parse -------------------------------------------------------------------------------- -import StylishHaskellImports +stylishHaskell :: Maybe FilePath -> String -> IO () +stylishHaskell mfp string = case parseModule mfp string of + Left err -> error err + Right module' -> do + let ls = lines string + changes = stylish ls module' + putStr $ unlines $ applyChanges changes ls -------------------------------------------------------------------------------- main :: IO () main = do - args <- getArgs - case args of - [] -> interact stylishHaskellImports - _ -> mapM_ (readFile >=> putStr . stylishHaskellImports) args + filePath <- listToMaybe <$> getArgs + contents <- maybe getContents readFile filePath + stylishHaskell filePath contents |