git.iko.soy/typeable/pandoc
on master help sign in
Have warningWithPos take a SourcePos rather than Maybe SourcePos.

After all, we have warning if you don't want the source pos info.

commite1d2da4c227a15427b82697d573d44bbd08ef906 authorJohn MacFarlane <jgm@berkeley.edu> dateMon 5 Dec 2016, 11:30 (10 years ago) parentf1cec1d
4 files changed+30−20
src/Text/Pandoc/Class.hs+22−12 src/Text/Pandoc/Readers/LaTeX.hs+1−1 src/Text/Pandoc/Readers/Markdown.hs+5−5 src/Text/Pandoc/Readers/RST.hs+2−2
src/Text/Pandoc/Class.hs+22−12
@@ -72,7 +72,7 @@ import qualified Text.Pandoc.Shared as IO ( fetchItem
7272 , readDataFile
7373 , warn)
7474import Text.Pandoc.Compat.Time (UTCTime)
75−import Text.Pandoc.Parsing (ParserT, ParserState, SourcePos)
75+import Text.Pandoc.Parsing (ParserT, SourcePos)
7676import qualified Text.Pandoc.Compat.Time as IO (getCurrentTime)
7777import Data.Time.Clock.POSIX ( utcTimeToPOSIXSeconds
7878 , posixSecondsToUTCTime
@@ -121,7 +121,7 @@ class (Functor m, Applicative m, Monad m, MonadError PandocError m, MonadState C
121121 glob :: String -> m [FilePath]
122122 getModificationTime :: FilePath -> m UTCTime
123123
124−
124+
125125
126126-- Functions defined for all PandocMonad instances
127127
@@ -157,11 +157,10 @@ getZonedTime = do
157157 return $ utcToZonedTime tz t
158158
159159warningWithPos :: PandocMonad m
160− => Maybe SourcePos
160+ => SourcePos
161161 -> String
162− -> ParserT [Char] ParserState m ()
163−warningWithPos mbpos msg =
164− lift $ warning $ msg ++ maybe "" (\pos -> " " ++ show pos) mbpos
162+ -> ParserT s st m ()
163+warningWithPos pos msg = lift $ warning $ msg ++ " " ++ show pos
165164
166165--
167166
@@ -377,9 +376,20 @@ instance PandocMonad PandocPure where
377376 Just tm -> return tm
378377 Nothing -> throwError $ PandocFileReadError fp
379378
380−
381−
382−
383−
384−
385−
379+{-
380+instance PandocMonad m => PandocMonad (ParserT s st m) where
381+ lookupEnv = lift . lookupEnv
382+ getCurrentTime = lift . getCurrentTime
383+ getCurrentTimeZone = lift . getCurrentTimeZone
384+ getDefaultReferenceDocx = lift . getDefaultReferenceDocx
385+ getDefaultReferenceODT = lift . getDefaultReferenceODT
386+ newStdGen = lift . newStdGen
387+ newUniqueHash = lift . newUniqueHash
388+ readFileLazy = lift . readFileLazy
389+ readDataFile mbuserdir = lift . readDataFile mbuserdir
390+ fail = lift . fail
391+ fetchItem media = lift . fetchItem media
392+ fetchItem' media sourceUrl = lift . fetchItem' media sourceUrl
393+ glob = lift . glob
394+ getModificationTime = lift . getModificationTime
395+-}
src/Text/Pandoc/Readers/LaTeX.hs+1−1
@@ -238,7 +238,7 @@ inline = (mempty <$ comment)
238238 <|> (str . (:[]) <$> tildeEscape)
239239 <|> (do res <- oneOf "#&~^'`\"[]"
240240 pos <- getPosition
241− warningWithPos (Just pos) ("Parsing unescaped '" ++ [res] ++ "'")
241+ warningWithPos pos ("Parsing unescaped '" ++ [res] ++ "'")
242242 return $ str [res])
243243
244244inlines :: PandocMonad m => LP m Inlines
src/Text/Pandoc/Readers/Markdown.hs+5−5
@@ -280,7 +280,7 @@ yamlMetaBlock = try $ do
280280 ) nullMeta hashmap
281281 Right Yaml.Null -> return nullMeta
282282 Right _ -> do
283− P.warningWithPos (Just pos) "YAML header is not an object"
283+ P.warningWithPos pos "YAML header is not an object"
284284 return nullMeta
285285 Left err' -> do
286286 case err' of
@@ -291,13 +291,13 @@ yamlMetaBlock = try $ do
291291 yamlLine = yline
292292 , yamlColumn = ycol
293293 }}) ->
294− P.warningWithPos (Just $ setSourceLine
294+ P.warningWithPos (setSourceLine
295295 (setSourceColumn pos
296296 (sourceColumn pos + ycol))
297297 (sourceLine pos + 1 + yline))
298298 $ "Could not parse YAML header: " ++
299299 problem
300− _ -> P.warningWithPos (Just pos)
300+ _ -> P.warningWithPos pos
301301 $ "Could not parse YAML header: " ++
302302 show err'
303303 return nullMeta
@@ -420,7 +420,7 @@ referenceKey = try $ do
420420 let oldkeys = stateKeys st
421421 let key = toKey raw
422422 case M.lookup key oldkeys of
423− Just _ -> P.warningWithPos (Just pos) $ "Duplicate link reference `" ++ raw ++ "'"
423+ Just _ -> P.warningWithPos pos $ "Duplicate link reference `" ++ raw ++ "'"
424424 Nothing -> return ()
425425 updateState $ \s -> s { stateKeys = M.insert key (target, attr') oldkeys }
426426 return $ return mempty
@@ -486,7 +486,7 @@ noteBlock = try $ do
486486 let newnote = (ref, parsed)
487487 oldnotes <- stateNotes' <$> getState
488488 case lookup ref oldnotes of
489− Just _ -> P.warningWithPos (Just pos) $ "Duplicate note reference `" ++ ref ++ "'"
489+ Just _ -> P.warningWithPos pos $ "Duplicate note reference `" ++ ref ++ "'"
490490 Nothing -> return ()
491491 updateState $ \s -> s { stateNotes' = newnote : oldnotes }
492492 return mempty
src/Text/Pandoc/Readers/RST.hs+2−2
@@ -696,7 +696,7 @@ directive' = do
696696 return $ B.divWith attrs children
697697 other -> do
698698 pos <- getPosition
699− P.warningWithPos (Just pos) $ "ignoring unknown directive: " ++ other
699+ P.warningWithPos pos $ "ignoring unknown directive: " ++ other
700700 return mempty
701701
702702-- TODO:
@@ -1135,7 +1135,7 @@ renderRole contents fmt role attr = case role of
11351135 renderRole contents newFmt newRole newAttr
11361136 Nothing -> do
11371137 pos <- getPosition
1138− P.warningWithPos (Just pos) $ "ignoring unknown role :" ++ custom ++ ": in"
1138+ P.warningWithPos pos $ "ignoring unknown role :" ++ custom ++ ": in"
11391139 return $ B.str contents -- Undefined role
11401140 where
11411141 titleRef ref = return $ B.str ref -- FIXME: Not a sensible behaviour