3 -- The above warning supression flag is a temporary kludge.
4 -- While working on this module you are encouraged to remove it and fix
5 -- any warnings in the module. See
6 -- http://hackage.haskell.org/trac/ghc/wiki/Commentary/CodingStyle#Warnings
10 parseHaddockParagraphs,
15 import {-# SOURCE #-} HaddockLex
22 %token '/' { TokSpecial '/' }
23 '@' { TokSpecial '@' }
26 DQUO { TokSpecial '\"' }
30 '/../' { TokEmphasis $$ }
33 '>..' { TokBirdTrack $$ }
36 STRING { TokString $$ }
38 %monad { EitherString }
40 %name parseHaddockParagraphs doc
41 %name parseHaddockString seq
45 doc :: { HsDoc RdrName }
46 : apara PARA doc { docAppend $1 $3 }
49 | {- empty -} { DocEmpty }
51 apara :: { HsDoc RdrName }
52 : ulpara { DocUnorderedList [$1] }
53 | olpara { DocOrderedList [$1] }
54 | defpara { DocDefList [$1] }
57 ulpara :: { HsDoc RdrName }
60 olpara :: { HsDoc RdrName }
63 defpara :: { (HsDoc RdrName, HsDoc RdrName) }
64 : '[' seq ']' seq { ($2, $4) }
66 para :: { HsDoc RdrName }
67 : seq { docParagraph $1 }
68 | codepara { DocCodeBlock $1 }
70 codepara :: { HsDoc RdrName }
71 : '>..' codepara { docAppend (DocString $1) $2 }
72 | '>..' { DocString $1 }
74 seq :: { HsDoc RdrName }
75 : elem seq { docAppend $1 $2 }
78 elem :: { HsDoc RdrName }
80 | '@' seq1 '@' { DocMonospaced $2 }
82 seq1 :: { HsDoc RdrName }
83 : PARA seq1 { docAppend (DocString "\n") $2 }
84 | elem1 seq1 { docAppend $1 $2 }
87 elem1 :: { HsDoc RdrName }
88 : STRING { DocString $1 }
89 | '/../' { DocEmphasis (DocString $1) }
92 | ANAME { DocAName $1 }
93 | IDENT { DocIdentifier $1 }
94 | DQUO strings DQUO { DocModule $2 }
98 | STRING strings { $1 ++ $2 }
101 happyError :: [Token] -> EitherString a
102 happyError toks = MyLeft ("parse error in doc string")
104 -- We don't want to make an instance for Either String,
105 -- since every user of the GHC API would get that instance
107 -- But why use non-Haskell98 instances when MyEither String
108 -- is the only MyEither we're intending to use anyway? --Isaac Dupree
109 --data MyEither a b = MyLeft a | MyRight b
110 data EitherString b = MyLeft String | MyRight b
112 instance Monad EitherString where
114 MyLeft l >>= _ = MyLeft l
115 MyRight r >>= k = k r
116 fail msg = MyLeft msg