git.iko.soy/typeable/pandoc
on master help sign in
Merge pull request #808 from davidlazar/master
5aec167John MacFarlane
src/Text/Pandoc/Readers/Haddock.hs+4−2
@@ -24,8 +24,10 @@ readHaddock :: ReaderOptions -- ^ Reader options
24readHaddock _ s = Pandoc (Meta [] [] []) blocks
24readHaddock _ s = Pandoc (Meta [] [] []) blocks
25 where
25 where
26 blocks = case parseParas (tokenise s (0,0)) of
26 blocks = case parseParas (tokenise s (0,0)) of
27− Nothing -> []
27+ Left [] -> error "parse failure"
28+ Left (tok:_) -> error $ "parse failure " ++ pos (tokenPos tok)
29+ where pos (l, c) = "(line " ++ show l ++ ", column " ++ show c ++ ")"
28− Just x -> mergeLists (toList x)
30+ Right x -> mergeLists (toList x)
29
31
30-- similar to 'docAppend' in Haddock.Doc
32-- similar to 'docAppend' in Haddock.Doc
31mergeLists :: [Block] -> [Block]
33mergeLists :: [Block] -> [Block]
src/Text/Pandoc/Readers/Haddock/Lex.x+5−3
@@ -19,7 +19,8 @@
19module Text.Pandoc.Readers.Haddock.Lex (
19module Text.Pandoc.Readers.Haddock.Lex (
20 Token(..),
20 Token(..),
21 LToken,
21 LToken,
22− tokenise
22+ tokenise,
23+ tokenPos
23 ) where
24 ) where
24
25
25import Data.Char
26import Data.Char
@@ -54,14 +55,15 @@ $ident = [$alphanum \'\_\.\!\#\$\%\&\*\+\/\<\=\>\?\@\\\\\^\|\-\~\:]
54<line> {
55<line> {
55 $ws* \> { begin birdtrack }
56 $ws* \> { begin birdtrack }
56 $ws* \>\>\> { strtoken TokExamplePrompt `andBegin` exampleexpr }
57 $ws* \>\>\> { strtoken TokExamplePrompt `andBegin` exampleexpr }
57− $ws* \n { token TokPara `andBegin` para }
58
58
59+ $ws* \n { token TokPara `andBegin` para }
59− -- Here, we really want to be able to say
60+ -- ^ Here, we really want to be able to say
60 -- $ws* (\n | <eof>) { token TokPara `andBegin` para}
61 -- $ws* (\n | <eof>) { token TokPara `andBegin` para}
61 -- because otherwise a trailing line of whitespace will result in
62 -- because otherwise a trailing line of whitespace will result in
62 -- a spurious TokString at the end of a docstring. We don't have <eof>,
63 -- a spurious TokString at the end of a docstring. We don't have <eof>,
63 -- though (NOW I realise what it was for :-). To get around this, we always
64 -- though (NOW I realise what it was for :-). To get around this, we always
64 -- append \n to the end of a docstring.
65 -- append \n to the end of a docstring.
66+
65 () { begin string }
67 () { begin string }
66}
68}
67
69
src/Text/Pandoc/Readers/Haddock/Parse.y+7−7
@@ -46,7 +46,7 @@ import Data.Sequence (viewr, ViewR(..))
46 PARA { (TokPara,_) }
46 PARA { (TokPara,_) }
47 STRING { (TokString $$,_) }
47 STRING { (TokString $$,_) }
48
48
49−%monad { Maybe }
49+%monad { Either [LToken] }
50
50
51%name parseParas doc
51%name parseParas doc
52%name parseString seq
52%name parseString seq
@@ -76,7 +76,7 @@ defpara :: { (Inlines, [Blocks]) }
76
76
77para :: { Blocks }
77para :: { Blocks }
78 : seq { para' $1 }
78 : seq { para' $1 }
79− | codepara { codeBlock $1 }
79+ | codepara { codeBlockWith ([], ["haskell"], []) $1 }
80 | property { $1 }
80 | property { $1 }
81 | examples { $1 }
81 | examples { $1 }
82
82
@@ -118,16 +118,16 @@ elem1 :: { Inlines }
118 | URL { makeHyperlink $1 }
118 | URL { makeHyperlink $1 }
119 | PIC { image $1 $1 mempty }
119 | PIC { image $1 $1 mempty }
120 | ANAME { mempty } -- TODO
120 | ANAME { mempty } -- TODO
121− | IDENT { code $1 }
121+ | IDENT { codeWith ([], ["haskell"], []) $1 }
122− | DQUO strings DQUO { code $2 }
122+ | DQUO strings DQUO { codeWith ([], ["haskell"], []) $2 }
123
123
124strings :: { String }
124strings :: { String }
125 : STRING { $1 }
125 : STRING { $1 }
126 | STRING strings { $1 ++ $2 }
126 | STRING strings { $1 ++ $2 }
127
127
128{
128{
129−happyError :: [LToken] -> Maybe a
129+happyError :: [LToken] -> Either [LToken] a
130−happyError toks = Nothing
130+happyError toks = Left toks
131
131
132para' :: Inlines -> Blocks
132para' :: Inlines -> Blocks
133para' (Many ils) =
133para' (Many ils) =
@@ -162,7 +162,7 @@ makeProperty s = case strip s of
162-- | Create an 'Example', stripping superfluous characters as appropriate
162-- | Create an 'Example', stripping superfluous characters as appropriate
163makeExample :: String -> String -> [String] -> Blocks
163makeExample :: String -> String -> [String] -> Blocks
164makeExample prompt expression result =
164makeExample prompt expression result =
165− para $ codeWith ([], ["expr"], []) (strip expression ++ "\n")
165+ para $ codeWith ([], ["haskell", "expr"], []) (strip expression ++ "\n")
166 <> codeWith ([], ["result"], []) (unlines result')
166 <> codeWith ([], ["result"], []) (unlines result')
167 where
167 where
168 -- 1. drop trailing whitespace from the prompt, remember the prefix
168 -- 1. drop trailing whitespace from the prompt, remember the prefix