git.iko.soy/typeable/pandoc
on master help sign in
Removed old haddock reader code. Add dependency on haddock-library.

This also removes the dependency on alex and happy.

commitab390a10ec3bc42c71d8746152acbf3ee7b1595b authorJohn MacFarlane <jgm@berkeley.edu> dateWed 18 Jun 2014, 11:33 (12 years ago) parentb371e83
5 files changed+25−370
INSTALL+1−5 pandoc.cabal+3−5 src/Text/Pandoc/Readers/Haddock.hs+21−11 src/Text/Pandoc/Readers/Haddock/Lex.x−171 src/Text/Pandoc/Readers/Haddock/Parse.y−178
INSTALL+1−5
@@ -12,11 +12,7 @@ Quick install
1212-------------
1313
14141. Install the [Haskell platform]. This will give you [GHC] and
15− the [cabal-install] build tool, as well as `alex` and `happy`.
16− If you do not use the Haskell platform, you'll need to install
17− `alex` and `happy` separately:
18−
19− cabal install alex happy
15+ the [cabal-install] build tool.
2016
21172. Update your package database:
2218
pandoc.cabal+3−5
@@ -255,8 +255,8 @@ Library
255255 vector >= 0.10 && < 0.11,
256256 hslua >= 0.3 && < 0.4,
257257 binary >= 0.5 && < 0.8,
258− SHA >= 1.6 && < 1.7
259− Build-Tools: alex, happy
258+ SHA >= 1.6 && < 1.7,
259+ haddock-library >= 1.0 && < 1.1
260260 if flag(https)
261261 Build-Depends: http-client >= 0.3.2 && < 0.4,
262262 http-client-tls >= 0.2 && < 0.3,
@@ -322,9 +322,7 @@ Library
322322 Text.Pandoc.XML,
323323 Text.Pandoc.SelfContained,
324324 Text.Pandoc.Process
325− Other-Modules: Text.Pandoc.Readers.Haddock.Lex,
326− Text.Pandoc.Readers.Haddock.Parse,
327− Text.Pandoc.Readers.Docx.Lists,
325+ Other-Modules: Text.Pandoc.Readers.Docx.Lists,
328326 Text.Pandoc.Readers.Docx.Parse,
329327 Text.Pandoc.Writers.Shared,
330328 Text.Pandoc.Asciify,
src/Text/Pandoc/Readers/Haddock.hs+21−11
@@ -3,7 +3,8 @@
33 Copyright : Copyright (C) 2013 David Lazar
44 License : GNU GPL, version 2 or above
55
6− Maintainer : David Lazar <lazar6@illinois.edu>
6+ Maintainer : David Lazar <lazar6@illinois.edu>,
7+ John MacFarlane <jgm@berkeley.edu>
78 Stability : alpha
89
910Conversion of Haddock markup to 'Pandoc' document.
@@ -12,22 +13,31 @@ module Text.Pandoc.Readers.Haddock
1213 ( readHaddock
1314 ) where
1415
15−import Text.Pandoc.Builder
16+import Text.Pandoc.Builder (Blocks, Inlines)
17+import qualified Text.Pandoc.Builder as B
18+import Data.Monoid
19+import Text.Pandoc.Definition
1620import Text.Pandoc.Options
17−import Text.Pandoc.Readers.Haddock.Lex
18−import Text.Pandoc.Readers.Haddock.Parse
21+import Documentation.Haddock.Parser (parseParas, Identifier)
22+import Documentation.Haddock.Types
1923
2024-- | Parse Haddock markup and return a 'Pandoc' document.
2125readHaddock :: ReaderOptions -- ^ Reader options
2226 -> String -- ^ String to parse
2327 -> Pandoc
24−readHaddock _ s = Pandoc nullMeta blocks
25− where
26− blocks = case parseParas (tokenise s (0,0)) of
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 ++ ")"
30− Right x -> mergeLists (toList x)
28+readHaddock _ = B.doc . docHToBlocks . parseParas
29+
30+docHToBlocks :: DocH mod Identifier -> Blocks
31+docHToBlocks d =
32+ case d of
33+ DocAppend d1 d2 -> mappend (docHToBlocks d1) (docHToBlocks d2)
34+ DocParagraph ils -> B.para $ docHToInlines ils
35+
36+docHToInlines :: DocH mod Identifier -> Inlines
37+docHToInlines d =
38+ case d of
39+ DocAppend d1 d2 -> mappend (docHToInlines d1) (docHToInlines d2)
40+ DocString s -> B.text s
3141
3242-- similar to 'docAppend' in Haddock.Doc
3343mergeLists :: [Block] -> [Block]
src/Text/Pandoc/Readers/Haddock/Lex.xdeleted−171
@@ -1,171 +0,0 @@
1−--
2−-- Haddock - A Haskell Documentation Tool
3−--
4−-- (c) Simon Marlow 2002
5−--
6−-- This file was modified and integrated into GHC by David Waern 2006.
7−-- Then moved back into Haddock by Isaac Dupree in 2009 :-)
8−-- Then copied into Pandoc by David Lazar in 2013 :-D
9−
10−{
11−{-# LANGUAGE BangPatterns #-} -- Generated by Alex
12−{-# OPTIONS -Wwarn -w #-}
13−-- The above warning supression flag is a temporary kludge.
14−-- While working on this module you are encouraged to remove it and fix
15−-- any warnings in the module. See
16−-- http://hackage.haskell.org/trac/ghc/wiki/Commentary/CodingStyle#Warnings
17−-- for details
18−
19−module Text.Pandoc.Readers.Haddock.Lex (
20− Token(..),
21− LToken,
22− tokenise,
23− tokenPos
24− ) where
25−
26−import Data.Char
27−import Numeric (readHex)
28−}
29−
30−%wrapper "posn"
31−
32−$ws = $white # \n
33−$digit = [0-9]
34−$hexdigit = [0-9a-fA-F]
35−$special = [\"\@]
36−$alphanum = [A-Za-z0-9]
37−$ident = [$alphanum \'\_\.\!\#\$\%\&\*\+\/\<\=\>\?\@\\\\\^\|\-\~\:]
38−
39−:-
40−
41−-- beginning of a paragraph
42−<0,para> {
43− $ws* \n ;
44− $ws* \> { begin birdtrack }
45− $ws* prop \> .* \n { strtoken TokProperty `andBegin` property}
46− $ws* \>\>\> { strtoken TokExamplePrompt `andBegin` exampleexpr }
47− $ws* [\*\-] { token TokBullet `andBegin` string }
48− $ws* \[ { token TokDefStart `andBegin` def }
49− $ws* \( $digit+ \) { token TokNumber `andBegin` string }
50− $ws* $digit+ \. { token TokNumber `andBegin` string }
51− $ws* { begin string }
52−}
53−
54−-- beginning of a line
55−<line> {
56− $ws* \> { begin birdtrack }
57− $ws* \>\>\> { strtoken TokExamplePrompt `andBegin` exampleexpr }
58−
59− $ws* \n { token TokPara `andBegin` para }
60− -- ^ Here, we really want to be able to say
61− -- $ws* (\n | <eof>) { token TokPara `andBegin` para}
62− -- because otherwise a trailing line of whitespace will result in
63− -- a spurious TokString at the end of a docstring. We don't have <eof>,
64− -- though (NOW I realise what it was for :-). To get around this, we always
65− -- append \n to the end of a docstring.
66−
67− () { begin string }
68−}
69−
70−<birdtrack> .* \n? { strtokenNL TokBirdTrack `andBegin` line }
71−
72−<property> () { token TokPara `andBegin` para }
73−
74−<example> {
75− $ws* \n { token TokPara `andBegin` para }
76− $ws* \>\>\> { strtoken TokExamplePrompt `andBegin` exampleexpr }
77− () { begin exampleresult }
78−}
79−
80−<exampleexpr> .* \n { strtokenNL TokExampleExpression `andBegin` example }
81−
82−<exampleresult> .* \n { strtokenNL TokExampleResult `andBegin` example }
83−
84−<string,def> {
85− $special { strtoken $ \s -> TokSpecial (head s) }
86− \<\< [^\>]* \>\> { strtoken $ \s -> TokPic (init $ init $ tail $ tail s) }
87− \< [^\>]* \> { strtoken $ \s -> TokURL (init (tail s)) }
88− \# [^\#]* \# { strtoken $ \s -> TokAName (init (tail s)) }
89− \/ [^\/]* \/ { strtoken $ \s -> TokEmphasis (init (tail s)) }
90− [\'\`] $ident+ [\'\`] { strtoken $ \s -> TokIdent (init (tail s)) }
91− \\ . { strtoken (TokString . tail) }
92− "&#" $digit+ \; { strtoken $ \s -> TokString [chr (read (init (drop 2 s)))] }
93− "&#" [xX] $hexdigit+ \;
94− { strtoken $ \s -> case readHex (init (drop 3 s)) of [(n,_)] -> TokString [chr n] }
95− -- allow special characters through if they don't fit one of the previous
96− -- patterns.
97− [\/\'\`\<\#\&\\] { strtoken TokString }
98− [^ $special \/ \< \# \n \'\` \& \\ \]]* \n { strtokenNL TokString `andBegin` line }
99− [^ $special \/ \< \# \n \'\` \& \\ \]]+ { strtoken TokString }
100−}
101−
102−<def> {
103− \] { token TokDefEnd `andBegin` string }
104−}
105−
106−-- ']' doesn't have any special meaning outside of the [...] at the beginning
107−-- of a definition paragraph.
108−<string> {
109− \] { strtoken TokString }
110−}
111−
112−{
113−-- | A located token
114−type LToken = (Token, AlexPosn)
115−
116−data Token
117− = TokPara
118− | TokNumber
119− | TokBullet
120− | TokDefStart
121− | TokDefEnd
122− | TokSpecial Char
123− | TokIdent String
124− | TokString String
125− | TokURL String
126− | TokPic String
127− | TokEmphasis String
128− | TokAName String
129− | TokBirdTrack String
130− | TokProperty String
131− | TokExamplePrompt String
132− | TokExampleExpression String
133− | TokExampleResult String
134− deriving Show
135−
136−tokenPos :: LToken -> (Int, Int)
137−tokenPos t = let AlexPn _ line col = snd t in (line, col)
138−
139−type StartCode = Int
140−type Action = AlexPosn -> String -> StartCode -> (StartCode -> [LToken]) -> [LToken]
141−
142−tokenise :: String -> (Int, Int) -> [LToken]
143−tokenise str (line, col) = go (posn,'\n',[],eofHack str) para
144− where posn = AlexPn 0 line col
145− go inp@(pos,_,_,str) sc =
146− case alexScan inp sc of
147− AlexEOF -> []
148− AlexError _ -> []
149− AlexSkip inp' len -> go inp' sc
150− AlexToken inp' len act -> act pos (take len str) sc (\sc -> go inp' sc)
151−
152−-- NB. we add a final \n to the string, (see comment in the beginning of line
153−-- production above).
154−eofHack str = str++"\n"
155−
156−andBegin :: Action -> StartCode -> Action
157−andBegin act new_sc = \pos str _ cont -> act pos str new_sc cont
158−
159−token :: Token -> Action
160−token t = \pos _ sc cont -> (t, pos) : cont sc
161−
162−strtoken, strtokenNL :: (String -> Token) -> Action
163−strtoken t = \pos str sc cont -> (t str, pos) : cont sc
164−strtokenNL t = \pos str sc cont -> (t (filter (/= '\r') str), pos) : cont sc
165−-- ^ We only want LF line endings in our internal doc string format, so we
166−-- filter out all CRs.
167−
168−begin :: StartCode -> Action
169−begin sc = \_ _ _ cont -> cont sc
170−
171−}
src/Text/Pandoc/Readers/Haddock/Parse.ydeleted−178
@@ -1,178 +0,0 @@
1−-- This code was copied from the 'haddock' package, modified, and integrated
2−-- into Pandoc by David Lazar.
3−{
4−{-# LANGUAGE BangPatterns #-} -- required for versions of Happy before 1.18.6
5−-- The above warning supression flag is a temporary kludge.
6−-- While working on this module you are encouraged to remove it and fix
7−-- any warnings in the module. See
8−-- http://hackage.haskell.org/trac/ghc/wiki/Commentary/CodingStyle#Warnings
9−-- for details
10−
11−module Text.Pandoc.Readers.Haddock.Parse (parseString, parseParas) where
12−
13−import Text.Pandoc.Readers.Haddock.Lex
14−import Text.Pandoc.Builder
15−import Text.Pandoc.Shared (trim, trimr)
16−import Data.Generics (everywhere, mkT)
17−import Data.Char (isSpace)
18−import Data.Maybe (fromMaybe)
19−import Data.List (stripPrefix, intersperse)
20−import Data.Monoid (mempty, mconcat)
21−}
22−
23−%expect 0
24−
25−%tokentype { LToken }
26−
27−%token
28− '/' { (TokSpecial '/',_) }
29− '@' { (TokSpecial '@',_) }
30− '[' { (TokDefStart,_) }
31− ']' { (TokDefEnd,_) }
32− DQUO { (TokSpecial '\"',_) }
33− URL { (TokURL $$,_) }
34− PIC { (TokPic $$,_) }
35− ANAME { (TokAName $$,_) }
36− '/../' { (TokEmphasis $$,_) }
37− '-' { (TokBullet,_) }
38− '(n)' { (TokNumber,_) }
39− '>..' { (TokBirdTrack $$,_) }
40− PROP { (TokProperty $$,_) }
41− PROMPT { (TokExamplePrompt $$,_) }
42− RESULT { (TokExampleResult $$,_) }
43− EXP { (TokExampleExpression $$,_) }
44− IDENT { (TokIdent $$,_) }
45− PARA { (TokPara,_) }
46− STRING { (TokString $$,_) }
47−
48−%monad { Either [LToken] }
49−
50−%name parseParas doc
51−%name parseString seq
52−
53−%%
54−
55−doc :: { Blocks }
56− : apara PARA doc { $1 <> $3 }
57− | PARA doc { $2 }
58− | apara { $1 }
59− | {- empty -} { mempty }
60−
61−apara :: { Blocks }
62− : ulpara { bulletList [$1] }
63− | olpara { orderedList [$1] }
64− | defpara { definitionList [$1] }
65− | para { $1 }
66−
67−ulpara :: { Blocks }
68− : '-' para { $2 }
69−
70−olpara :: { Blocks }
71− : '(n)' para { $2 }
72−
73−defpara :: { (Inlines, [Blocks]) }
74− : '[' seq ']' seq { (trimInlines $2, [plain $ trimInlines $4]) }
75−
76−para :: { Blocks }
77− : seq { para' $1 }
78− | codepara { codeBlockWith ([], ["haskell"], []) $1 }
79− | property { $1 }
80− | examples { $1 }
81−
82−codepara :: { String }
83− : '>..' codepara { $1 ++ $2 }
84− | '>..' { $1 }
85−
86−property :: { Blocks }
87− : PROP { makeProperty $1 }
88−
89−examples :: { Blocks }
90− : example examples { $1 <> $2 }
91− | example { $1 }
92−
93−example :: { Blocks }
94− : PROMPT EXP result { makeExample $1 $2 (lines $3) }
95− | PROMPT EXP { makeExample $1 $2 [] }
96−
97−result :: { String }
98− : RESULT result { $1 ++ $2 }
99− | RESULT { $1 }
100−
101−seq :: { Inlines }
102− : elem seq { $1 <> $2 }
103− | elem { $1 }
104−
105−elem :: { Inlines }
106− : elem1 { $1 }
107− | '@' seq1 '@' { monospace $2 }
108−
109−seq1 :: { Inlines }
110− : PARA seq1 { linebreak <> $2 }
111− | elem1 seq1 { $1 <> $2 }
112− | elem1 { $1 }
113−
114−elem1 :: { Inlines }
115− : STRING { text $1 }
116− | '/../' { emph (str $1) }
117− | URL { makeHyperlink $1 }
118− | PIC { image $1 $1 mempty }
119− | ANAME { mempty } -- TODO
120− | IDENT { codeWith ([], ["haskell"], []) $1 }
121− | DQUO strings DQUO { codeWith ([], ["haskell"], []) $2 }
122−
123−strings :: { String }
124− : STRING { $1 }
125− | STRING strings { $1 ++ $2 }
126−
127−{
128−happyError :: [LToken] -> Either [LToken] a
129−happyError toks = Left toks
130−
131−para' :: Inlines -> Blocks
132−para' = para . trimInlines
133−
134−monospace :: Inlines -> Inlines
135−monospace = everywhere (mkT go)
136− where
137− go (Str s) = Code nullAttr s
138− go x = x
139−
140−-- | Create a `Hyperlink` from given string.
141−--
142−-- A hyperlink consists of a URL and an optional label. The label is separated
143−-- from the url by one or more whitespace characters.
144−makeHyperlink :: String -> Inlines
145−makeHyperlink input = case break isSpace $ trim input of
146− (url, "") -> link url url (str url)
147− (url, lb) -> link url url (trimInlines $ text lb)
148−
149−makeProperty :: String -> Blocks
150−makeProperty s = case trim s of
151− 'p':'r':'o':'p':'>':xs ->
152− codeBlockWith ([], ["property"], []) (dropWhile isSpace xs)
153− xs ->
154− error $ "makeProperty: invalid input " ++ show xs
155−
156−-- | Create an 'Example', stripping superfluous characters as appropriate
157−makeExample :: String -> String -> [String] -> Blocks
158−makeExample prompt expression result =
159− para $ codeWith ([], ["haskell","expr"], []) (trim expression)
160− <> linebreak
161− <> (mconcat $ intersperse linebreak $ map coder result')
162− where
163− -- 1. drop trailing whitespace from the prompt, remember the prefix
164− prefix = takeWhile isSpace prompt
165−
166− -- 2. drop, if possible, the exact same sequence of whitespace
167− -- characters from each result line
168− --
169− -- 3. interpret lines that only contain the string "<BLANKLINE>" as an
170− -- empty line
171− result' = map (substituteBlankLine . tryStripPrefix prefix) result
172− where
173− tryStripPrefix xs ys = fromMaybe ys $ stripPrefix xs ys
174−
175− substituteBlankLine "<BLANKLINE>" = ""
176− substituteBlankLine line = line
177− coder = codeWith ([], ["result"], [])
178−}