@@ -1,5 +1,8 @@
1−{-# LANGUAGE GeneralizedNewtypeDeriving, TypeSynonymInstances,
3+, GeneralizedNewtypeDeriving
2− FlexibleInstances#-}
5+, FlexibleInstances #-}
4Copyright (C) 2006-2014 John MacFarlane <jgm@berkeley.edu>
7Copyright (C) 2006-2014 John MacFarlane <jgm@berkeley.edu>
@@ -177,12 +180,15 @@ import Text.Pandoc.Asciify (toAsciiChar)
177import Data.Default
180import Data.Default
178import qualified Data.Set as Set
181import qualified Data.Set as Set
179import Control.Monad.Reader
182import Control.Monad.Reader
183+import Control.Monad.Identity
180−import Control.Applicative ((*>), (<*), (<$), liftA2, Applicative)
184+import Control.Applicative ((<$>), (<*>), (*>), (<*), (<$), Applicative)
181import Data.Monoid
185import Data.Monoid
182import Data.Maybe (catMaybes)
186import Data.Maybe (catMaybes)
184type Parser t s = Parsec t s
188type Parser t s = Parsec t s
190+type ParserT = ParsecT
186newtype F a = F { unF :: Reader ParserState a } deriving (Monad, Applicative, Functor)
192newtype F a = F { unF :: Reader ParserState a } deriving (Monad, Applicative, Functor)
188runF :: F a -> ParserState -> a
194runF :: F a -> ParserState -> a
@@ -201,11 +207,11 @@ instance Monoid a => Monoid (F a) where
202-- | Like >>, but returns the operation on the left.
208-- | Like >>, but returns the operation on the left.
203-- (Suggested by Tillmann Rendel on Haskell-cafe list.)
209-- (Suggested by Tillmann Rendel on Haskell-cafe list.)
204−(>>~) :: (Monad m) => m a -> m b -> m a
210+(>>~) :: (Applicative m) => m a -> m b -> m a
205−a >>~ b = a >>= \x -> b >> return x
211+a >>~ b = a <* b
207-- | Parse any line of text
213-- | Parse any line of text
208−anyLine :: Parser [Char] st [Char]
214+anyLine :: Stream [Char] m Char => ParserT [Char] st m [Char]
209anyLine = do
215anyLine = do
210 -- This is much faster than:
216 -- This is much faster than:
211 -- manyTill anyChar newline
217 -- manyTill anyChar newline
@@ -221,9 +227,10 @@ anyLine = do
221 _ -> mzero
227 _ -> mzero
223-- | Like @manyTill@, but reads at least one item.
229-- | Like @manyTill@, but reads at least one item.
224−many1Till :: Parser [tok] st a
230+many1Till :: Stream s m t
225− -> Parser [tok] st end
231+ => ParserT s st m a
226− -> Parser [tok] st [a]
232+ -> ParserT s st m end
233+ -> ParserT s st m [a]
227many1Till p end = do
234many1Till p end = do
228 first <- p
235 first <- p
229 rest <- manyTill p end
236 rest <- manyTill p end
@@ -232,14 +239,14 @@ many1Till p end = do
232-- | A more general form of @notFollowedBy@. This one allows any
239-- | A more general form of @notFollowedBy@. This one allows any
233-- type of parser to be specified, and succeeds only if that parser fails.
240-- type of parser to be specified, and succeeds only if that parser fails.
234-- It does not consume any input.
241-- It does not consume any input.
235−notFollowedBy' :: Show b => Parser [a] st b -> Parser [a] st ()
242+notFollowedBy' :: (Show b, Stream s m a) => ParserT s st m b -> ParserT s st m ()
236notFollowedBy' p = try $ join $ do a <- try p
243notFollowedBy' p = try $ join $ do a <- try p
237 return (unexpected (show a))
244 return (unexpected (show a))
239 return (return ())
246 return (return ())
240-- (This version due to Andrew Pimlott on the Haskell mailing list.)
247-- (This version due to Andrew Pimlott on the Haskell mailing list.)
242−oneOfStrings' :: (Char -> Char -> Bool) -> [String] -> Parser [Char] st String
249+oneOfStrings' :: Stream s m Char => (Char -> Char -> Bool) -> [String] -> ParserT s st m String
243oneOfStrings' _ [] = fail "no strings"
250oneOfStrings' _ [] = fail "no strings"
244oneOfStrings' matches strs = try $ do
251oneOfStrings' matches strs = try $ do
245 c <- anyChar
252 c <- anyChar
@@ -254,11 +261,11 @@ oneOfStrings' matches strs = try $ do
254-- | Parses one of a list of strings. If the list contains
261-- | Parses one of a list of strings. If the list contains
255-- two strings one of which is a prefix of the other, the longer
262-- two strings one of which is a prefix of the other, the longer
256-- string will be matched if possible.
263-- string will be matched if possible.
257−oneOfStrings :: [String] -> Parser [Char] st String
264+oneOfStrings :: Stream s m Char => [String] -> ParserT s st m String
258oneOfStrings = oneOfStrings' (==)
265oneOfStrings = oneOfStrings' (==)
260-- | Parses one of a list of strings (tried in order), case insensitive.
267-- | Parses one of a list of strings (tried in order), case insensitive.
261−oneOfStringsCI :: [String] -> Parser [Char] st String
268+oneOfStringsCI :: Stream s m Char => [String] -> ParserT s st m String
262oneOfStringsCI = oneOfStrings' ciMatch
269oneOfStringsCI = oneOfStrings' ciMatch
263 where ciMatch x y = toLower' x == toLower' y
270 where ciMatch x y = toLower' x == toLower' y
264 -- this optimizes toLower by checking common ASCII case
271 -- this optimizes toLower by checking common ASCII case
@@ -269,35 +276,35 @@ oneOfStringsCI = oneOfStrings' ciMatch
269 | otherwise = toLower c
276 | otherwise = toLower c
271-- | Parses a space or tab.
278-- | Parses a space or tab.
272−spaceChar :: Parser [Char] st Char
279+spaceChar :: Stream s m Char => ParserT s st m Char
273spaceChar = satisfy $ \c -> c == ' ' || c == '\t'
280spaceChar = satisfy $ \c -> c == ' ' || c == '\t'
275-- | Parses a nonspace, nonnewline character.
282-- | Parses a nonspace, nonnewline character.
276−nonspaceChar :: Parser [Char] st Char
283+nonspaceChar :: Stream s m Char => ParserT s st m Char
277nonspaceChar = satisfy $ flip notElem ['\t', '\n', ' ', '\r']
284nonspaceChar = satisfy $ flip notElem ['\t', '\n', ' ', '\r']
279-- | Skips zero or more spaces or tabs.
286-- | Skips zero or more spaces or tabs.
280−skipSpaces :: Parser [Char] st ()
287+skipSpaces :: Stream s m Char => ParserT s st m ()
281skipSpaces = skipMany spaceChar
288skipSpaces = skipMany spaceChar
283-- | Skips zero or more spaces or tabs, then reads a newline.
290-- | Skips zero or more spaces or tabs, then reads a newline.
284−blankline :: Parser [Char] st Char
291+blankline :: Stream s m Char => ParserT s st m Char
285blankline = try $ skipSpaces >> newline
292blankline = try $ skipSpaces >> newline
287-- | Parses one or more blank lines and returns a string of newlines.
294-- | Parses one or more blank lines and returns a string of newlines.
288−blanklines :: Parser [Char] st [Char]
295+blanklines :: Stream s m Char => ParserT s st m [Char]
289blanklines = many1 blankline
296blanklines = many1 blankline
291-- | Parses material enclosed between start and end parsers.
298-- | Parses material enclosed between start and end parsers.
292−enclosed :: Parser [Char] st t -- ^ start parser
299+enclosed :: Stream s m Char => ParserT s st m t -- ^ start parser
293− -> Parser [Char] st end -- ^ end parser
300+ -> ParserT s st m end -- ^ end parser
294− -> Parser [Char] st a -- ^ content parser (to be used repeatedly)
301+ -> ParserT s st m a -- ^ content parser (to be used repeatedly)
295− -> Parser [Char] st [a]
302+ -> ParserT s st m [a]
296enclosed start end parser = try $
303enclosed start end parser = try $
297 start >> notFollowedBy space >> many1Till parser end
304 start >> notFollowedBy space >> many1Till parser end
299-- | Parse string, case insensitive.
306-- | Parse string, case insensitive.
300−stringAnyCase :: [Char] -> Parser [Char] st String
307+stringAnyCase :: Stream s m Char => [Char] -> ParserT s st m String
301stringAnyCase [] = string ""
308stringAnyCase [] = string ""
302stringAnyCase (x:xs) = do
309stringAnyCase (x:xs) = do
303 firstChar <- char (toUpper x) <|> char (toLower x)
310 firstChar <- char (toUpper x) <|> char (toLower x)
@@ -305,7 +312,7 @@ stringAnyCase (x:xs) = do
305 return (firstChar:rest)
312 return (firstChar:rest)
307-- | Parse contents of 'str' using 'parser' and return result.
314-- | Parse contents of 'str' using 'parser' and return result.
308−parseFromString :: Parser [tok] st a -> [tok] -> Parser [tok] st a
315+parseFromString :: Stream s m t => ParserT s st m a -> s -> ParserT s st m a
309parseFromString parser str = do
316parseFromString parser str = do
310 oldPos <- getPosition
317 oldPos <- getPosition
311 oldInput <- getInput
318 oldInput <- getInput
@@ -316,7 +323,7 @@ parseFromString parser str = do
316 return result
323 return result
318-- | Parse raw line block up to and including blank lines.
325-- | Parse raw line block up to and including blank lines.
319−lineClump :: Parser [Char] st String
326+lineClump :: Stream [Char] m Char => ParserT [Char] st m String
320lineClump = blanklines
327lineClump = blanklines
321 <|> (many1 (notFollowedBy blankline >> anyLine) >>= return . unlines)
328 <|> (many1 (notFollowedBy blankline >> anyLine) >>= return . unlines)
@@ -325,8 +332,8 @@ lineClump = blanklines
325-- pairs of open and close, which must be different. For example,
332-- pairs of open and close, which must be different. For example,
326-- @charsInBalanced '(' ')' anyChar@ will parse "(hello (there))"
333-- @charsInBalanced '(' ')' anyChar@ will parse "(hello (there))"
327-- and return "hello (there)".
334-- and return "hello (there)".
328−charsInBalanced :: Char -> Char -> Parser [Char] st Char
335+charsInBalanced :: Stream s m Char => Char -> Char -> ParserT s st m Char
329− -> Parser [Char] st String
336+ -> ParserT s st m String
330charsInBalanced open close parser = try $ do
337charsInBalanced open close parser = try $ do
331 char open
338 char open
332 let isDelim c = c == open || c == close
339 let isDelim c = c == open || c == close
@@ -350,8 +357,8 @@ uppercaseRomanDigits :: [Char]
350uppercaseRomanDigits = map toUpper lowercaseRomanDigits
357uppercaseRomanDigits = map toUpper lowercaseRomanDigits
352-- | Parses a roman numeral (uppercase or lowercase), returns number.
359-- | Parses a roman numeral (uppercase or lowercase), returns number.
353−romanNumeral :: Bool -- ^ Uppercase if true
360+romanNumeral :: Stream s m Char => Bool -- ^ Uppercase if true
354− -> Parser [Char] st Int
361+ -> ParserT s st m Int
355romanNumeral upperCase = do
362romanNumeral upperCase = do
356 let romanDigits = if upperCase
363 let romanDigits = if upperCase
357 then uppercaseRomanDigits
364 then uppercaseRomanDigits
@@ -383,8 +390,8 @@ romanNumeral upperCase = do
384-- | Parses an email address; returns original and corresponding
391-- | Parses an email address; returns original and corresponding
385-- escaped mailto: URI.
392-- escaped mailto: URI.
386−emailAddress :: Parser [Char] st (String, String)
393+emailAddress :: Stream s m Char => ParserT s st m (String, String)
387−emailAddress = try $ liftA2 toResult mailbox (char '@' *> domain)
394+emailAddress = try $ toResult <$> mailbox <*> (char '@' *> domain)
388 where toResult mbox dom = let full = fromEntities $ mbox ++ '@':dom
395 where toResult mbox dom = let full = fromEntities $ mbox ++ '@':dom
389 in (full, escapeURI $ "mailto:" ++ full)
396 in (full, escapeURI $ "mailto:" ++ full)
390 mailbox = intercalate "." `fmap` (emailWord `sepby1` dot)
397 mailbox = intercalate "." `fmap` (emailWord `sepby1` dot)
@@ -398,7 +405,7 @@ emailAddress = try $ liftA2 toResult mailbox (char '@' *> domain)
398 isEmailPunct c = c `elem` "!\"#$%&'*+-/=?^_{|}~;"
405 isEmailPunct c = c `elem` "!\"#$%&'*+-/=?^_{|}~;"
399 -- note: sepBy1 from parsec consumes input when sep
406 -- note: sepBy1 from parsec consumes input when sep
400 -- succeeds and p fails, so we use this variant here.
407 -- succeeds and p fails, so we use this variant here.
401− sepby1 p sep = liftA2 (:) p (many (try $ sep >> p))
408+ sepby1 p sep = (:) <$> p <*> (many (try $ sep >> p))
404-- Schemes from http://www.iana.org/assignments/uri-schemes.html plus
411-- Schemes from http://www.iana.org/assignments/uri-schemes.html plus
@@ -426,11 +433,11 @@ schemes = ["coap","doi","javascript","aaa","aaas","about","acap","cap","cid",
426 "ventrilo","view-source","webcal","wtai","wyciwyg","xfire","xri",
433 "ventrilo","view-source","webcal","wtai","wyciwyg","xfire","xri",
429−uriScheme :: Parser [Char] st String
436+uriScheme :: Stream s m Char => ParserT s st m String
430uriScheme = oneOfStringsCI schemes
437uriScheme = oneOfStringsCI schemes
432-- | Parses a URI. Returns pair of original and URI-escaped version.
439-- | Parses a URI. Returns pair of original and URI-escaped version.
433−uri :: Parser [Char] st (String, String)
440+uri :: Stream [Char] m Char => ParserT [Char] st m (String, String)
434uri = try $ do
441uri = try $ do
435 scheme <- uriScheme
442 scheme <- uriScheme
@@ -460,7 +467,7 @@ uri = try $ do
460 let uri' = scheme ++ ":" ++ fromEntities str'
467 let uri' = scheme ++ ":" ++ fromEntities str'
461 return (uri', escapeURI uri')
468 return (uri', escapeURI uri')
463−mathInlineWith :: String -> String -> Parser [Char] st String
470+mathInlineWith :: Stream s m Char => String -> String -> ParserT s st m String
464mathInlineWith op cl = try $ do
471mathInlineWith op cl = try $ do
465 string op
472 string op
466 notFollowedBy space
473 notFollowedBy space
@@ -474,12 +481,12 @@ mathInlineWith op cl = try $ do
474 notFollowedBy digit -- to prevent capture of $5
481 notFollowedBy digit -- to prevent capture of $5
475 return $ concat words'
482 return $ concat words'
477−mathDisplayWith :: String -> String -> Parser [Char] st String
484+mathDisplayWith :: Stream s m Char => String -> String -> ParserT s st m String
478mathDisplayWith op cl = try $ do
485mathDisplayWith op cl = try $ do
479 string op
486 string op
480 many1Till (noneOf "\n" <|> (newline >>~ notFollowedBy' blankline)) (try $ string cl)
487 many1Till (noneOf "\n" <|> (newline >>~ notFollowedBy' blankline)) (try $ string cl)
482−mathDisplay :: Parser [Char] ParserState String
489+mathDisplay :: Stream s m Char => ParserT s ParserState m String
483mathDisplay =
490mathDisplay =
484 (guardEnabled Ext_tex_math_dollars >> mathDisplayWith "$$" "$$")
491 (guardEnabled Ext_tex_math_dollars >> mathDisplayWith "$$" "$$")
485 <|> (guardEnabled Ext_tex_math_single_backslash >>
492 <|> (guardEnabled Ext_tex_math_single_backslash >>
@@ -487,7 +494,7 @@ mathDisplay =
487 <|> (guardEnabled Ext_tex_math_double_backslash >>
494 <|> (guardEnabled Ext_tex_math_double_backslash >>
488 mathDisplayWith "\\\\[" "\\\\]")
495 mathDisplayWith "\\\\[" "\\\\]")
490−mathInline :: Parser [Char] ParserState String
497+mathInline :: Stream s m Char => ParserT s ParserState m String
491mathInline =
498mathInline =
492 (guardEnabled Ext_tex_math_dollars >> mathInlineWith "$" "$")
499 (guardEnabled Ext_tex_math_dollars >> mathInlineWith "$" "$")
493 <|> (guardEnabled Ext_tex_math_single_backslash >>
500 <|> (guardEnabled Ext_tex_math_single_backslash >>
@@ -499,8 +506,9 @@ mathInline =
499-- displacement (the difference between the source column at the end
506-- displacement (the difference between the source column at the end
500-- and the source column at the beginning). Vertical displacement
507-- and the source column at the beginning). Vertical displacement
501-- (source row) is ignored.
508-- (source row) is ignored.
502−withHorizDisplacement :: Parser [Char] st a -- ^ Parser to apply
509+withHorizDisplacement :: Stream s m Char
510+ => ParserT s st m a -- ^ Parser to apply
503− -> Parser [Char] st (a, Int) -- ^ (result, displacement)
511+ -> ParserT s st m (a, Int) -- ^ (result, displacement)
504withHorizDisplacement parser = do
512withHorizDisplacement parser = do
505 pos1 <- getPosition
513 pos1 <- getPosition
506 result <- parser
514 result <- parser
@@ -509,7 +517,7 @@ withHorizDisplacement parser = do
510-- | Applies a parser and returns the raw string that was parsed,
518-- | Applies a parser and returns the raw string that was parsed,
511-- along with the value produced by the parser.
519-- along with the value produced by the parser.
512−withRaw :: Monad m => ParsecT [Char] st m a -> ParsecT [Char] st m (a, [Char])
520+withRaw :: Stream [Char] m Char => ParsecT [Char] st m a -> ParsecT [Char] st m (a, [Char])
513withRaw parser = do
521withRaw parser = do
514 pos1 <- getPosition
522 pos1 <- getPosition
515 inp <- getInput
523 inp <- getInput
@@ -525,12 +533,13 @@ withRaw parser = do
525 return (result, raw)
533 return (result, raw)
527-- | Parses backslash, then applies character parser.
535-- | Parses backslash, then applies character parser.
536+escaped :: Stream s m Char
528−escaped :: Parser [Char] st Char -- ^ Parser for character to escape
537+ => ParserT s st m Char -- ^ Parser for character to escape
529− -> Parser [Char] st Char
538+ -> ParserT s st m Char
530escaped parser = try $ char '\\' >> parser
539escaped parser = try $ char '\\' >> parser
532-- | Parse character entity.
541-- | Parse character entity.
533−characterReference :: Parser [Char] st Char
542+characterReference :: Stream s m Char => ParserT s st m Char
534characterReference = try $ do
543characterReference = try $ do
536 ent <- many1Till nonspaceChar (char ';')
545 ent <- many1Till nonspaceChar (char ';')
@@ -539,19 +548,19 @@ characterReference = try $ do
539 Nothing -> fail "entity not found"
548 Nothing -> fail "entity not found"
541-- | Parses an uppercase roman numeral and returns (UpperRoman, number).
550-- | Parses an uppercase roman numeral and returns (UpperRoman, number).
542−upperRoman :: Parser [Char] st (ListNumberStyle, Int)
551+upperRoman :: Stream s m Char => ParserT s st m (ListNumberStyle, Int)
543upperRoman = do
552upperRoman = do
544 num <- romanNumeral True
553 num <- romanNumeral True
545 return (UpperRoman, num)
554 return (UpperRoman, num)
547-- | Parses a lowercase roman numeral and returns (LowerRoman, number).
556-- | Parses a lowercase roman numeral and returns (LowerRoman, number).
548−lowerRoman :: Parser [Char] st (ListNumberStyle, Int)
557+lowerRoman :: Stream s m Char => ParserT s st m (ListNumberStyle, Int)
549lowerRoman = do
558lowerRoman = do
550 num <- romanNumeral False
559 num <- romanNumeral False
551 return (LowerRoman, num)
560 return (LowerRoman, num)
553-- | Parses a decimal numeral and returns (Decimal, number).
562-- | Parses a decimal numeral and returns (Decimal, number).
554−decimal :: Parser [Char] st (ListNumberStyle, Int)
563+decimal :: Stream s m Char => ParserT s st m (ListNumberStyle, Int)
555decimal = do
564decimal = do
556 num <- many1 digit
565 num <- many1 digit
557 return (Decimal, read num)
566 return (Decimal, read num)
@@ -560,7 +569,8 @@ decimal = do
560-- returns (DefaultStyle, [next example number]). The next
569-- returns (DefaultStyle, [next example number]). The next
561-- example number is incremented in parser state, and the label
570-- example number is incremented in parser state, and the label
562-- (if present) is added to the label table.
571-- (if present) is added to the label table.
572+exampleNum :: Stream s m Char
563−exampleNum :: Parser [Char] ParserState (ListNumberStyle, Int)
573+ => ParserT s ParserState m (ListNumberStyle, Int)
564exampleNum = do
574exampleNum = do
566 lab <- many (alphaNum <|> satisfy (\c -> c == '_' || c == '-'))
576 lab <- many (alphaNum <|> satisfy (\c -> c == '_' || c == '-'))
@@ -574,38 +584,39 @@ exampleNum = do
574 return (Example, num)
584 return (Example, num)
576-- | Parses a '#' returns (DefaultStyle, 1).
586-- | Parses a '#' returns (DefaultStyle, 1).
577−defaultNum :: Parser [Char] st (ListNumberStyle, Int)
587+defaultNum :: Stream s m Char => ParserT s st m (ListNumberStyle, Int)
578defaultNum = do
588defaultNum = do
580 return (DefaultStyle, 1)
590 return (DefaultStyle, 1)
582-- | Parses a lowercase letter and returns (LowerAlpha, number).
592-- | Parses a lowercase letter and returns (LowerAlpha, number).
583−lowerAlpha :: Parser [Char] st (ListNumberStyle, Int)
593+lowerAlpha :: Stream s m Char => ParserT s st m (ListNumberStyle, Int)
584lowerAlpha = do
594lowerAlpha = do
585 ch <- oneOf ['a'..'z']
595 ch <- oneOf ['a'..'z']
586 return (LowerAlpha, ord ch - ord 'a' + 1)
596 return (LowerAlpha, ord ch - ord 'a' + 1)
588-- | Parses an uppercase letter and returns (UpperAlpha, number).
598-- | Parses an uppercase letter and returns (UpperAlpha, number).
589−upperAlpha :: Parser [Char] st (ListNumberStyle, Int)
599+upperAlpha :: Stream s m Char => ParserT s st m (ListNumberStyle, Int)
590upperAlpha = do
600upperAlpha = do
591 ch <- oneOf ['A'..'Z']
601 ch <- oneOf ['A'..'Z']
592 return (UpperAlpha, ord ch - ord 'A' + 1)
602 return (UpperAlpha, ord ch - ord 'A' + 1)
594-- | Parses a roman numeral i or I
604-- | Parses a roman numeral i or I
595−romanOne :: Parser [Char] st (ListNumberStyle, Int)
605+romanOne :: Stream s m Char => ParserT s st m (ListNumberStyle, Int)
596romanOne = (char 'i' >> return (LowerRoman, 1)) <|>
606romanOne = (char 'i' >> return (LowerRoman, 1)) <|>
597 (char 'I' >> return (UpperRoman, 1))
607 (char 'I' >> return (UpperRoman, 1))
599-- | Parses an ordered list marker and returns list attributes.
609-- | Parses an ordered list marker and returns list attributes.
600−anyOrderedListMarker :: Parser [Char] ParserState ListAttributes
610+anyOrderedListMarker :: Stream s m Char => ParserT s ParserState m ListAttributes
601anyOrderedListMarker = choice $
611anyOrderedListMarker = choice $
602 [delimParser numParser | delimParser <- [inPeriod, inOneParen, inTwoParens],
612 [delimParser numParser | delimParser <- [inPeriod, inOneParen, inTwoParens],
603 numParser <- [decimal, exampleNum, defaultNum, romanOne,
613 numParser <- [decimal, exampleNum, defaultNum, romanOne,
604 lowerAlpha, lowerRoman, upperAlpha, upperRoman]]
614 lowerAlpha, lowerRoman, upperAlpha, upperRoman]]
606-- | Parses a list number (num) followed by a period, returns list attributes.
616-- | Parses a list number (num) followed by a period, returns list attributes.
617+inPeriod :: Stream s m Char
607−inPeriod :: Parser [Char] st (ListNumberStyle, Int)
618+ => ParserT s st m (ListNumberStyle, Int)
608− -> Parser [Char] st ListAttributes
619+ -> ParserT s st m ListAttributes
609inPeriod num = try $ do
620inPeriod num = try $ do
610 (style, start) <- num
621 (style, start) <- num
@@ -615,16 +626,18 @@ inPeriod num = try $ do
615 return (start, style, delim)
626 return (start, style, delim)
617-- | Parses a list number (num) followed by a paren, returns list attributes.
628-- | Parses a list number (num) followed by a paren, returns list attributes.
629+inOneParen :: Stream s m Char
618−inOneParen :: Parser [Char] st (ListNumberStyle, Int)
630+ => ParserT s st m (ListNumberStyle, Int)
619− -> Parser [Char] st ListAttributes
631+ -> ParserT s st m ListAttributes
620inOneParen num = try $ do
632inOneParen num = try $ do
621 (style, start) <- num
633 (style, start) <- num
623 return (start, style, OneParen)
635 return (start, style, OneParen)
625-- | Parses a list number (num) enclosed in parens, returns list attributes.
637-- | Parses a list number (num) enclosed in parens, returns list attributes.
638+inTwoParens :: Stream s m Char
626−inTwoParens :: Parser [Char] st (ListNumberStyle, Int)
639+ => ParserT s st m (ListNumberStyle, Int)
627− -> Parser [Char] st ListAttributes
640+ -> ParserT s st m ListAttributes
628inTwoParens num = try $ do
641inTwoParens num = try $ do
630 (style, start) <- num
643 (style, start) <- num
@@ -633,9 +646,10 @@ inTwoParens num = try $ do
634-- | Parses an ordered list marker with a given style and delimiter,
647-- | Parses an ordered list marker with a given style and delimiter,
635-- returns number.
648-- returns number.
649+orderedListMarker :: Stream s m Char
636−orderedListMarker :: ListNumberStyle
650+ => ListNumberStyle
637 -> ListNumberDelim
651 -> ListNumberDelim
638− -> Parser [Char] ParserState Int
652+ -> ParserT s ParserState m Int
639orderedListMarker style delim = do
653orderedListMarker style delim = do
640 let num = defaultNum <|> -- # can continue any kind of list
654 let num = defaultNum <|> -- # can continue any kind of list
641 case style of
655 case style of
@@ -655,12 +669,12 @@ orderedListMarker style delim = do
655 return start
669 return start
657-- | Parses a character reference and returns a Str element.
671-- | Parses a character reference and returns a Str element.
658−charRef :: Parser [Char] st Inline
672+charRef :: Stream s m Char => ParserT s st m Inline
659charRef = do
673charRef = do
660 c <- characterReference
674 c <- characterReference
661 return $ Str [c]
675 return $ Str [c]
663−lineBlockLine :: Parser [Char] st String
677+lineBlockLine :: Stream [Char] m Char => ParserT [Char] st m String
664lineBlockLine = try $ do
678lineBlockLine = try $ do
@@ -671,7 +685,7 @@ lineBlockLine = try $ do
671 return $ white ++ unwords (line : continuations)
685 return $ white ++ unwords (line : continuations)
673-- | Parses an RST-style line block and returns a list of strings.
687-- | Parses an RST-style line block and returns a list of strings.
674−lineBlockLines :: Parser [Char] st [String]
688+lineBlockLines :: Stream [Char] m Char => ParserT [Char] st m [String]
675lineBlockLines = try $ do
689lineBlockLines = try $ do
676 lines' <- many1 lineBlockLine
690 lines' <- many1 lineBlockLine
677 skipMany1 $ blankline <|> try (char '|' >> blankline)
691 skipMany1 $ blankline <|> try (char '|' >> blankline)
@@ -679,11 +693,12 @@ lineBlockLines = try $ do
680-- | Parse a table using 'headerParser', 'rowParser',
694-- | Parse a table using 'headerParser', 'rowParser',
681-- 'lineParser', and 'footerParser'.
695-- 'lineParser', and 'footerParser'.
696+tableWith :: Stream s m Char
682−tableWith :: Parser [Char] ParserState ([[Block]], [Alignment], [Int])
697+ => ParserT s ParserState m ([[Block]], [Alignment], [Int])
683− -> ([Int] -> Parser [Char] ParserState [[Block]])
698+ -> ([Int] -> ParserT s ParserState m [[Block]])
684− -> Parser [Char] ParserState sep
699+ -> ParserT s ParserState m sep
685− -> Parser [Char] ParserState end
700+ -> ParserT s ParserState m end
686− -> Parser [Char] ParserState Block
701+ -> ParserT s ParserState m Block
687tableWith headerParser rowParser lineParser footerParser = try $ do
702tableWith headerParser rowParser lineParser footerParser = try $ do
688 (heads, aligns, indices) <- headerParser
703 (heads, aligns, indices) <- headerParser
689 lines' <- rowParser indices `sepEndBy1` lineParser
704 lines' <- rowParser indices `sepEndBy1` lineParser
@@ -725,9 +740,10 @@ widthsFromIndices numColumns' indices =
725-- (which may be grid), then the rows,
740-- (which may be grid), then the rows,
726-- which may be grid, separated by blank lines, and
741-- which may be grid, separated by blank lines, and
727-- ending with a footer (dashed line followed by blank line).
742-- ending with a footer (dashed line followed by blank line).
743+gridTableWith :: Stream [Char] m Char
728−gridTableWith :: Parser [Char] ParserState [Block] -- ^ Block list parser
744+ => ParserT [Char] ParserState m [Block] -- ^ Block list parser
729 -> Bool -- ^ Headerless table
745 -> Bool -- ^ Headerless table
730− -> Parser [Char] ParserState Block
746+ -> ParserT [Char] ParserState m Block
731gridTableWith blocks headless =
747gridTableWith blocks headless =
732 tableWith (gridTableHeader headless blocks) (gridTableRow blocks)
748 tableWith (gridTableHeader headless blocks) (gridTableRow blocks)
733 (gridTableSep '-') gridTableFooter
749 (gridTableSep '-') gridTableFooter
@@ -736,13 +752,13 @@ gridTableSplitLine :: [Int] -> String -> [String]
736gridTableSplitLine indices line = map removeFinalBar $ tail $
752gridTableSplitLine indices line = map removeFinalBar $ tail $
737 splitStringByIndices (init indices) $ trimr line
753 splitStringByIndices (init indices) $ trimr line
739−gridPart :: Char -> Parser [Char] st (Int, Int)
755+gridPart :: Stream s m Char => Char -> ParserT s st m (Int, Int)
740gridPart ch = do
756gridPart ch = do
741 dashes <- many1 (char ch)
757 dashes <- many1 (char ch)
743 return (length dashes, length dashes + 1)
759 return (length dashes, length dashes + 1)
745−gridDashedLines :: Char -> Parser [Char] st [(Int,Int)]
761+gridDashedLines :: Stream s m Char => Char -> ParserT s st m [(Int,Int)]
746gridDashedLines ch = try $ char '+' >> many1 (gridPart ch) >>~ blankline
762gridDashedLines ch = try $ char '+' >> many1 (gridPart ch) >>~ blankline
748removeFinalBar :: String -> String
764removeFinalBar :: String -> String
@@ -750,13 +766,14 @@ removeFinalBar =
750 reverse . dropWhile (`elem` " \t") . dropWhile (=='|') . reverse
766 reverse . dropWhile (`elem` " \t") . dropWhile (=='|') . reverse
752-- | Separator between rows of grid table.
768-- | Separator between rows of grid table.
753−gridTableSep :: Char -> Parser [Char] ParserState Char
769+gridTableSep :: Stream s m Char => Char -> ParserT s ParserState m Char
754gridTableSep ch = try $ gridDashedLines ch >> return '\n'
770gridTableSep ch = try $ gridDashedLines ch >> return '\n'
756-- | Parse header for a grid table.
772-- | Parse header for a grid table.
773+gridTableHeader :: Stream [Char] m Char
757−gridTableHeader :: Bool -- ^ Headerless table
774+ => Bool -- ^ Headerless table
758− -> Parser [Char] ParserState [Block]
775+ -> ParserT [Char] ParserState m [Block]
759− -> Parser [Char] ParserState ([[Block]], [Alignment], [Int])
776+ -> ParserT [Char] ParserState m ([[Block]], [Alignment], [Int])
760gridTableHeader headless blocks = try $ do
777gridTableHeader headless blocks = try $ do
761 optional blanklines
778 optional blanklines
762 dashes <- gridDashedLines '-'
779 dashes <- gridDashedLines '-'
@@ -779,16 +796,17 @@ gridTableHeader headless blocks = try $ do
779 heads <- mapM (parseFromString blocks) $ map trim rawHeads
796 heads <- mapM (parseFromString blocks) $ map trim rawHeads
780 return (heads, aligns, indices)
797 return (heads, aligns, indices)
782−gridTableRawLine :: [Int] -> Parser [Char] ParserState [String]
799+gridTableRawLine :: Stream s m Char => [Int] -> ParserT s ParserState m [String]
783gridTableRawLine indices = do
800gridTableRawLine indices = do
785 line <- many1Till anyChar newline
802 line <- many1Till anyChar newline
786 return (gridTableSplitLine indices line)
803 return (gridTableSplitLine indices line)
788-- | Parse row of grid table.
805-- | Parse row of grid table.
806+gridTableRow :: Stream [Char] m Char
789−gridTableRow :: Parser [Char] ParserState [Block]
807+ => ParserT [Char] ParserState m [Block]
791− -> Parser [Char] ParserState [[Block]]
809+ -> ParserT [Char] ParserState m [[Block]]
792gridTableRow blocks indices = do
810gridTableRow blocks indices = do
793 colLines <- many1 (gridTableRawLine indices)
811 colLines <- many1 (gridTableRawLine indices)
794 let cols = map ((++ "\n") . unlines . removeOneLeadingSpace) $
812 let cols = map ((++ "\n") . unlines . removeOneLeadingSpace) $
@@ -807,15 +825,16 @@ compactifyCell :: [Block] -> [Block]
807compactifyCell bs = head $ compactify [bs]
825compactifyCell bs = head $ compactify [bs]
809-- | Parse footer for a grid table.
827-- | Parse footer for a grid table.
810−gridTableFooter :: Parser [Char] ParserState [Char]
828+gridTableFooter :: Stream s m Char => ParserT s ParserState m [Char]
811gridTableFooter = blanklines
829gridTableFooter = blanklines
815-- | Parse a string with a given parser and state.
833-- | Parse a string with a given parser and state.
816−readWith :: Parser [Char] st a -- ^ parser
834+readWith :: (Show s, Stream s Identity Char)
835+ => ParserT s st Identity a -- ^ parser
817 -> st -- ^ initial state
836 -> st -- ^ initial state
818− -> [Char] -- ^ input
837+ -> s -- ^ input
820readWith parser state input =
839readWith parser state input =
821 case runParser parser state "source" input of
840 case runParser parser state "source" input of
@@ -823,15 +842,16 @@ readWith parser state input =
823 let errPos = errorPos err'
842 let errPos = errorPos err'
824 errLine = sourceLine errPos
843 errLine = sourceLine errPos
825 errColumn = sourceColumn errPos
844 errColumn = sourceColumn errPos
826− theline = (lines input ++ [""]) !! (errLine - 1)
845+ theline = (lines (show input) ++ [""]) !! (errLine - 1)
827 in error $ "\nError at " ++ show err' ++ "\n" ++
846 in error $ "\nError at " ++ show err' ++ "\n" ++
828 theline ++ "\n" ++ replicate (errColumn - 1) ' ' ++
847 theline ++ "\n" ++ replicate (errColumn - 1) ' ' ++
830 Right result -> result
849 Right result -> result
832-- | Parse a string with @parser@ (for testing).
851-- | Parse a string with @parser@ (for testing).
833−testStringWith :: (Show a) => Parser [Char] ParserState a
852+testStringWith :: (Show s, Show a, Stream s Identity Char)
834− -> String
853+ => ParserT s ParserState Identity a
836testStringWith parser str = UTF8.putStrLn $ show $
856testStringWith parser str = UTF8.putStrLn $ show $
837 readWith parser defaultParserState str
857 readWith parser defaultParserState str
@@ -878,7 +898,7 @@ instance HasMeta ParserState where
879class HasReaderOptions st where
899class HasReaderOptions st where
880 extractReaderOptions :: st -> ReaderOptions
900 extractReaderOptions :: st -> ReaderOptions
881− getOption :: (ReaderOptions -> b) -> Parser s st b
901+ getOption :: (Stream s m t) => (ReaderOptions -> b) -> ParserT s st m b
882 -- default
902 -- default
883 getOption f = (f . extractReaderOptions) `fmap` getState
903 getOption f = (f . extractReaderOptions) `fmap` getState
@@ -946,19 +966,19 @@ defaultParserState =
946 stateWarnings = []}
966 stateWarnings = []}
948-- | Succeed only if the extension is enabled.
968-- | Succeed only if the extension is enabled.
949−guardEnabled :: HasReaderOptions st => Extension -> Parser s st ()
969+guardEnabled :: (Stream s m a, HasReaderOptions st) => Extension -> ParserT s st m ()
950guardEnabled ext = getOption readerExtensions >>= guard . Set.member ext
970guardEnabled ext = getOption readerExtensions >>= guard . Set.member ext
952-- | Succeed only if the extension is disabled.
972-- | Succeed only if the extension is disabled.
953−guardDisabled :: HasReaderOptions st => Extension -> Parser s st ()
973+guardDisabled :: (Stream s m a, HasReaderOptions st) => Extension -> ParserT s st m ()
954guardDisabled ext = getOption readerExtensions >>= guard . not . Set.member ext
974guardDisabled ext = getOption readerExtensions >>= guard . not . Set.member ext
956-- | Update the position on which the last string ended.
976-- | Update the position on which the last string ended.
957−updateLastStrPos :: HasLastStrPosition st => Parser s st ()
977+updateLastStrPos :: (Stream s m a, HasLastStrPosition st) => ParserT s st m ()
958updateLastStrPos = getPosition >>= updateState . setLastStrPos
978updateLastStrPos = getPosition >>= updateState . setLastStrPos
960-- | Whether we are right after the end of a string.
980-- | Whether we are right after the end of a string.
961−notAfterString :: HasLastStrPosition st => Parser s st Bool
981+notAfterString :: (Stream s m a, HasLastStrPosition st) => ParserT s st m Bool
962notAfterString = do
982notAfterString = do
963 pos <- getPosition
983 pos <- getPosition
964 st <- getState
984 st <- getState
@@ -998,8 +1018,8 @@ type SubstTable = M.Map Key Inlines
998-- and the auto_identifers extension is set, generate a new
1018-- and the auto_identifers extension is set, generate a new
999-- unique identifier, and update the list of identifiers
1019-- unique identifier, and update the list of identifiers
1000-- in state.
1020-- in state.
1001−registerHeader :: (HasReaderOptions st, HasHeaderMap st, HasIdentifierList st)
1021+registerHeader :: (Stream s m a, HasReaderOptions st, HasHeaderMap st, HasIdentifierList st)
1002− => Attr -> Inlines -> Parser s st Attr
1022+ => Attr -> Inlines -> ParserT s st m Attr
1003registerHeader (ident,classes,kvs) header' = do
1023registerHeader (ident,classes,kvs) header' = do
1004 ids <- extractIdentifierList `fmap` getState
1024 ids <- extractIdentifierList `fmap` getState
1005 exts <- getOption readerExtensions
1025 exts <- getOption readerExtensions
@@ -1020,25 +1040,28 @@ registerHeader (ident,classes,kvs) header' = do
1020 return (ident,classes,kvs)
1040 return (ident,classes,kvs)
1022-- | Fail unless we're in "smart typography" mode.
1042-- | Fail unless we're in "smart typography" mode.
1023−failUnlessSmart :: HasReaderOptions st => Parser s st ()
1043+failUnlessSmart :: (Stream s m a, HasReaderOptions st) => ParserT s st m ()
1024failUnlessSmart = getOption readerSmart >>= guard
1044failUnlessSmart = getOption readerSmart >>= guard
1026−smartPunctuation :: Parser [Char] ParserState Inlines
1046+smartPunctuation :: Stream s m Char
1047+ => ParserT s ParserState m Inlines
1027− -> Parser [Char] ParserState Inlines
1048+ -> ParserT s ParserState m Inlines
1028smartPunctuation inlineParser = do
1049smartPunctuation inlineParser = do
1029 failUnlessSmart
1050 failUnlessSmart
1030 choice [ quoted inlineParser, apostrophe, dash, ellipses ]
1051 choice [ quoted inlineParser, apostrophe, dash, ellipses ]
1032−apostrophe :: Parser [Char] ParserState Inlines
1053+apostrophe :: Stream s m Char => ParserT s st m Inlines
1033apostrophe = (char '\'' <|> char '\8217') >> return (B.str "\x2019")
1054apostrophe = (char '\'' <|> char '\8217') >> return (B.str "\x2019")
1056+quoted :: Stream s m Char
1035−quoted :: Parser [Char] ParserState Inlines
1057+ => ParserT s ParserState m Inlines
1036− -> Parser [Char] ParserState Inlines
1058+ -> ParserT s ParserState m Inlines
1037quoted inlineParser = doubleQuoted inlineParser <|> singleQuoted inlineParser
1059quoted inlineParser = doubleQuoted inlineParser <|> singleQuoted inlineParser
1039−withQuoteContext :: QuoteContext
1061+withQuoteContext :: Stream s m t
1040− -> Parser [tok] ParserState a
1063+ -> ParserT s ParserState m a
1041− -> Parser [tok] ParserState a
1064+ -> ParserT s ParserState m a
1042withQuoteContext context parser = do
1065withQuoteContext context parser = do
1043 oldState <- getState
1066 oldState <- getState
1044 let oldQuoteContext = stateQuoteContext oldState
1067 let oldQuoteContext = stateQuoteContext oldState
@@ -1048,99 +1071,112 @@ withQuoteContext context parser = do
1048 setState newState { stateQuoteContext = oldQuoteContext }
1071 setState newState { stateQuoteContext = oldQuoteContext }
1049 return result
1072 return result
1074+singleQuoted :: Stream s m Char
1051−singleQuoted :: Parser [Char] ParserState Inlines
1075+ => ParserT s ParserState m Inlines
1052− -> Parser [Char] ParserState Inlines
1076+ -> ParserT s ParserState m Inlines
1053singleQuoted inlineParser = try $ do
1077singleQuoted inlineParser = try $ do
1054 singleQuoteStart
1078 singleQuoteStart
1055 withQuoteContext InSingleQuote $ many1Till inlineParser singleQuoteEnd >>=
1079 withQuoteContext InSingleQuote $ many1Till inlineParser singleQuoteEnd >>=
1056 return . B.singleQuoted . mconcat
1080 return . B.singleQuoted . mconcat
1082+doubleQuoted :: Stream s m Char
1058−doubleQuoted :: Parser [Char] ParserState Inlines
1083+ => ParserT s ParserState m Inlines
1059− -> Parser [Char] ParserState Inlines
1084+ -> ParserT s ParserState m Inlines
1060doubleQuoted inlineParser = try $ do
1085doubleQuoted inlineParser = try $ do
1061 doubleQuoteStart
1086 doubleQuoteStart
1062 withQuoteContext InDoubleQuote $ manyTill inlineParser doubleQuoteEnd >>=
1087 withQuoteContext InDoubleQuote $ manyTill inlineParser doubleQuoteEnd >>=
1063 return . B.doubleQuoted . mconcat
1088 return . B.doubleQuoted . mconcat
1065−failIfInQuoteContext :: QuoteContext -> Parser [tok] ParserState ()
1090+failIfInQuoteContext :: Stream s m t
1092+ -> ParserT s ParserState m ()
1066failIfInQuoteContext context = do
1093failIfInQuoteContext context = do
1067 st <- getState
1094 st <- getState
1068 if stateQuoteContext st == context
1095 if stateQuoteContext st == context
1069 then fail "already inside quotes"
1096 then fail "already inside quotes"
1070 else return ()
1097 else return ()
1072−charOrRef :: [Char] -> Parser [Char] st Char
1099+charOrRef :: Stream s m Char => String -> ParserT s st m Char
1073charOrRef cs =
1100charOrRef cs =
1074 oneOf cs <|> try (do c <- characterReference
1101 oneOf cs <|> try (do c <- characterReference
1075 guard (c `elem` cs)
1102 guard (c `elem` cs)
1076 return c)
1103 return c)
1078−singleQuoteStart :: Parser [Char] ParserState ()
1105+singleQuoteStart :: Stream s m Char
1106+ => ParserT s ParserState m ()
1079singleQuoteStart = do
1107singleQuoteStart = do
1080 failIfInQuoteContext InSingleQuote
1108 failIfInQuoteContext InSingleQuote
1081 -- single quote start can't be right after str
1109 -- single quote start can't be right after str
1082 guard =<< notAfterString
1110 guard =<< notAfterString
1083 () <$ charOrRef "'\8216\145"
1111 () <$ charOrRef "'\8216\145"
1085−singleQuoteEnd :: Parser [Char] st ()
1113+singleQuoteEnd :: Stream s m Char
1114+ => ParserT s st m ()
1086singleQuoteEnd = try $ do
1115singleQuoteEnd = try $ do
1087 charOrRef "'\8217\146"
1116 charOrRef "'\8217\146"
1088 notFollowedBy alphaNum
1117 notFollowedBy alphaNum
1090−doubleQuoteStart :: Parser [Char] ParserState ()
1119+doubleQuoteStart :: Stream s m Char
1120+ => ParserT s ParserState m ()
1091doubleQuoteStart = do
1121doubleQuoteStart = do
1092 failIfInQuoteContext InDoubleQuote
1122 failIfInQuoteContext InDoubleQuote
1093 try $ do charOrRef "\"\8220\147"
1123 try $ do charOrRef "\"\8220\147"
1094 notFollowedBy . satisfy $ flip elem [' ', '\t', '\n']
1124 notFollowedBy . satisfy $ flip elem [' ', '\t', '\n']
1096−doubleQuoteEnd :: Parser [Char] st ()
1126+doubleQuoteEnd :: Stream s m Char
1097−doubleQuoteEnd = do
1127+ => ParserT s st m ()
1098− charOrRef "\"\8221\148"
1128+doubleQuoteEnd = void (charOrRef "\"\8221\148")
1101−ellipses :: Parser [Char] st Inlines
1130+ellipses :: Stream s m Char
1131+ => ParserT s st m Inlines
1102ellipses = do
1132ellipses = do
1103 try (charOrRef "\8230\133") <|> try (string "..." >> return '…')
1133 try (charOrRef "\8230\133") <|> try (string "..." >> return '…')
1104 return (B.str "\8230")
1134 return (B.str "\8230")
1106−dash :: Parser [Char] ParserState Inlines
1136+dash :: Stream s m Char => ParserT s ParserState m Inlines
1107dash = do
1137dash = do
1108 oldDashes <- getOption readerOldDashes
1138 oldDashes <- getOption readerOldDashes
1109 if oldDashes
1139 if oldDashes
1110 then emDashOld <|> enDashOld
1140 then emDashOld <|> enDashOld
1111− else B.str `fmap` (hyphenDash <|> emDash <|> enDash)
1141+ else B.str <$> (hyphenDash <|> emDash <|> enDash)
1113-- Two hyphens = en-dash, three = em-dash
1143-- Two hyphens = en-dash, three = em-dash
1114−hyphenDash :: Parser [Char] st String
1144+hyphenDash :: Stream s m Char
1145+ => ParserT s st m String
1115hyphenDash = do
1146hyphenDash = do
1116 try $ string "--"
1147 try $ string "--"
1117 option "\8211" (char '-' >> return "\8212")
1148 option "\8211" (char '-' >> return "\8212")
1119−emDash :: Parser [Char] st String
1150+emDash :: Stream s m Char
1151+ => ParserT s st m String
1120emDash = do
1152emDash = do
1121 try (charOrRef "\8212\151")
1153 try (charOrRef "\8212\151")
1122 return "\8212"
1154 return "\8212"
1124−enDash :: Parser [Char] st String
1156+enDash :: Stream s m Char
1157+ => ParserT s st m String
1125enDash = do
1158enDash = do
1126 try (charOrRef "\8212\151")
1159 try (charOrRef "\8212\151")
1127 return "\8211"
1160 return "\8211"
1129−enDashOld :: Parser [Char] st Inlines
1162+enDashOld :: Stream s m Char
1163+ => ParserT s st m Inlines
1130enDashOld = do
1164enDashOld = do
1131 try (charOrRef "\8211\150") <|>
1165 try (charOrRef "\8211\150") <|>
1132 try (char '-' >> lookAhead (satisfy isDigit) >> return '–')
1166 try (char '-' >> lookAhead (satisfy isDigit) >> return '–')
1133 return (B.str "\8211")
1167 return (B.str "\8211")
1135−emDashOld :: Parser [Char] st Inlines
1169+emDashOld :: Stream s m Char
1170+ => ParserT s st m Inlines
1136emDashOld = do
1171emDashOld = do
1137 try (charOrRef "\8212\151") <|> (try $ string "--" >> optional (char '-') >> return '-')
1172 try (charOrRef "\8212\151") <|> (try $ string "--" >> optional (char '-') >> return '-')
1138 return (B.str "\8212")
1173 return (B.str "\8212")
1140-- This is used to prevent exponential blowups for things like:
1175-- This is used to prevent exponential blowups for things like:
1141-- a**a*a**a*a**a*a**a*a**a*a**a*a**
1176-- a**a*a**a*a**a*a**a*a**a*a**a*a**
1177+nested :: Stream s m a
1142−nested :: Parser s ParserState a
1178+ => ParserT s ParserState m a
1143− -> Parser s ParserState a
1179+ -> ParserT s ParserState m a
1144nested p = do
1180nested p = do
1145 nestlevel <- stateMaxNestingLevel `fmap` getState
1181 nestlevel <- stateMaxNestingLevel `fmap` getState
1146 guard $ nestlevel > 0
1182 guard $ nestlevel > 0
@@ -1149,7 +1185,8 @@ nested p = do
1149 updateState $ \st -> st{ stateMaxNestingLevel = nestlevel }
1185 updateState $ \st -> st{ stateMaxNestingLevel = nestlevel }
1150 return res
1186 return res
1152−citeKey :: HasLastStrPosition st => Parser [Char] st (Bool, String)
1188+citeKey :: (Stream s m Char, HasLastStrPosition st)
1189+ => ParserT s st m (Bool, String)
1153citeKey = try $ do
1190citeKey = try $ do
1154 guard =<< notAfterString
1191 guard =<< notAfterString
1155 suppress_author <- option False (char '-' *> return True)
1192 suppress_author <- option False (char '-' *> return True)
@@ -1166,7 +1203,8 @@ citeKey = try $ do
1168-- | Parse a \newcommand or \renewcommand macro definition.
1205-- | Parse a \newcommand or \renewcommand macro definition.
1169−macro :: (HasMacros st, HasReaderOptions st) => Parser [Char] st Blocks
1206+macro :: (Stream [Char] m Char, HasMacros st, HasReaderOptions st)
1207+ => ParserT [Char] st m Blocks
1170macro = do
1208macro = do
1171 apply <- getOption readerApplyMacros
1209 apply <- getOption readerApplyMacros
1172 inp <- getInput
1210 inp <- getInput
@@ -1181,7 +1219,9 @@ macro = do
1181 else return $ rawBlock "latex" def'
1219 else return $ rawBlock "latex" def'
1183-- | Apply current macros to string.
1221-- | Apply current macros to string.
1222+applyMacros' :: Stream [Char] m Char
1184−applyMacros' :: String -> Parser [Char] ParserState String
1224+ -> ParserT [Char] ParserState m String
1185applyMacros' target = do
1225applyMacros' target = do
1186 apply <- getOption readerApplyMacros
1226 apply <- getOption readerApplyMacros
1187 if apply
1227 if apply