X-Git-Url: http://git.megacz.com/?a=blobdiff_plain;f=compiler%2Fparser%2FHaddockParse.y;h=c0f64d45ad26451a749a0b01d94fb3127acffe0f;hb=a4005d2d0c18ffa72ba7bd0fa052666e70e8c16e;hp=880652e5b58b2ae37dbb841652fed5162af185f0;hpb=7fc749a43b4b6b85d234fa95d4928648259584f4;p=ghc-hetmet.git diff --git a/compiler/parser/HaddockParse.y b/compiler/parser/HaddockParse.y index 880652e..c0f64d4 100644 --- a/compiler/parser/HaddockParse.y +++ b/compiler/parser/HaddockParse.y @@ -1,18 +1,24 @@ { -{-# OPTIONS -w #-} +{-# OPTIONS -Wwarn -w #-} -- The above warning supression flag is a temporary kludge. -- While working on this module you are encouraged to remove it and fix -- any warnings in the module. See -- http://hackage.haskell.org/trac/ghc/wiki/Commentary/CodingStyle#Warnings -- for details -module HaddockParse (parseHaddockParagraphs, parseHaddockString) where +module HaddockParse ( + parseHaddockParagraphs, + parseHaddockString, + EitherString(..) +) where import {-# SOURCE #-} HaddockLex import HsSyn import RdrName } +%expect 0 + %tokentype { Token } %token '/' { TokSpecial '/' } @@ -21,7 +27,9 @@ import RdrName ']' { TokDefEnd } DQUO { TokSpecial '\"' } URL { TokURL $$ } + PIC { TokPic $$ } ANAME { TokAName $$ } + '/../' { TokEmphasis $$ } '-' { TokBullet } '(n)' { TokNumber } '>..' { TokBirdTrack $$ } @@ -29,7 +37,7 @@ import RdrName PARA { TokPara } STRING { TokString $$ } -%monad { Either String } +%monad { EitherString } %name parseHaddockParagraphs doc %name parseHaddockString seq @@ -74,13 +82,15 @@ elem :: { HsDoc RdrName } | '@' seq1 '@' { DocMonospaced $2 } seq1 :: { HsDoc RdrName } - : elem1 seq1 { docAppend $1 $2 } + : PARA seq1 { docAppend (DocString "\n") $2 } + | elem1 seq1 { docAppend $1 $2 } | elem1 { $1 } elem1 :: { HsDoc RdrName } : STRING { DocString $1 } - | '/' strings '/' { DocEmphasis (DocString $2) } + | '/../' { DocEmphasis (DocString $1) } | URL { DocURL $1 } + | PIC { DocPic $1 } | ANAME { DocAName $1 } | IDENT { DocIdentifier $1 } | DQUO strings DQUO { DocModule $2 } @@ -90,16 +100,20 @@ strings :: { String } | STRING strings { $1 ++ $2 } { -happyError :: [Token] -> Either String a -happyError toks = --- Left ("parse error in doc string: " ++ show (take 3 toks)) - Left ("parse error in doc string") - --- Either monad (we can't use MonadError because GHC < 5.00 has --- an older incompatible version). -instance Monad (Either String) where - return = Right - Left l >>= _ = Left l - Right r >>= k = k r - fail msg = Left msg +happyError :: [Token] -> EitherString a +happyError toks = MyLeft ("parse error in doc string") + +-- We don't want to make an instance for Either String, +-- since every user of the GHC API would get that instance + +-- But why use non-Haskell98 instances when MyEither String +-- is the only MyEither we're intending to use anyway? --Isaac Dupree +--data MyEither a b = MyLeft a | MyRight b +data EitherString b = MyLeft String | MyRight b + +instance Monad EitherString where + return = MyRight + MyLeft l >>= _ = MyLeft l + MyRight r >>= k = k r + fail msg = MyLeft msg }