Last active
December 10, 2015 05:08
-
-
Save tos-kamiya/4385141 to your computer and use it in GitHub Desktop.
A pretty-printing for Haskell in Haskell. Almost same as http://code.haskell.org/haskell-src-exts/examples/Prettify.hs .
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- references | |
-- http://code.haskell.org/haskell-src-exts/Test/examples/HaskellParser.hs | |
-- http://code.haskell.org/haskell-src-exts/examples/Prettify.hs | |
import qualified Language.Haskell.Exts.Annotated as P | |
import qualified Language.Haskell.Exts.Extension as Ext | |
import Language.Haskell.Exts.Pretty (prettyPrint) | |
import System.Environment (getArgs) | |
parse originalFileName input = P.parseModuleWithMode parseMode input | |
where | |
parseMode :: P.ParseMode | |
parseMode = P.defaultParseMode | |
{ P.parseFilename = originalFileName | |
, P.extensions = Ext.glasgowExts ++ | |
[ Ext.ExplicitForAll | |
, Ext.DoAndIfThenElse | |
] | |
} | |
main = | |
do args <- getArgs | |
case args of | |
[] -> putStrLn usage | |
(_:_:_) -> fail "too many command-line arguments" | |
[fileName] -> | |
do s <- readFile fileName | |
let x = parse fileName s | |
putStrLn $ case x of | |
P.ParseOk h -> | |
prettyPrint h | |
P.ParseFailed srcLoc message -> | |
unlines [ prettyPrint srcLoc | |
, message | |
] | |
where usage = "Prettify.hs <source.hs>" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment