diff options
Diffstat (limited to 'src/Language/Haskell/Stylish/Parse.hs')
-rw-r--r-- | src/Language/Haskell/Stylish/Parse.hs | 13 |
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 " ++ |