{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE OverloadedStrings #-}
module Text.Pandoc.Parsing.Lists
( anyOrderedListMarker
, decimal
, lowerAlpha
, lowerRoman
, orderedListMarker
, romanNumeral
, upperAlpha
, upperRoman
)
where
import Data.Char
( isAsciiUpper
, isAsciiLower
, ord
, toLower
)
import Data.Maybe (fromMaybe)
import Text.Pandoc.Definition
( ListNumberDelim(..)
, ListAttributes
, ListNumberStyle(..)
)
import Text.Pandoc.Shared (safeRead)
import Text.Pandoc.Sources
import Text.Parsec
( (<|>)
, ParsecT
, Stream(..)
, choice
, getState
, lookAhead
, many
, many1
, option
, try
, updateState
)
import Text.Pandoc.Parsing.State
import qualified Data.Map as M
import qualified Data.Text as T
romanNumeral :: (Stream s m Char, UpdateSourcePos s Char)
=> Bool
-> ParsecT s st m Int
romanNumeral :: forall s (m :: * -> *) st.
(Stream s m Char, UpdateSourcePos s Char) =>
Bool -> ParsecT s st m Int
romanNumeral Bool
upperCase = do
let rchar :: Char -> ParsecT s u m Char
rchar Char
uc = forall (m :: * -> *) s u.
(Monad m, Stream s m Char, UpdateSourcePos s Char) =>
Char -> ParsecT s u m Char
char forall a b. (a -> b) -> a -> b
$ if Bool
upperCase then Char
uc else Char -> Char
toLower Char
uc
let one :: ParsecT s u m Char
one = forall {m :: * -> *} {s} {u}.
(Stream s m Char, UpdateSourcePos s Char) =>
Char -> ParsecT s u m Char
rchar Char
'I'
let five :: ParsecT s u m Char
five = forall {m :: * -> *} {s} {u}.
(Stream s m Char, UpdateSourcePos s Char) =>
Char -> ParsecT s u m Char
rchar Char
'V'
let ten :: ParsecT s u m Char
ten = forall {m :: * -> *} {s} {u}.
(Stream s m Char, UpdateSourcePos s Char) =>
Char -> ParsecT s u m Char
rchar Char
'X'
let fifty :: ParsecT s u m Char
fifty = forall {m :: * -> *} {s} {u}.
(Stream s m Char, UpdateSourcePos s Char) =>
Char -> ParsecT s u m Char
rchar Char
'L'
let hundred :: ParsecT s u m Char
hundred = forall {m :: * -> *} {s} {u}.
(Stream s m Char, UpdateSourcePos s Char) =>
Char -> ParsecT s u m Char
rchar Char
'C'
let fivehundred :: ParsecT s u m Char
fivehundred = forall {m :: * -> *} {s} {u}.
(Stream s m Char, UpdateSourcePos s Char) =>
Char -> ParsecT s u m Char
rchar Char
'D'
let thousand :: ParsecT s u m Char
thousand = forall {m :: * -> *} {s} {u}.
(Stream s m Char, UpdateSourcePos s Char) =>
Char -> ParsecT s u m Char
rchar Char
'M'
forall s (m :: * -> *) t u a.
Stream s m t =>
ParsecT s u m a -> ParsecT s u m a
lookAhead forall a b. (a -> b) -> a -> b
$ forall s (m :: * -> *) t u a.
Stream s m t =>
[ParsecT s u m a] -> ParsecT s u m a
choice [forall {u}. ParsecT s u m Char
one, forall {u}. ParsecT s u m Char
five, forall {u}. ParsecT s u m Char
ten, forall {u}. ParsecT s u m Char
fifty, forall {u}. ParsecT s u m Char
hundred, forall {u}. ParsecT s u m Char
fivehundred, forall {u}. ParsecT s u m Char
thousand]
Int
thousands <- (Int
1000 forall a. Num a => a -> a -> a
*) forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall (t :: * -> *) a. Foldable t => t a -> Int
length forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m [a]
many forall {u}. ParsecT s u m Char
thousand
Int
ninehundreds <- forall s (m :: * -> *) t a u.
Stream s m t =>
a -> ParsecT s u m a -> ParsecT s u m a
option Int
0 forall a b. (a -> b) -> a -> b
$ forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try forall a b. (a -> b) -> a -> b
$ forall {u}. ParsecT s u m Char
hundred forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> forall {u}. ParsecT s u m Char
thousand forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> forall (m :: * -> *) a. Monad m => a -> m a
return Int
900
Int
fivehundreds <- forall s (m :: * -> *) t a u.
Stream s m t =>
a -> ParsecT s u m a -> ParsecT s u m a
option Int
0 forall a b. (a -> b) -> a -> b
$ Int
500 forall (f :: * -> *) a b. Functor f => a -> f b -> f a
<$ forall {u}. ParsecT s u m Char
fivehundred
Int
fourhundreds <- forall s (m :: * -> *) t a u.
Stream s m t =>
a -> ParsecT s u m a -> ParsecT s u m a
option Int
0 forall a b. (a -> b) -> a -> b
$ forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try forall a b. (a -> b) -> a -> b
$ forall {u}. ParsecT s u m Char
hundred forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> forall {u}. ParsecT s u m Char
fivehundred forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> forall (m :: * -> *) a. Monad m => a -> m a
return Int
400
Int
hundreds <- (Int
100 forall a. Num a => a -> a -> a
*) forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall (t :: * -> *) a. Foldable t => t a -> Int
length forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m [a]
many forall {u}. ParsecT s u m Char
hundred
Int
nineties <- forall s (m :: * -> *) t a u.
Stream s m t =>
a -> ParsecT s u m a -> ParsecT s u m a
option Int
0 forall a b. (a -> b) -> a -> b
$ forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try forall a b. (a -> b) -> a -> b
$ forall {u}. ParsecT s u m Char
ten forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> forall {u}. ParsecT s u m Char
hundred forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> forall (m :: * -> *) a. Monad m => a -> m a
return Int
90
Int
fifties <- forall s (m :: * -> *) t a u.
Stream s m t =>
a -> ParsecT s u m a -> ParsecT s u m a
option Int
0 (Int
50 forall (f :: * -> *) a b. Functor f => a -> f b -> f a
<$ forall {u}. ParsecT s u m Char
fifty)
Int
forties <- forall s (m :: * -> *) t a u.
Stream s m t =>
a -> ParsecT s u m a -> ParsecT s u m a
option Int
0 forall a b. (a -> b) -> a -> b
$ forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try forall a b. (a -> b) -> a -> b
$ forall {u}. ParsecT s u m Char
ten forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> forall {u}. ParsecT s u m Char
fifty forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> forall (m :: * -> *) a. Monad m => a -> m a
return Int
40
Int
tens <- (Int
10 forall a. Num a => a -> a -> a
*) forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall (t :: * -> *) a. Foldable t => t a -> Int
length forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m [a]
many forall {u}. ParsecT s u m Char
ten
Int
nines <- forall s (m :: * -> *) t a u.
Stream s m t =>
a -> ParsecT s u m a -> ParsecT s u m a
option Int
0 forall a b. (a -> b) -> a -> b
$ forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try forall a b. (a -> b) -> a -> b
$ forall {u}. ParsecT s u m Char
one forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> forall {u}. ParsecT s u m Char
ten forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> forall (m :: * -> *) a. Monad m => a -> m a
return Int
9
Int
fives <- forall s (m :: * -> *) t a u.
Stream s m t =>
a -> ParsecT s u m a -> ParsecT s u m a
option Int
0 (Int
5 forall (f :: * -> *) a b. Functor f => a -> f b -> f a
<$ forall {u}. ParsecT s u m Char
five)
Int
fours <- forall s (m :: * -> *) t a u.
Stream s m t =>
a -> ParsecT s u m a -> ParsecT s u m a
option Int
0 forall a b. (a -> b) -> a -> b
$ forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try forall a b. (a -> b) -> a -> b
$ forall {u}. ParsecT s u m Char
one forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> forall {u}. ParsecT s u m Char
five forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> forall (m :: * -> *) a. Monad m => a -> m a
return Int
4
Int
ones <- forall (t :: * -> *) a. Foldable t => t a -> Int
length forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m [a]
many forall {u}. ParsecT s u m Char
one
let total :: Int
total = Int
thousands forall a. Num a => a -> a -> a
+ Int
ninehundreds forall a. Num a => a -> a -> a
+ Int
fivehundreds forall a. Num a => a -> a -> a
+ Int
fourhundreds forall a. Num a => a -> a -> a
+
Int
hundreds forall a. Num a => a -> a -> a
+ Int
nineties forall a. Num a => a -> a -> a
+ Int
fifties forall a. Num a => a -> a -> a
+ Int
forties forall a. Num a => a -> a -> a
+ Int
tens forall a. Num a => a -> a -> a
+ Int
nines forall a. Num a => a -> a -> a
+
Int
fives forall a. Num a => a -> a -> a
+ Int
fours forall a. Num a => a -> a -> a
+ Int
ones
if Int
total forall a. Eq a => a -> a -> Bool
== Int
0
then forall (m :: * -> *) a. MonadFail m => [Char] -> m a
Prelude.fail [Char]
"not a roman numeral"
else forall (m :: * -> *) a. Monad m => a -> m a
return Int
total
upperRoman :: (Stream s m Char, UpdateSourcePos s Char) => ParsecT s st m (ListNumberStyle, Int)
upperRoman :: forall s (m :: * -> *) st.
(Stream s m Char, UpdateSourcePos s Char) =>
ParsecT s st m (ListNumberStyle, Int)
upperRoman = do
Int
num <- forall s (m :: * -> *) st.
(Stream s m Char, UpdateSourcePos s Char) =>
Bool -> ParsecT s st m Int
romanNumeral Bool
True
forall (m :: * -> *) a. Monad m => a -> m a
return (ListNumberStyle
UpperRoman, Int
num)
lowerRoman :: (Stream s m Char, UpdateSourcePos s Char) => ParsecT s st m (ListNumberStyle, Int)
lowerRoman :: forall s (m :: * -> *) st.
(Stream s m Char, UpdateSourcePos s Char) =>
ParsecT s st m (ListNumberStyle, Int)
lowerRoman = do
Int
num <- forall s (m :: * -> *) st.
(Stream s m Char, UpdateSourcePos s Char) =>
Bool -> ParsecT s st m Int
romanNumeral Bool
False
forall (m :: * -> *) a. Monad m => a -> m a
return (ListNumberStyle
LowerRoman, Int
num)
decimal :: (Stream s m Char, UpdateSourcePos s Char) => ParsecT s st m (ListNumberStyle, Int)
decimal :: forall s (m :: * -> *) st.
(Stream s m Char, UpdateSourcePos s Char) =>
ParsecT s st m (ListNumberStyle, Int)
decimal = do
[Char]
num <- forall s (m :: * -> *) t u a.
Stream s m t =>
ParsecT s u m a -> ParsecT s u m [a]
many1 forall (m :: * -> *) s u.
(Monad m, Stream s m Char, UpdateSourcePos s Char) =>
ParsecT s u m Char
digit
forall (m :: * -> *) a. Monad m => a -> m a
return (ListNumberStyle
Decimal, forall a. a -> Maybe a -> a
fromMaybe Int
1 forall a b. (a -> b) -> a -> b
$ forall (m :: * -> *) a. (MonadPlus m, Read a) => Text -> m a
safeRead forall a b. (a -> b) -> a -> b
$ [Char] -> Text
T.pack [Char]
num)
exampleNum :: (Stream s m Char, UpdateSourcePos s Char)
=> ParsecT s ParserState m (ListNumberStyle, Int)
exampleNum :: forall s (m :: * -> *).
(Stream s m Char, UpdateSourcePos s Char) =>
ParsecT s ParserState m (ListNumberStyle, Int)
exampleNum = do
forall (m :: * -> *) s u.
(Monad m, Stream s m Char, UpdateSourcePos s Char) =>
Char -> ParsecT s u m Char
char Char
'@'
Text
lab <- forall a. Monoid a => [a] -> a
mconcat forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a b. (a -> b) -> [a] -> [b]
map [Char] -> Text
T.pack forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$>
forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m [a]
many (forall s (m :: * -> *) t u a.
Stream s m t =>
ParsecT s u m a -> ParsecT s u m [a]
many1 forall (m :: * -> *) s u.
(Monad m, Stream s m Char, UpdateSourcePos s Char) =>
ParsecT s u m Char
alphaNum forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|>
forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try (do Char
c <- forall (m :: * -> *) s u.
(Monad m, Stream s m Char, UpdateSourcePos s Char) =>
Char -> ParsecT s u m Char
char Char
'_' forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|> forall (m :: * -> *) s u.
(Monad m, Stream s m Char, UpdateSourcePos s Char) =>
Char -> ParsecT s u m Char
char Char
'-'
[Char]
cs <- forall s (m :: * -> *) t u a.
Stream s m t =>
ParsecT s u m a -> ParsecT s u m [a]
many1 forall (m :: * -> *) s u.
(Monad m, Stream s m Char, UpdateSourcePos s Char) =>
ParsecT s u m Char
alphaNum
forall (m :: * -> *) a. Monad m => a -> m a
return (Char
cforall a. a -> [a] -> [a]
:[Char]
cs)))
ParserState
st <- forall (m :: * -> *) s u. Monad m => ParsecT s u m u
getState
let num :: Int
num = ParserState -> Int
stateNextExample ParserState
st
let newlabels :: Map Text Int
newlabels = if Text -> Bool
T.null Text
lab
then ParserState -> Map Text Int
stateExamples ParserState
st
else forall k a. Ord k => k -> a -> Map k a -> Map k a
M.insert Text
lab Int
num forall a b. (a -> b) -> a -> b
$ ParserState -> Map Text Int
stateExamples ParserState
st
forall (m :: * -> *) u s. Monad m => (u -> u) -> ParsecT s u m ()
updateState forall a b. (a -> b) -> a -> b
$ \ParserState
s -> ParserState
s{ stateNextExample :: Int
stateNextExample = Int
num forall a. Num a => a -> a -> a
+ Int
1
, stateExamples :: Map Text Int
stateExamples = Map Text Int
newlabels }
forall (m :: * -> *) a. Monad m => a -> m a
return (ListNumberStyle
Example, Int
num)
defaultNum :: (Stream s m Char, UpdateSourcePos s Char) => ParsecT s st m (ListNumberStyle, Int)
defaultNum :: forall s (m :: * -> *) st.
(Stream s m Char, UpdateSourcePos s Char) =>
ParsecT s st m (ListNumberStyle, Int)
defaultNum = do
forall (m :: * -> *) s u.
(Monad m, Stream s m Char, UpdateSourcePos s Char) =>
Char -> ParsecT s u m Char
char Char
'#'
forall (m :: * -> *) a. Monad m => a -> m a
return (ListNumberStyle
DefaultStyle, Int
1)
lowerAlpha :: (Stream s m Char, UpdateSourcePos s Char) => ParsecT s st m (ListNumberStyle, Int)
lowerAlpha :: forall s (m :: * -> *) st.
(Stream s m Char, UpdateSourcePos s Char) =>
ParsecT s st m (ListNumberStyle, Int)
lowerAlpha = do
Char
ch <- forall (m :: * -> *) s u.
(Monad m, Stream s m Char, UpdateSourcePos s Char) =>
(Char -> Bool) -> ParsecT s u m Char
satisfy Char -> Bool
isAsciiLower
forall (m :: * -> *) a. Monad m => a -> m a
return (ListNumberStyle
LowerAlpha, Char -> Int
ord Char
ch forall a. Num a => a -> a -> a
- Char -> Int
ord Char
'a' forall a. Num a => a -> a -> a
+ Int
1)
upperAlpha :: (Stream s m Char, UpdateSourcePos s Char) => ParsecT s st m (ListNumberStyle, Int)
upperAlpha :: forall s (m :: * -> *) st.
(Stream s m Char, UpdateSourcePos s Char) =>
ParsecT s st m (ListNumberStyle, Int)
upperAlpha = do
Char
ch <- forall (m :: * -> *) s u.
(Monad m, Stream s m Char, UpdateSourcePos s Char) =>
(Char -> Bool) -> ParsecT s u m Char
satisfy Char -> Bool
isAsciiUpper
forall (m :: * -> *) a. Monad m => a -> m a
return (ListNumberStyle
UpperAlpha, Char -> Int
ord Char
ch forall a. Num a => a -> a -> a
- Char -> Int
ord Char
'A' forall a. Num a => a -> a -> a
+ Int
1)
romanOne :: (Stream s m Char, UpdateSourcePos s Char) => ParsecT s st m (ListNumberStyle, Int)
romanOne :: forall s (m :: * -> *) st.
(Stream s m Char, UpdateSourcePos s Char) =>
ParsecT s st m (ListNumberStyle, Int)
romanOne = (forall (m :: * -> *) s u.
(Monad m, Stream s m Char, UpdateSourcePos s Char) =>
Char -> ParsecT s u m Char
char Char
'i' forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> forall (m :: * -> *) a. Monad m => a -> m a
return (ListNumberStyle
LowerRoman, Int
1)) forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|>
(forall (m :: * -> *) s u.
(Monad m, Stream s m Char, UpdateSourcePos s Char) =>
Char -> ParsecT s u m Char
char Char
'I' forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> forall (m :: * -> *) a. Monad m => a -> m a
return (ListNumberStyle
UpperRoman, Int
1))
anyOrderedListMarker :: (Stream s m Char, UpdateSourcePos s Char) => ParsecT s ParserState m ListAttributes
anyOrderedListMarker :: forall s (m :: * -> *).
(Stream s m Char, UpdateSourcePos s Char) =>
ParsecT s ParserState m ListAttributes
anyOrderedListMarker = forall s (m :: * -> *) t u a.
Stream s m t =>
[ParsecT s u m a] -> ParsecT s u m a
choice
[ParsecT s ParserState m (ListNumberStyle, Int)
-> ParsecT s ParserState m ListAttributes
delimParser ParsecT s ParserState m (ListNumberStyle, Int)
numParser | ParsecT s ParserState m (ListNumberStyle, Int)
-> ParsecT s ParserState m ListAttributes
delimParser <- [forall s (m :: * -> *) st.
(Stream s m Char, UpdateSourcePos s Char) =>
ParsecT s st m (ListNumberStyle, Int)
-> ParsecT s st m ListAttributes
inPeriod, forall s (m :: * -> *) st.
(Stream s m Char, UpdateSourcePos s Char) =>
ParsecT s st m (ListNumberStyle, Int)
-> ParsecT s st m ListAttributes
inOneParen, forall s (m :: * -> *) st.
(Stream s m Char, UpdateSourcePos s Char) =>
ParsecT s st m (ListNumberStyle, Int)
-> ParsecT s st m ListAttributes
inTwoParens],
ParsecT s ParserState m (ListNumberStyle, Int)
numParser <- [forall s (m :: * -> *) st.
(Stream s m Char, UpdateSourcePos s Char) =>
ParsecT s st m (ListNumberStyle, Int)
decimal, forall s (m :: * -> *).
(Stream s m Char, UpdateSourcePos s Char) =>
ParsecT s ParserState m (ListNumberStyle, Int)
exampleNum, forall s (m :: * -> *) st.
(Stream s m Char, UpdateSourcePos s Char) =>
ParsecT s st m (ListNumberStyle, Int)
defaultNum, forall s (m :: * -> *) st.
(Stream s m Char, UpdateSourcePos s Char) =>
ParsecT s st m (ListNumberStyle, Int)
romanOne,
forall s (m :: * -> *) st.
(Stream s m Char, UpdateSourcePos s Char) =>
ParsecT s st m (ListNumberStyle, Int)
lowerAlpha, forall s (m :: * -> *) st.
(Stream s m Char, UpdateSourcePos s Char) =>
ParsecT s st m (ListNumberStyle, Int)
lowerRoman, forall s (m :: * -> *) st.
(Stream s m Char, UpdateSourcePos s Char) =>
ParsecT s st m (ListNumberStyle, Int)
upperAlpha, forall s (m :: * -> *) st.
(Stream s m Char, UpdateSourcePos s Char) =>
ParsecT s st m (ListNumberStyle, Int)
upperRoman]]
inPeriod :: (Stream s m Char, UpdateSourcePos s Char)
=> ParsecT s st m (ListNumberStyle, Int)
-> ParsecT s st m ListAttributes
inPeriod :: forall s (m :: * -> *) st.
(Stream s m Char, UpdateSourcePos s Char) =>
ParsecT s st m (ListNumberStyle, Int)
-> ParsecT s st m ListAttributes
inPeriod ParsecT s st m (ListNumberStyle, Int)
num = forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try forall a b. (a -> b) -> a -> b
$ do
(ListNumberStyle
style, Int
start) <- ParsecT s st m (ListNumberStyle, Int)
num
forall (m :: * -> *) s u.
(Monad m, Stream s m Char, UpdateSourcePos s Char) =>
Char -> ParsecT s u m Char
char Char
'.'
let delim :: ListNumberDelim
delim = if ListNumberStyle
style forall a. Eq a => a -> a -> Bool
== ListNumberStyle
DefaultStyle
then ListNumberDelim
DefaultDelim
else ListNumberDelim
Period
forall (m :: * -> *) a. Monad m => a -> m a
return (Int
start, ListNumberStyle
style, ListNumberDelim
delim)
inOneParen :: (Stream s m Char, UpdateSourcePos s Char)
=> ParsecT s st m (ListNumberStyle, Int)
-> ParsecT s st m ListAttributes
inOneParen :: forall s (m :: * -> *) st.
(Stream s m Char, UpdateSourcePos s Char) =>
ParsecT s st m (ListNumberStyle, Int)
-> ParsecT s st m ListAttributes
inOneParen ParsecT s st m (ListNumberStyle, Int)
num = forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try forall a b. (a -> b) -> a -> b
$ do
(ListNumberStyle
style, Int
start) <- ParsecT s st m (ListNumberStyle, Int)
num
forall (m :: * -> *) s u.
(Monad m, Stream s m Char, UpdateSourcePos s Char) =>
Char -> ParsecT s u m Char
char Char
')'
forall (m :: * -> *) a. Monad m => a -> m a
return (Int
start, ListNumberStyle
style, ListNumberDelim
OneParen)
inTwoParens :: (Stream s m Char, UpdateSourcePos s Char)
=> ParsecT s st m (ListNumberStyle, Int)
-> ParsecT s st m ListAttributes
inTwoParens :: forall s (m :: * -> *) st.
(Stream s m Char, UpdateSourcePos s Char) =>
ParsecT s st m (ListNumberStyle, Int)
-> ParsecT s st m ListAttributes
inTwoParens ParsecT s st m (ListNumberStyle, Int)
num = forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try forall a b. (a -> b) -> a -> b
$ do
forall (m :: * -> *) s u.
(Monad m, Stream s m Char, UpdateSourcePos s Char) =>
Char -> ParsecT s u m Char
char Char
'('
(ListNumberStyle
style, Int
start) <- ParsecT s st m (ListNumberStyle, Int)
num
forall (m :: * -> *) s u.
(Monad m, Stream s m Char, UpdateSourcePos s Char) =>
Char -> ParsecT s u m Char
char Char
')'
forall (m :: * -> *) a. Monad m => a -> m a
return (Int
start, ListNumberStyle
style, ListNumberDelim
TwoParens)
orderedListMarker :: (Stream s m Char, UpdateSourcePos s Char)
=> ListNumberStyle
-> ListNumberDelim
-> ParsecT s ParserState m Int
orderedListMarker :: forall s (m :: * -> *).
(Stream s m Char, UpdateSourcePos s Char) =>
ListNumberStyle -> ListNumberDelim -> ParsecT s ParserState m Int
orderedListMarker ListNumberStyle
style ListNumberDelim
delim = do
let num :: ParsecT s ParserState m (ListNumberStyle, Int)
num = forall s (m :: * -> *) st.
(Stream s m Char, UpdateSourcePos s Char) =>
ParsecT s st m (ListNumberStyle, Int)
defaultNum forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|>
case ListNumberStyle
style of
ListNumberStyle
DefaultStyle -> forall s (m :: * -> *) st.
(Stream s m Char, UpdateSourcePos s Char) =>
ParsecT s st m (ListNumberStyle, Int)
decimal
ListNumberStyle
Example -> forall s (m :: * -> *).
(Stream s m Char, UpdateSourcePos s Char) =>
ParsecT s ParserState m (ListNumberStyle, Int)
exampleNum
ListNumberStyle
Decimal -> forall s (m :: * -> *) st.
(Stream s m Char, UpdateSourcePos s Char) =>
ParsecT s st m (ListNumberStyle, Int)
decimal
ListNumberStyle
UpperRoman -> forall s (m :: * -> *) st.
(Stream s m Char, UpdateSourcePos s Char) =>
ParsecT s st m (ListNumberStyle, Int)
upperRoman
ListNumberStyle
LowerRoman -> forall s (m :: * -> *) st.
(Stream s m Char, UpdateSourcePos s Char) =>
ParsecT s st m (ListNumberStyle, Int)
lowerRoman
ListNumberStyle
UpperAlpha -> forall s (m :: * -> *) st.
(Stream s m Char, UpdateSourcePos s Char) =>
ParsecT s st m (ListNumberStyle, Int)
upperAlpha
ListNumberStyle
LowerAlpha -> forall s (m :: * -> *) st.
(Stream s m Char, UpdateSourcePos s Char) =>
ParsecT s st m (ListNumberStyle, Int)
lowerAlpha
let context :: ParsecT s st m (ListNumberStyle, Int)
-> ParsecT s st m ListAttributes
context = case ListNumberDelim
delim of
ListNumberDelim
DefaultDelim -> forall s (m :: * -> *) st.
(Stream s m Char, UpdateSourcePos s Char) =>
ParsecT s st m (ListNumberStyle, Int)
-> ParsecT s st m ListAttributes
inPeriod
ListNumberDelim
Period -> forall s (m :: * -> *) st.
(Stream s m Char, UpdateSourcePos s Char) =>
ParsecT s st m (ListNumberStyle, Int)
-> ParsecT s st m ListAttributes
inPeriod
ListNumberDelim
OneParen -> forall s (m :: * -> *) st.
(Stream s m Char, UpdateSourcePos s Char) =>
ParsecT s st m (ListNumberStyle, Int)
-> ParsecT s st m ListAttributes
inOneParen
ListNumberDelim
TwoParens -> forall s (m :: * -> *) st.
(Stream s m Char, UpdateSourcePos s Char) =>
ParsecT s st m (ListNumberStyle, Int)
-> ParsecT s st m ListAttributes
inTwoParens
(Int
start, ListNumberStyle
_, ListNumberDelim
_) <- forall {st}.
ParsecT s st m (ListNumberStyle, Int)
-> ParsecT s st m ListAttributes
context ParsecT s ParserState m (ListNumberStyle, Int)
num
forall (m :: * -> *) a. Monad m => a -> m a
return Int
start