aboutsummaryrefslogtreecommitdiff
path: root/src/Haddock/Parser/Util.hs
diff options
context:
space:
mode:
authorMateusz Kowalczyk <fuuzetsu@fuuzetsu.co.uk>2014-05-05 05:16:19 +0200
committerMateusz Kowalczyk <fuuzetsu@fuuzetsu.co.uk>2014-05-05 09:19:49 +0200
commit7ac2d0f2d31c2e1c7ede09828f3d5ba5626bd0d4 (patch)
tree646d89bbeeb15e7e163788d335ccb74b5e3654a2 /src/Haddock/Parser/Util.hs
parentdba02d6df32534aac5d257f2d28596238d248942 (diff)
Prepare modules for parser split.
We have to generalise the Doc (now DocH) slightly to remove the dependency on GHC-supplied type.
Diffstat (limited to 'src/Haddock/Parser/Util.hs')
-rw-r--r--src/Haddock/Parser/Util.hs44
1 files changed, 23 insertions, 21 deletions
diff --git a/src/Haddock/Parser/Util.hs b/src/Haddock/Parser/Util.hs
index 92fa7448..29da91c0 100644
--- a/src/Haddock/Parser/Util.hs
+++ b/src/Haddock/Parser/Util.hs
@@ -1,26 +1,28 @@
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
+import DynFlags (DynFlags)
+import FastString (mkFastString)
+import Haddock.Types
+import Haddock.Parser
+import Lexer (mkPState, unP, ParseResult(POk))
+import Parser (parseIdentifier)
+import RdrName (RdrName)
+import SrcLoc (mkRealSrcLoc, unLoc)
+import StringBuffer (stringToStringBuffer)
-takeUntil :: ByteString -> Parser ByteString
-takeUntil end_ = dropEnd <$> requireEnd (scan (False, end) p) >>= gotSome
- where
- end = BS.unpack end_
+{-# DEPRECATED parseParasMaybe "use `parseParas` instead" #-}
+parseParasMaybe :: DynFlags -> String -> Maybe (Doc RdrName)
+parseParasMaybe d = Just . overIdentifier (parseIdent d) . parseParas
- 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)
+{-# DEPRECATED parseStringMaybe "use `parseString` instead" #-}
+parseStringMaybe :: DynFlags -> String -> Maybe (Doc RdrName)
+parseStringMaybe d = Just . overIdentifier (parseIdent d) . parseString
- dropEnd = BS.reverse . BS.drop (length end) . BS.reverse
- requireEnd = mfilter (BS.isSuffixOf end_)
-
- gotSome xs
- | BS.null xs = fail "didn't get any content"
- | otherwise = return xs
+parseIdent :: DynFlags -> String -> Maybe RdrName
+parseIdent dflags str0 =
+ let buffer = stringToStringBuffer str0
+ realSrcLc = mkRealSrcLoc (mkFastString "<unknown file>") 0 0
+ pstate = mkPState dflags buffer realSrcLc
+ in case unP parseIdentifier pstate of
+ POk _ name -> Just (unLoc name)
+ _ -> Nothing