aboutsummaryrefslogtreecommitdiff
path: root/src/Haddock/Parser
diff options
context:
space:
mode:
authorMateusz Kowalczyk <fuuzetsu@fuuzetsu.co.uk>2014-01-10 05:37:17 +0000
committerAustin Seipp <austin@well-typed.com>2014-01-12 14:48:35 -0600
commitef9aa98d6ccbe79888c501f94c9aa6688520c28e (patch)
treec8b86e469383ebcac5472300608355d410e6942a /src/Haddock/Parser
parentd08865e42e7b03348549b79cdc251f444516bc34 (diff)
Support for bold.
Conflicts: src/Haddock/Backends/Hoogle.hs src/Haddock/Interface/Rename.hs src/Haddock/Parser.hs
Diffstat (limited to 'src/Haddock/Parser')
-rw-r--r--src/Haddock/Parser/Util.hs22
1 files changed, 22 insertions, 0 deletions
diff --git a/src/Haddock/Parser/Util.hs b/src/Haddock/Parser/Util.hs
new file mode 100644
index 00000000..ea682601
--- /dev/null
+++ b/src/Haddock/Parser/Util.hs
@@ -0,0 +1,22 @@
+module Haddock.Parser.Util where
+
+import Control.Applicative
+import Control.Monad
+import Data.Attoparsec.ByteString.Char8
+import Data.ByteString.Char8 (ByteString)
+import qualified Data.ByteString.Char8 as BS
+
+takeUntil :: ByteString -> Parser ByteString
+takeUntil end_ = dropEnd <$> requireEnd (scan (False, end) p)
+ where
+ end = BS.unpack end_
+
+ p :: (Bool, String) -> Char -> Maybe (Bool, String)
+ p acc c = case acc of
+ (True, _) -> Just (False, end)
+ (_, []) -> Nothing
+ (_, x:xs) | x == c -> Just (False, xs)
+ _ -> Just (c == '\\', end)
+
+ dropEnd = BS.reverse . BS.drop (length end) . BS.reverse
+ requireEnd = mfilter (BS.isSuffixOf end_)