summaryrefslogtreecommitdiffhomepage
path: root/src
diff options
context:
space:
mode:
authorJasper Van der Jeugt <m@jaspervdj.be>2012-07-08 13:12:34 +0200
committerJasper Van der Jeugt <m@jaspervdj.be>2012-07-08 13:12:34 +0200
commit3598ec21fbd215350940ae064c38f0c756cef916 (patch)
treec24f9c111af71fadb0f90ddc49577aa54ca9c232 /src
parent3ce343735d026d86934298bf1a43f8d0c0e3ebad (diff)
downloadstylish-haskell-3598ec21fbd215350940ae064c38f0c756cef916.tar.gz
Ignore UTF-8 BOM while parsing
See #3
Diffstat (limited to 'src')
-rw-r--r--src/StylishHaskell/Parse.hs12
1 files changed, 10 insertions, 2 deletions
diff --git a/src/StylishHaskell/Parse.hs b/src/StylishHaskell/Parse.hs
index 24aa8f2..97e9044 100644
--- a/src/StylishHaskell/Parse.hs
+++ b/src/StylishHaskell/Parse.hs
@@ -25,6 +25,14 @@ unCpp = unlines . map unCpp' . lines
--------------------------------------------------------------------------------
+-- | 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
+dropBom ('\xfeff' : str) = str
+dropBom str = str
+
+
+--------------------------------------------------------------------------------
-- | Read an extension name from a string
parseExtension :: String -> Either String H.Extension
parseExtension str = case reads str of
@@ -46,8 +54,8 @@ parseModule extraExts mfp string = do
mode = H.defaultParseMode
{H.extensions = exts, H.fixities = Nothing}
- -- Special handling for CPP, haskell-src-exts can't deal with it
- string' = if H.CPP `elem` exts then unCpp string else string
+ -- Preprocessing
+ string' = dropBom $ (if H.CPP `elem` exts then unCpp else id) $ string
case H.parseModuleWithComments mode string' of
H.ParseOk md -> return md