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
, insertIncludedFileF
, 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
, getPosition
) where
import Data.Text (Text)
import Text.Pandoc.Readers.Org.ParserState
import Text.Pandoc.Parsing hiding (F, anyLine, blanklines, newline,
parseFromString)
import qualified Text.Pandoc.Parsing as P
import Control.Monad (guard)
import Control.Monad.Reader (ReaderT)
type OrgParser m = ParserT Text OrgParserState (ReaderT OrgParserLocal m)
anyLine :: Monad m => OrgParser m Text
anyLine =
P.anyLine
<* updateLastPreCharPos
<* updateLastForbiddenCharPos
parseFromString :: Monad m => OrgParser m a -> Text -> OrgParser m a
parseFromString parser str' = do
updateState $ \s -> s{ orgStateLastPreCharPos = Nothing }
result <- P.parseFromString parser str'
updateState $ \s -> s { orgStateLastPreCharPos = Nothing }
return result
skipSpaces1 :: Monad m => OrgParser m ()
skipSpaces1 = skipMany1 spaceChar
newline :: Monad m => OrgParser m Char
newline =
P.newline
<* updateLastPreCharPos
<* updateLastForbiddenCharPos
blanklines :: Monad m => OrgParser m Text
blanklines =
P.blanklines
<* updateLastPreCharPos
<* updateLastForbiddenCharPos
inList :: Monad m => OrgParser m ()
inList = do
ctx <- orgStateParserContext <$> getState
guard (ctx == ListItemState)
withContext :: Monad m
=> ParserContext
-> OrgParser m a
-> OrgParser m a
withContext context parser = do
oldContext <- orgStateParserContext <$> getState
updateState $ \s -> s{ orgStateParserContext = context }
result <- parser
updateState $ \s -> s{ orgStateParserContext = oldContext }
return result
getExportSetting :: Monad m => (ExportSettings -> a) -> OrgParser m a
getExportSetting s = s . orgStateExportSettings <$> getState
updateLastForbiddenCharPos :: Monad m => OrgParser m ()
updateLastForbiddenCharPos = getPosition >>= \p ->
updateState $ \s -> s{ orgStateLastForbiddenCharPos = Just p}
updateLastPreCharPos :: Monad m => OrgParser m ()
updateLastPreCharPos = getPosition >>= \p ->
updateState $ \s -> s{ orgStateLastPreCharPos = Just p}
orgArgKey :: Monad m => OrgParser m Text
orgArgKey = try $
skipSpaces *> char ':'
*> many1Char orgArgWordChar
orgArgWord :: Monad m => OrgParser m Text
orgArgWord = many1Char orgArgWordChar
orgArgWordChar :: Monad m => OrgParser m Char
orgArgWordChar = alphaNum <|> oneOf "-_"
orgTagWord :: Monad m => OrgParser m Text
orgTagWord = many1Char orgTagWordChar
orgTagWordChar :: Monad m => OrgParser m Char
orgTagWordChar = alphaNum <|> oneOf "@%#_"