summaryrefslogtreecommitdiffhomepage
path: root/src
diff options
context:
space:
mode:
authorJasper Van der Jeugt <m@jaspervdj.be>2015-04-19 13:42:41 +0200
committerJasper Van der Jeugt <m@jaspervdj.be>2015-04-19 13:44:06 +0200
commit86352f21d4c2a5a83a85654e403f9fc3ed326cea (patch)
treef572c224f63354d95650870c9eaafb534a7bc008 /src
parent7c8a55767f852110e99d5015dc8c72286da3a59b (diff)
downloadstylish-haskell-86352f21d4c2a5a83a85654e403f9fc3ed326cea.tar.gz
Add support for shebang at start of file
Fixes #86
Diffstat (limited to 'src')
-rw-r--r--src/Language/Haskell/Stylish/Parse.hs13
1 files changed, 11 insertions, 2 deletions
diff --git a/src/Language/Haskell/Stylish/Parse.hs b/src/Language/Haskell/Stylish/Parse.hs
index 8b3d34b..a3ef579 100644
--- a/src/Language/Haskell/Stylish/Parse.hs
+++ b/src/Language/Haskell/Stylish/Parse.hs
@@ -7,6 +7,7 @@ module Language.Haskell.Stylish.Parse
--------------------------------------------------------------------------------
import Data.Maybe (fromMaybe, listToMaybe)
import qualified Language.Haskell.Exts.Annotated as H
+import Data.List (isPrefixOf)
--------------------------------------------------------------------------------
@@ -27,6 +28,14 @@ unCpp = unlines . go False . lines
--------------------------------------------------------------------------------
+-- | Remove shebang from the first line
+unShebang :: String -> String
+unShebang str
+ | "#!" `isPrefixOf` str = unlines $ drop 1 $ lines str
+ | otherwise = str
+
+
+--------------------------------------------------------------------------------
-- | If the given string is prefixed with an UTF-8 Byte Order Mark, drop it
-- because haskell-src-exts can't handle it.
dropBom :: String -> String
@@ -55,10 +64,10 @@ parseModule extraExts mfp string = do
}
-- Preprocessing
- noCpp =
+ processed = unShebang $
if H.EnableExtension H.CPP `elem` exts then unCpp noBom else noBom
- case H.parseModuleWithComments mode noCpp of
+ case H.parseModuleWithComments mode processed of
H.ParseOk md -> return md
err -> Left $
"Language.Haskell.Stylish.Parse.parseModule: could not parse " ++