module Text.Pandoc.Readers.Org.Parsing
( OrgParser
, anyLine
, anyLineNewline
, indentWith
, blanklines
, newline
, parseFromString
, skipSpaces1
, inList
, withContext
, getExportSetting
, updateLastForbiddenCharPos
, updateLastPreCharPos
, orgArgKey
, orgArgWord
, orgArgWordChar
, orgTagWord
, orgTagWordChar
, ParserContext (..)
, textStr
, countChar
, manyChar
, many1Char
, manyTillChar
, many1Till
, many1TillChar
, notFollowedBy'
, spaceChar
, nonspaceChar
, skipSpaces
, blankline
, enclosed
, stringAnyCase
, charsInBalanced
, uri
, withRaw
, readWithM
, guardEnabled
, updateLastStrPos
, notAfterString
, ParserState (..)
, registerHeader
, QuoteContext (..)
, singleQuoteStart
, singleQuoteEnd
, doubleQuoteStart
, doubleQuoteEnd
, dash
, ellipses
, citeKey
, gridTableWith
, insertIncludedFile
, runParser
, runParserT
, getInput
, char
, letter
, digit
, alphaNum
, skipMany1
, spaces
, anyChar
, satisfy
, string
, count
, eof
, noneOf
, oneOf
, lookAhead
, notFollowedBy
, many
, many1
, manyTill
, (<|>)
, (<?>)
, choice
, try
, sepBy
, sepBy1
, sepEndBy1
, endBy1
, option
, optional
, optionMaybe
, getState
, updateState
, SourcePos
, sourceName
, getPosition
) where
import Data.Text (Text)
import Text.Pandoc.Readers.Org.ParserState
import Text.Pandoc.Parsing hiding (anyLine, blanklines, newline,
parseFromString)
import qualified Text.Pandoc.Parsing as P
import Control.Monad (guard)
import Control.Monad.Reader (ReaderT)
type OrgParser m = ParsecT Sources OrgParserState (ReaderT OrgParserLocal m)
anyLine :: Monad m => OrgParser m Text
anyLine :: forall (m :: * -> *). Monad m => OrgParser m Text
anyLine =
ParsecT Sources OrgParserState (ReaderT OrgParserLocal m) Text
forall (m :: * -> *) st. Monad m => ParsecT Sources st m Text
P.anyLine
ParsecT Sources OrgParserState (ReaderT OrgParserLocal m) Text
-> ParsecT Sources OrgParserState (ReaderT OrgParserLocal m) ()
-> ParsecT Sources OrgParserState (ReaderT OrgParserLocal m) Text
forall a b.
ParsecT Sources OrgParserState (ReaderT OrgParserLocal m) a
-> ParsecT Sources OrgParserState (ReaderT OrgParserLocal m) b
-> ParsecT Sources OrgParserState (ReaderT OrgParserLocal m) a
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f a
<* ParsecT Sources OrgParserState (ReaderT OrgParserLocal m) ()
forall (m :: * -> *). Monad m => OrgParser m ()
updateLastPreCharPos
ParsecT Sources OrgParserState (ReaderT OrgParserLocal m) Text
-> ParsecT Sources OrgParserState (ReaderT OrgParserLocal m) ()
-> ParsecT Sources OrgParserState (ReaderT OrgParserLocal m) Text
forall a b.
ParsecT Sources OrgParserState (ReaderT OrgParserLocal m) a
-> ParsecT Sources OrgParserState (ReaderT OrgParserLocal m) b
-> ParsecT Sources OrgParserState (ReaderT OrgParserLocal m) a
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f a
<* ParsecT Sources OrgParserState (ReaderT OrgParserLocal m) ()
forall (m :: * -> *). Monad m => OrgParser m ()
updateLastForbiddenCharPos
parseFromString :: Monad m => OrgParser m a -> Text -> OrgParser m a
parseFromString :: forall (m :: * -> *) a.
Monad m =>
OrgParser m a -> Text -> OrgParser m a
parseFromString OrgParser m a
parser Text
str' = do
(OrgParserState -> OrgParserState)
-> ParsecT Sources OrgParserState (ReaderT OrgParserLocal m) ()
forall (m :: * -> *) u s. Monad m => (u -> u) -> ParsecT s u m ()
updateState ((OrgParserState -> OrgParserState)
-> ParsecT Sources OrgParserState (ReaderT OrgParserLocal m) ())
-> (OrgParserState -> OrgParserState)
-> ParsecT Sources OrgParserState (ReaderT OrgParserLocal m) ()
forall a b. (a -> b) -> a -> b
$ \OrgParserState
s -> OrgParserState
s{ orgStateLastPreCharPos :: Maybe SourcePos
orgStateLastPreCharPos = Maybe SourcePos
forall a. Maybe a
Nothing }
a
result <- OrgParser m a -> Text -> OrgParser m a
forall (m :: * -> *) st r.
Monad m =>
ParsecT Sources st m r -> Text -> ParsecT Sources st m r
P.parseFromString OrgParser m a
parser Text
str'
(OrgParserState -> OrgParserState)
-> ParsecT Sources OrgParserState (ReaderT OrgParserLocal m) ()
forall (m :: * -> *) u s. Monad m => (u -> u) -> ParsecT s u m ()
updateState ((OrgParserState -> OrgParserState)
-> ParsecT Sources OrgParserState (ReaderT OrgParserLocal m) ())
-> (OrgParserState -> OrgParserState)
-> ParsecT Sources OrgParserState (ReaderT OrgParserLocal m) ()
forall a b. (a -> b) -> a -> b
$ \OrgParserState
s -> OrgParserState
s { orgStateLastPreCharPos :: Maybe SourcePos
orgStateLastPreCharPos = Maybe SourcePos
forall a. Maybe a
Nothing }
a -> OrgParser m a
forall a.
a -> ParsecT Sources OrgParserState (ReaderT OrgParserLocal m) a
forall (m :: * -> *) a. Monad m => a -> m a
return a
result
skipSpaces1 :: Monad m => OrgParser m ()
skipSpaces1 :: forall (m :: * -> *). Monad m => OrgParser m ()
skipSpaces1 = ParsecT Sources OrgParserState (ReaderT OrgParserLocal m) Char
-> ParsecT Sources OrgParserState (ReaderT OrgParserLocal m) ()
forall s (m :: * -> *) t u a.
Stream s m t =>
ParsecT s u m a -> ParsecT s u m ()
skipMany1 ParsecT Sources OrgParserState (ReaderT OrgParserLocal m) Char
forall s (m :: * -> *) st.
(Stream s m Char, UpdateSourcePos s Char) =>
ParsecT s st m Char
spaceChar
newline :: Monad m => OrgParser m Char
newline :: forall (m :: * -> *). Monad m => OrgParser m Char
newline =
ParsecT Sources OrgParserState (ReaderT OrgParserLocal m) Char
forall (m :: * -> *) s u.
(Monad m, Stream s m Char, UpdateSourcePos s Char) =>
ParsecT s u m Char
P.newline
ParsecT Sources OrgParserState (ReaderT OrgParserLocal m) Char
-> ParsecT Sources OrgParserState (ReaderT OrgParserLocal m) ()
-> ParsecT Sources OrgParserState (ReaderT OrgParserLocal m) Char
forall a b.
ParsecT Sources OrgParserState (ReaderT OrgParserLocal m) a
-> ParsecT Sources OrgParserState (ReaderT OrgParserLocal m) b
-> ParsecT Sources OrgParserState (ReaderT OrgParserLocal m) a
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f a
<* ParsecT Sources OrgParserState (ReaderT OrgParserLocal m) ()
forall (m :: * -> *). Monad m => OrgParser m ()
updateLastPreCharPos
ParsecT Sources OrgParserState (ReaderT OrgParserLocal m) Char
-> ParsecT Sources OrgParserState (ReaderT OrgParserLocal m) ()
-> ParsecT Sources OrgParserState (ReaderT OrgParserLocal m) Char
forall a b.
ParsecT Sources OrgParserState (ReaderT OrgParserLocal m) a
-> ParsecT Sources OrgParserState (ReaderT OrgParserLocal m) b
-> ParsecT Sources OrgParserState (ReaderT OrgParserLocal m) a
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f a
<* ParsecT Sources OrgParserState (ReaderT OrgParserLocal m) ()
forall (m :: * -> *). Monad m => OrgParser m ()
updateLastForbiddenCharPos
blanklines :: Monad m => OrgParser m Text
blanklines :: forall (m :: * -> *). Monad m => OrgParser m Text
blanklines =
ParsecT Sources OrgParserState (ReaderT OrgParserLocal m) Text
forall s (m :: * -> *) st.
(Stream s m Char, UpdateSourcePos s Char) =>
ParsecT s st m Text
P.blanklines
ParsecT Sources OrgParserState (ReaderT OrgParserLocal m) Text
-> ParsecT Sources OrgParserState (ReaderT OrgParserLocal m) ()
-> ParsecT Sources OrgParserState (ReaderT OrgParserLocal m) Text
forall a b.
ParsecT Sources OrgParserState (ReaderT OrgParserLocal m) a
-> ParsecT Sources OrgParserState (ReaderT OrgParserLocal m) b
-> ParsecT Sources OrgParserState (ReaderT OrgParserLocal m) a
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f a
<* ParsecT Sources OrgParserState (ReaderT OrgParserLocal m) ()
forall (m :: * -> *). Monad m => OrgParser m ()
updateLastPreCharPos
ParsecT Sources OrgParserState (ReaderT OrgParserLocal m) Text
-> ParsecT Sources OrgParserState (ReaderT OrgParserLocal m) ()
-> ParsecT Sources OrgParserState (ReaderT OrgParserLocal m) Text
forall a b.
ParsecT Sources OrgParserState (ReaderT OrgParserLocal m) a
-> ParsecT Sources OrgParserState (ReaderT OrgParserLocal m) b
-> ParsecT Sources OrgParserState (ReaderT OrgParserLocal m) a
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f a
<* ParsecT Sources OrgParserState (ReaderT OrgParserLocal m) ()
forall (m :: * -> *). Monad m => OrgParser m ()
updateLastForbiddenCharPos
inList :: Monad m => OrgParser m ()
inList :: forall (m :: * -> *). Monad m => OrgParser m ()
inList = do
ParserContext
ctx <- OrgParserState -> ParserContext
orgStateParserContext (OrgParserState -> ParserContext)
-> ParsecT
Sources OrgParserState (ReaderT OrgParserLocal m) OrgParserState
-> ParsecT
Sources OrgParserState (ReaderT OrgParserLocal m) ParserContext
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> ParsecT
Sources OrgParserState (ReaderT OrgParserLocal m) OrgParserState
forall (m :: * -> *) s u. Monad m => ParsecT s u m u
getState
Bool -> OrgParser m ()
forall (f :: * -> *). Alternative f => Bool -> f ()
guard (ParserContext
ctx ParserContext -> ParserContext -> Bool
forall a. Eq a => a -> a -> Bool
== ParserContext
ListItemState)
withContext :: Monad m
=> ParserContext
-> OrgParser m a
-> OrgParser m a
withContext :: forall (m :: * -> *) a.
Monad m =>
ParserContext -> OrgParser m a -> OrgParser m a
withContext ParserContext
context OrgParser m a
parser = do
ParserContext
oldContext <- OrgParserState -> ParserContext
orgStateParserContext (OrgParserState -> ParserContext)
-> ParsecT
Sources OrgParserState (ReaderT OrgParserLocal m) OrgParserState
-> ParsecT
Sources OrgParserState (ReaderT OrgParserLocal m) ParserContext
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> ParsecT
Sources OrgParserState (ReaderT OrgParserLocal m) OrgParserState
forall (m :: * -> *) s u. Monad m => ParsecT s u m u
getState
(OrgParserState -> OrgParserState)
-> ParsecT Sources OrgParserState (ReaderT OrgParserLocal m) ()
forall (m :: * -> *) u s. Monad m => (u -> u) -> ParsecT s u m ()
updateState ((OrgParserState -> OrgParserState)
-> ParsecT Sources OrgParserState (ReaderT OrgParserLocal m) ())
-> (OrgParserState -> OrgParserState)
-> ParsecT Sources OrgParserState (ReaderT OrgParserLocal m) ()
forall a b. (a -> b) -> a -> b
$ \OrgParserState
s -> OrgParserState
s{ orgStateParserContext :: ParserContext
orgStateParserContext = ParserContext
context }
a
result <- OrgParser m a
parser
(OrgParserState -> OrgParserState)
-> ParsecT Sources OrgParserState (ReaderT OrgParserLocal m) ()
forall (m :: * -> *) u s. Monad m => (u -> u) -> ParsecT s u m ()
updateState ((OrgParserState -> OrgParserState)
-> ParsecT Sources OrgParserState (ReaderT OrgParserLocal m) ())
-> (OrgParserState -> OrgParserState)
-> ParsecT Sources OrgParserState (ReaderT OrgParserLocal m) ()
forall a b. (a -> b) -> a -> b
$ \OrgParserState
s -> OrgParserState
s{ orgStateParserContext :: ParserContext
orgStateParserContext = ParserContext
oldContext }
a -> OrgParser m a
forall a.
a -> ParsecT Sources OrgParserState (ReaderT OrgParserLocal m) a
forall (m :: * -> *) a. Monad m => a -> m a
return a
result
getExportSetting :: Monad m => (ExportSettings -> a) -> OrgParser m a
getExportSetting :: forall (m :: * -> *) a.
Monad m =>
(ExportSettings -> a) -> OrgParser m a
getExportSetting ExportSettings -> a
s = ExportSettings -> a
s (ExportSettings -> a)
-> (OrgParserState -> ExportSettings) -> OrgParserState -> a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. OrgParserState -> ExportSettings
orgStateExportSettings (OrgParserState -> a)
-> ParsecT
Sources OrgParserState (ReaderT OrgParserLocal m) OrgParserState
-> ParsecT Sources OrgParserState (ReaderT OrgParserLocal m) a
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> ParsecT
Sources OrgParserState (ReaderT OrgParserLocal m) OrgParserState
forall (m :: * -> *) s u. Monad m => ParsecT s u m u
getState
updateLastForbiddenCharPos :: Monad m => OrgParser m ()
updateLastForbiddenCharPos :: forall (m :: * -> *). Monad m => OrgParser m ()
updateLastForbiddenCharPos = ParsecT Sources OrgParserState (ReaderT OrgParserLocal m) SourcePos
forall (m :: * -> *) s u. Monad m => ParsecT s u m SourcePos
getPosition ParsecT Sources OrgParserState (ReaderT OrgParserLocal m) SourcePos
-> (SourcePos
-> ParsecT Sources OrgParserState (ReaderT OrgParserLocal m) ())
-> ParsecT Sources OrgParserState (ReaderT OrgParserLocal m) ()
forall a b.
ParsecT Sources OrgParserState (ReaderT OrgParserLocal m) a
-> (a
-> ParsecT Sources OrgParserState (ReaderT OrgParserLocal m) b)
-> ParsecT Sources OrgParserState (ReaderT OrgParserLocal m) b
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= \SourcePos
p ->
(OrgParserState -> OrgParserState)
-> ParsecT Sources OrgParserState (ReaderT OrgParserLocal m) ()
forall (m :: * -> *) u s. Monad m => (u -> u) -> ParsecT s u m ()
updateState ((OrgParserState -> OrgParserState)
-> ParsecT Sources OrgParserState (ReaderT OrgParserLocal m) ())
-> (OrgParserState -> OrgParserState)
-> ParsecT Sources OrgParserState (ReaderT OrgParserLocal m) ()
forall a b. (a -> b) -> a -> b
$ \OrgParserState
s -> OrgParserState
s{ orgStateLastForbiddenCharPos :: Maybe SourcePos
orgStateLastForbiddenCharPos = SourcePos -> Maybe SourcePos
forall a. a -> Maybe a
Just SourcePos
p}
updateLastPreCharPos :: Monad m => OrgParser m ()
updateLastPreCharPos :: forall (m :: * -> *). Monad m => OrgParser m ()
updateLastPreCharPos = ParsecT Sources OrgParserState (ReaderT OrgParserLocal m) SourcePos
forall (m :: * -> *) s u. Monad m => ParsecT s u m SourcePos
getPosition ParsecT Sources OrgParserState (ReaderT OrgParserLocal m) SourcePos
-> (SourcePos
-> ParsecT Sources OrgParserState (ReaderT OrgParserLocal m) ())
-> ParsecT Sources OrgParserState (ReaderT OrgParserLocal m) ()
forall a b.
ParsecT Sources OrgParserState (ReaderT OrgParserLocal m) a
-> (a
-> ParsecT Sources OrgParserState (ReaderT OrgParserLocal m) b)
-> ParsecT Sources OrgParserState (ReaderT OrgParserLocal m) b
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= \SourcePos
p ->
(OrgParserState -> OrgParserState)
-> ParsecT Sources OrgParserState (ReaderT OrgParserLocal m) ()
forall (m :: * -> *) u s. Monad m => (u -> u) -> ParsecT s u m ()
updateState ((OrgParserState -> OrgParserState)
-> ParsecT Sources OrgParserState (ReaderT OrgParserLocal m) ())
-> (OrgParserState -> OrgParserState)
-> ParsecT Sources OrgParserState (ReaderT OrgParserLocal m) ()
forall a b. (a -> b) -> a -> b
$ \OrgParserState
s -> OrgParserState
s{ orgStateLastPreCharPos :: Maybe SourcePos
orgStateLastPreCharPos = SourcePos -> Maybe SourcePos
forall a. a -> Maybe a
Just SourcePos
p}
orgArgKey :: Monad m => OrgParser m Text
orgArgKey :: forall (m :: * -> *). Monad m => OrgParser m Text
orgArgKey = ParsecT Sources OrgParserState (ReaderT OrgParserLocal m) Text
-> ParsecT Sources OrgParserState (ReaderT OrgParserLocal m) Text
forall s u (m :: * -> *) a. ParsecT s u m a -> ParsecT s u m a
try (ParsecT Sources OrgParserState (ReaderT OrgParserLocal m) Text
-> ParsecT Sources OrgParserState (ReaderT OrgParserLocal m) Text)
-> ParsecT Sources OrgParserState (ReaderT OrgParserLocal m) Text
-> ParsecT Sources OrgParserState (ReaderT OrgParserLocal m) Text
forall a b. (a -> b) -> a -> b
$
ParsecT Sources OrgParserState (ReaderT OrgParserLocal m) ()
forall s (m :: * -> *) st.
(Stream s m Char, UpdateSourcePos s Char) =>
ParsecT s st m ()
skipSpaces ParsecT Sources OrgParserState (ReaderT OrgParserLocal m) ()
-> ParsecT Sources OrgParserState (ReaderT OrgParserLocal m) Char
-> ParsecT Sources OrgParserState (ReaderT OrgParserLocal m) Char
forall a b.
ParsecT Sources OrgParserState (ReaderT OrgParserLocal m) a
-> ParsecT Sources OrgParserState (ReaderT OrgParserLocal m) b
-> ParsecT Sources OrgParserState (ReaderT OrgParserLocal m) b
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> Char
-> ParsecT Sources OrgParserState (ReaderT OrgParserLocal m) Char
forall (m :: * -> *) s u.
(Monad m, Stream s m Char, UpdateSourcePos s Char) =>
Char -> ParsecT s u m Char
char Char
':'
ParsecT Sources OrgParserState (ReaderT OrgParserLocal m) Char
-> ParsecT Sources OrgParserState (ReaderT OrgParserLocal m) Text
-> ParsecT Sources OrgParserState (ReaderT OrgParserLocal m) Text
forall a b.
ParsecT Sources OrgParserState (ReaderT OrgParserLocal m) a
-> ParsecT Sources OrgParserState (ReaderT OrgParserLocal m) b
-> ParsecT Sources OrgParserState (ReaderT OrgParserLocal m) b
forall (f :: * -> *) a b. Applicative f => f a -> f b -> f b
*> ParsecT Sources OrgParserState (ReaderT OrgParserLocal m) Char
-> ParsecT Sources OrgParserState (ReaderT OrgParserLocal m) Text
forall s (m :: * -> *) t st.
Stream s m t =>
ParsecT s st m Char -> ParsecT s st m Text
many1Char ParsecT Sources OrgParserState (ReaderT OrgParserLocal m) Char
forall (m :: * -> *). Monad m => OrgParser m Char
orgArgWordChar
orgArgWord :: Monad m => OrgParser m Text
orgArgWord :: forall (m :: * -> *). Monad m => OrgParser m Text
orgArgWord = ParsecT Sources OrgParserState (ReaderT OrgParserLocal m) Char
-> ParsecT Sources OrgParserState (ReaderT OrgParserLocal m) Text
forall s (m :: * -> *) t st.
Stream s m t =>
ParsecT s st m Char -> ParsecT s st m Text
many1Char ParsecT Sources OrgParserState (ReaderT OrgParserLocal m) Char
forall (m :: * -> *). Monad m => OrgParser m Char
orgArgWordChar
orgArgWordChar :: Monad m => OrgParser m Char
orgArgWordChar :: forall (m :: * -> *). Monad m => OrgParser m Char
orgArgWordChar = ParsecT Sources OrgParserState (ReaderT OrgParserLocal m) Char
forall (m :: * -> *) s u.
(Monad m, Stream s m Char, UpdateSourcePos s Char) =>
ParsecT s u m Char
alphaNum ParsecT Sources OrgParserState (ReaderT OrgParserLocal m) Char
-> ParsecT Sources OrgParserState (ReaderT OrgParserLocal m) Char
-> ParsecT Sources OrgParserState (ReaderT OrgParserLocal m) Char
forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|> [Char]
-> ParsecT Sources OrgParserState (ReaderT OrgParserLocal m) Char
forall (m :: * -> *) s u.
(Monad m, Stream s m Char, UpdateSourcePos s Char) =>
[Char] -> ParsecT s u m Char
oneOf [Char]
"-_"
orgTagWord :: Monad m => OrgParser m Text
orgTagWord :: forall (m :: * -> *). Monad m => OrgParser m Text
orgTagWord = ParsecT Sources OrgParserState (ReaderT OrgParserLocal m) Char
-> ParsecT Sources OrgParserState (ReaderT OrgParserLocal m) Text
forall s (m :: * -> *) t st.
Stream s m t =>
ParsecT s st m Char -> ParsecT s st m Text
many1Char ParsecT Sources OrgParserState (ReaderT OrgParserLocal m) Char
forall (m :: * -> *). Monad m => OrgParser m Char
orgTagWordChar
orgTagWordChar :: Monad m => OrgParser m Char
orgTagWordChar :: forall (m :: * -> *). Monad m => OrgParser m Char
orgTagWordChar = ParsecT Sources OrgParserState (ReaderT OrgParserLocal m) Char
forall (m :: * -> *) s u.
(Monad m, Stream s m Char, UpdateSourcePos s Char) =>
ParsecT s u m Char
alphaNum ParsecT Sources OrgParserState (ReaderT OrgParserLocal m) Char
-> ParsecT Sources OrgParserState (ReaderT OrgParserLocal m) Char
-> ParsecT Sources OrgParserState (ReaderT OrgParserLocal m) Char
forall s u (m :: * -> *) a.
ParsecT s u m a -> ParsecT s u m a -> ParsecT s u m a
<|> [Char]
-> ParsecT Sources OrgParserState (ReaderT OrgParserLocal m) Char
forall (m :: * -> *) s u.
(Monad m, Stream s m Char, UpdateSourcePos s Char) =>
[Char] -> ParsecT s u m Char
oneOf [Char]
"@%#_"