Text.Jira.Parser.Core

jira-wiki-markup-1.5.1: Handle Jira wiki markup

Copyright | © 2019–2023 Albert Krewinkel
License | MIT
Maintainer | Albert Krewinkel <tarleb@zeitkraut.de>
Stability | alpha
Portability | portable
Safe Haskell | Safe-Inferred
Language | Haskell2010

Text.Jira.Parser.Core

Contents

- Jira parser and state
- String position tracking
- Parsing helpers

Description

Core components of the Jira wiki markup parser.

Synopsis

- type JiraParser = Parsec Text ParserState
- data ParserState = ParserState {
  - stateInLink :: Bool
  - stateInList :: Bool
  - stateInMarkup :: Bool
  - stateInTable :: Bool
  - stateLastSpcPos :: Maybe SourcePos
  - stateLastStrPos :: Maybe SourcePos
  }
- defaultState :: ParserState
- parseJira :: JiraParser a -> Text -> Either ParseError a
- withStateFlag :: (Bool -> ParserState -> ParserState) -> JiraParser a -> JiraParser a
- updateLastStrPos :: JiraParser ()
- updateLastSpcPos :: JiraParser ()
- notAfterString :: JiraParser Bool
- afterString :: JiraParser Bool
- afterSpace :: JiraParser Bool
- endOfPara :: JiraParser ()
- notFollowedBy' :: Show a => JiraParser a -> JiraParser ()
- many1Till :: Show end => JiraParser a -> JiraParser end -> JiraParser [a]
- blankline :: JiraParser ()
- skipSpaces :: JiraParser ()
- blockNames :: [String]
- parameters :: JiraParser (Maybe Text, [Parameter])

# Jira parser and state

type JiraParser = Parsec Text ParserState #

Jira Parsec parser

data ParserState #

Parser state used to keep track of various parameteres.

Constructors

ParserState |
Fields stateInLink :: Bool whether the parser is within a link stateInList :: Bool whether the parser is within a list stateInMarkup :: Bool whether the parser is within markup stateInTable :: Bool whether the parser is within a table stateLastSpcPos :: Maybe SourcePos most recent space char position stateLastStrPos :: Maybe SourcePos position at which the last string ended

defaultState :: ParserState #

Default parser state (i.e., start state)

parseJira :: JiraParser a -> Text -> Either ParseError a #

Parses a string with the given Jira parser.

withStateFlag :: (Bool -> ParserState -> ParserState) -> JiraParser a -> JiraParser a #

Set a flag in the parser to `True` before running a parser, then set the flag's value to `False`.

# String position tracking

updateLastStrPos :: JiraParser () #

Updates the state, marking the current input position as the end of a string.

updateLastSpcPos :: JiraParser () #

Updates the state, marking the current input position as the end of a string.

notAfterString :: JiraParser Bool #

Returns true when the current parser position is either at the beginning of the document or if the preceding characters did not belong to a string.

afterString :: JiraParser Bool #

Returns ``True`` if the current parser position is directly after a word/string. Returns ``False`` if the parser is looking at the first character of the input.

afterSpace :: JiraParser Bool #

Returns ``True`` iff the character before the current parser position was a space.

# Parsing helpers

endOfPara :: JiraParser () #

Succeeds if the parser is looking at the end of a paragraph.

notFollowedBy' :: Show a => JiraParser a -> JiraParser () #

Variant of parsec's `notFollowedBy` function which properly fails even if the given parser does not consume any input (like `eof` does).

many1Till :: Show end => JiraParser a -> JiraParser end -> JiraParser [a] #

Like `manyTill`, but reads at least one item.

blankline :: JiraParser () #

Parses an empty line, i.e., a line with no chars or whitespace only.

skipSpaces :: JiraParser () #

Skip zero or more space chars.

blockNames :: [String] #

parameters :: JiraParser (Maybe Text, [Parameter]) #

Parses a set of panel parameters