summaryrefslogtreecommitdiffhomepage
path: root/src
diff options
context:
space:
mode:
authorJasper Van der Jeugt <m@jaspervdj.be>2013-02-07 17:21:04 +0100
committerJasper Van der Jeugt <m@jaspervdj.be>2013-02-07 17:21:04 +0100
commit1bb9662003179fb01a75c5f1290982ef68c7ee20 (patch)
tree2048a06b4e07adc6c096c78823c098b6a06be38b /src
parent00328cbf36029949832e2e39fe65f247b42c579e (diff)
downloadstylish-haskell-1bb9662003179fb01a75c5f1290982ef68c7ee20.tar.gz
Be careful with multiline CPP
Closes #31
Diffstat (limited to 'src')
-rw-r--r--src/Language/Haskell/Stylish/Parse.hs11
1 files changed, 7 insertions, 4 deletions
diff --git a/src/Language/Haskell/Stylish/Parse.hs b/src/Language/Haskell/Stylish/Parse.hs
index 580e0fd..36422d1 100644
--- a/src/Language/Haskell/Stylish/Parse.hs
+++ b/src/Language/Haskell/Stylish/Parse.hs
@@ -6,7 +6,7 @@ module Language.Haskell.Stylish.Parse
--------------------------------------------------------------------------------
import Control.Monad.Error (throwError)
-import Data.Maybe (fromMaybe)
+import Data.Maybe (fromMaybe, listToMaybe)
import qualified Language.Haskell.Exts.Annotated as H
@@ -18,10 +18,13 @@ import Language.Haskell.Stylish.Step
--------------------------------------------------------------------------------
-- | Filter out lines which use CPP macros
unCpp :: String -> String
-unCpp = unlines . map unCpp' . lines
+unCpp = unlines . go False . lines
where
- unCpp' ('#' : _) = ""
- unCpp' xs = xs
+ go _ [] = []
+ go isMultiline (x : xs) =
+ let isCpp = isMultiline || listToMaybe x == Just '#'
+ nextMultiline = isCpp && not (null x) && last x == '\\'
+ in (if isCpp then "" else x) : go nextMultiline xs
--------------------------------------------------------------------------------