blob: 29da91c08304f4ce78b832be86bef9ffe24fdc05 (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
|
module Haddock.Parser.Util where
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)
{-# DEPRECATED parseParasMaybe "use `parseParas` instead" #-}
parseParasMaybe :: DynFlags -> String -> Maybe (Doc RdrName)
parseParasMaybe d = Just . overIdentifier (parseIdent d) . parseParas
{-# DEPRECATED parseStringMaybe "use `parseString` instead" #-}
parseStringMaybe :: DynFlags -> String -> Maybe (Doc RdrName)
parseStringMaybe d = Just . overIdentifier (parseIdent d) . parseString
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
|