git.iko.soy/typeable/pandoc
on master help sign in
Use Parsec directly in Biblio and Templates.
commitf79ed27bb50411bf0704f34b555c5c348e4c7ec8 authorJohn MacFarlane <fiddlosopher@gmail.com> dateFri 20 Jul 2012, 16:33 (14 years ago) parent2c30c48
2 files changed+16−16
src/Text/Pandoc/Biblio.hs+6−6 src/Text/Pandoc/Templates.hs+10−10
src/Text/Pandoc/Biblio.hs+6−6
@@ -38,7 +38,7 @@ import qualified Text.CSL as CSL ( Cite(..) )
3838import Text.Pandoc.Definition
3939import Text.Pandoc.Generic
4040import Text.Pandoc.Shared (stringify)
41−import Text.Pandoc.Parsing
41+import Text.Parsec
4242import Control.Monad
4343
4444-- | Process a 'Pandoc' document by adding citations formatted
@@ -165,7 +165,7 @@ locatorWords inp =
165165 breakup (x : xs) = x : breakup xs
166166 splitup = groupBy (\x y -> x /= '\160' && y /= '\160')
167167
168−pLocatorWords :: Parser [Inline] st (String, [Inline])
168+pLocatorWords :: Parsec [Inline] st (String, [Inline])
169169pLocatorWords = do
170170 l <- pLocator
171171 s <- getInput -- rest is suffix
@@ -173,16 +173,16 @@ pLocatorWords = do
173173 then return (init l, Str "," : s)
174174 else return (l, s)
175175
176−pMatch :: (Inline -> Bool) -> Parser [Inline] st Inline
176+pMatch :: (Inline -> Bool) -> Parsec [Inline] st Inline
177177pMatch condition = try $ do
178178 t <- anyToken
179179 guard $ condition t
180180 return t
181181
182−pSpace :: Parser [Inline] st Inline
182+pSpace :: Parsec [Inline] st Inline
183183pSpace = pMatch (\t -> t == Space || t == Str "\160")
184184
185−pLocator :: Parser [Inline] st String
185+pLocator :: Parsec [Inline] st String
186186pLocator = try $ do
187187 optional $ pMatch (== Str ",")
188188 optional pSpace
@@ -190,7 +190,7 @@ pLocator = try $ do
190190 gs <- many1 pWordWithDigits
191191 return $ stringify f ++ (' ' : unwords gs)
192192
193−pWordWithDigits :: Parser [Inline] st String
193+pWordWithDigits :: Parsec [Inline] st String
194194pWordWithDigits = try $ do
195195 pSpace
196196 r <- many1 (notFollowedBy pSpace >> anyToken)
src/Text/Pandoc/Templates.hs+10−10
@@ -68,7 +68,7 @@ module Text.Pandoc.Templates ( renderTemplate
6868 , TemplateTarget
6969 , getDefaultTemplate ) where
7070
71−import Text.Pandoc.Parsing
71+import Text.Parsec
7272import Control.Monad (liftM, when, forM, mzero)
7373import System.FilePath
7474import Data.List (intercalate, intersperse)
@@ -98,7 +98,7 @@ getDefaultTemplate user writer = do
9898
9999data TemplateState = TemplateState Int [(String,String)]
100100
101−adjustPosition :: String -> Parser [Char] TemplateState String
101+adjustPosition :: String -> Parsec [Char] TemplateState String
102102adjustPosition str = do
103103 let lastline = takeWhile (/= '\n') $ reverse str
104104 updateState $ \(TemplateState pos x) ->
@@ -132,21 +132,21 @@ renderTemplate vals templ =
132132reservedWords :: [String]
133133reservedWords = ["else","endif","for","endfor","sep"]
134134
135−parseTemplate :: Parser [Char] TemplateState [String]
135+parseTemplate :: Parsec [Char] TemplateState [String]
136136parseTemplate =
137137 many $ (plaintext <|> escapedDollar <|> conditional <|> for <|> variable)
138138 >>= adjustPosition
139139
140−plaintext :: Parser [Char] TemplateState String
140+plaintext :: Parsec [Char] TemplateState String
141141plaintext = many1 $ noneOf "$"
142142
143−escapedDollar :: Parser [Char] TemplateState String
143+escapedDollar :: Parsec [Char] TemplateState String
144144escapedDollar = try $ string "$$" >> return "$"
145145
146−skipEndline :: Parser [Char] st ()
146+skipEndline :: Parsec [Char] st ()
147147skipEndline = try $ skipMany (oneOf " \t") >> newline >> return ()
148148
149−conditional :: Parser [Char] TemplateState String
149+conditional :: Parsec [Char] TemplateState String
150150conditional = try $ do
151151 TemplateState pos vars <- getState
152152 string "$if("
@@ -170,7 +170,7 @@ conditional = try $ do
170170 then ifContents
171171 else elseContents
172172
173−for :: Parser [Char] TemplateState String
173+for :: Parsec [Char] TemplateState String
174174for = try $ do
175175 TemplateState pos vars <- getState
176176 string "$for("
@@ -193,7 +193,7 @@ for = try $ do
193193 setState $ TemplateState pos vars
194194 return $ concat $ intersperse sep contents
195195
196−ident :: Parser [Char] TemplateState String
196+ident :: Parsec [Char] TemplateState String
197197ident = do
198198 first <- letter
199199 rest <- many (alphaNum <|> oneOf "_-")
@@ -202,7 +202,7 @@ ident = do
202202 then mzero
203203 else return id'
204204
205−variable :: Parser [Char] TemplateState String
205+variable :: Parsec [Char] TemplateState String
206206variable = try $ do
207207 char '$'
208208 id' <- ident