Copyright | (c) Ogma Project 2016 |
---|---|
License | MIT |
Stability | experimental |
Safe Haskell | None |
Language | Haskell2010 |
This module provides several parsers that can be used in order to
extract the Ast
of an Ogmarkup document.
Please consider that only document
should be used outside this
module.
- data ParserState = ParserState {}
- type OgmarkupParser a = StateT ParserState (Parsec Void a)
- enterEmph :: Stream a => OgmarkupParser a ()
- leaveEmph :: Stream a => OgmarkupParser a ()
- enterStrongEmph :: Stream a => OgmarkupParser a ()
- leaveStrongEmph :: Stream a => OgmarkupParser a ()
- enterQuote :: Stream a => OgmarkupParser a ()
- leaveQuote :: Stream a => OgmarkupParser a ()
- initParserState :: ParserState
- parse :: Stream a => OgmarkupParser a b -> String -> a -> Either (ParseError (Token a) Void) b
- document :: (Stream a, Token a ~ Char, IsString (Tokens a), IsString b) => OgmarkupParser a (Document b)
- section :: (Stream a, Token a ~ Char, IsString b) => OgmarkupParser a (Section b)
- aside :: (Stream a, Token a ~ Char, IsString b) => OgmarkupParser a (Section b)
- story :: (Stream a, Token a ~ Char, IsString b) => OgmarkupParser a (Section b)
- paragraph :: (Stream a, Token a ~ Char, IsString b) => OgmarkupParser a (Paragraph b)
- component :: (Stream a, Token a ~ Char, IsString b) => OgmarkupParser a (Component b)
- illformed :: (Stream a, Token a ~ Char, IsString b) => OgmarkupParser a (Component b)
- restOfParagraph :: (Stream a, Token a ~ Char, IsString b) => OgmarkupParser a b
- teller :: (Stream a, Token a ~ Char, IsString b) => OgmarkupParser a (Component b)
- dialogue :: (Stream a, Token a ~ Char, IsString b) => OgmarkupParser a (Component b)
- thought :: (Stream a, Token a ~ Char, IsString b) => OgmarkupParser a (Component b)
- talk :: (Stream a, Token a ~ Char, IsString b) => Char -> Char -> (Reply b -> Maybe b -> Component b) -> OgmarkupParser a (Component b)
- characterName :: (Stream a, Token a ~ Char, IsString b) => OgmarkupParser a b
- reply :: (Stream a, Token a ~ Char, IsString b) => Char -> Char -> OgmarkupParser a (Reply b)
- format :: (Stream a, Token a ~ Char, IsString b) => OgmarkupParser a (Format b)
- raw :: (Stream a, Token a ~ Char, IsString b) => OgmarkupParser a (Format b)
- emph :: (Stream a, Token a ~ Char, IsString b) => OgmarkupParser a (Format b)
- strongEmph :: (Stream a, Token a ~ Char, IsString b) => OgmarkupParser a (Format b)
- quote :: (Stream a, Token a ~ Char, IsString b) => OgmarkupParser a (Format b)
- atom :: (Stream a, Token a ~ Char, IsString b) => OgmarkupParser a (Atom b)
- word :: (Stream a, Token a ~ Char, IsString b) => OgmarkupParser a (Atom b)
- longword :: (Stream a, Token a ~ Char, IsString b) => OgmarkupParser a (Atom b)
- mark :: (Stream a, Token a ~ Char) => OgmarkupParser a (Atom b)
- openQuote :: (Stream a, Token a ~ Char) => OgmarkupParser a ()
- closeQuote :: (Stream a, Token a ~ Char) => OgmarkupParser a ()
- asideSeparator :: (Stream a, Token a ~ Char) => OgmarkupParser a ()
- endOfParagraph :: (Stream a, Token a ~ Char) => OgmarkupParser a ()
- blank :: (Stream a, Token a ~ Char) => OgmarkupParser a ()
- skip :: Stream a => OgmarkupParser a b -> OgmarkupParser a ()
Documentation
data ParserState Source #
Keep track of the currently opened formats.
ParserState | |
|
type OgmarkupParser a = StateT ParserState (Parsec Void a) Source #
An ogmarkup parser processes Char
tokens and carries a ParserState
.
enterEmph :: Stream a => OgmarkupParser a () Source #
Update the ParserState
to guard against nested emphasis.
leaveEmph :: Stream a => OgmarkupParser a () Source #
Update the ParserState
to be able to parse input with emphasis
again.
enterStrongEmph :: Stream a => OgmarkupParser a () Source #
Update the ParserState
to guard against nested strong emphasis.
leaveStrongEmph :: Stream a => OgmarkupParser a () Source #
Update the ParserState
to be able to parse input with strong emphasis
again.
enterQuote :: Stream a => OgmarkupParser a () Source #
Update the ParserState
to guard against nested quoted inputs.
leaveQuote :: Stream a => OgmarkupParser a () Source #
Update the ParserState
to be able to parse an input
surrounded by quotes again.
initParserState :: ParserState Source #
A initial ParserState instance to be used at the begining of a document parsing.
parse :: Stream a => OgmarkupParser a b -> String -> a -> Either (ParseError (Token a) Void) b Source #
A wrapper around the runParser
function of Megaparsec. It uses
initParserState
as an initial state.
document :: (Stream a, Token a ~ Char, IsString (Tokens a), IsString b) => OgmarkupParser a (Document b) Source #
Try its best to parse an ogmarkup document. When it encounters an error, it returns an Ast and the remaining input.
See Document
.
section :: (Stream a, Token a ~ Char, IsString b) => OgmarkupParser a (Section b) Source #
See Section
.
paragraph :: (Stream a, Token a ~ Char, IsString b) => OgmarkupParser a (Paragraph b) Source #
See Paragraph
.
component :: (Stream a, Token a ~ Char, IsString b) => OgmarkupParser a (Component b) Source #
See Component
.
illformed :: (Stream a, Token a ~ Char, IsString b) => OgmarkupParser a (Component b) Source #
See IllFormed
.
restOfParagraph :: (Stream a, Token a ~ Char, IsString b) => OgmarkupParser a b Source #
Parse the rest of the current paragraph with no regards for the ogmarkup syntax. This Parser is used when the document is ill-formed, to find a new point of synchronization.
teller :: (Stream a, Token a ~ Char, IsString b) => OgmarkupParser a (Component b) Source #
See Teller
.
dialogue :: (Stream a, Token a ~ Char, IsString b) => OgmarkupParser a (Component b) Source #
See Dialogue
.
thought :: (Stream a, Token a ~ Char, IsString b) => OgmarkupParser a (Component b) Source #
See Thought
.
characterName :: (Stream a, Token a ~ Char, IsString b) => OgmarkupParser a b Source #
Parse the name of the character which speaks or thinks. According to the ogmarkup syntax, it is surrounded by parentheses.
reply :: (Stream a, Token a ~ Char, IsString b) => Char -> Char -> OgmarkupParser a (Reply b) Source #
strongEmph :: (Stream a, Token a ~ Char, IsString b) => OgmarkupParser a (Format b) Source #
See StrongEmph
.
word :: (Stream a, Token a ~ Char, IsString b) => OgmarkupParser a (Atom b) Source #
See Word
. This parser does not consume the following spaces, so
the caller needs to take care of it.
longword :: (Stream a, Token a ~ Char, IsString b) => OgmarkupParser a (Atom b) Source #
Wrap a raw string surrounded by `
inside a Word
.
>>>
parse longword "" "`test *ei*`"
Right (Ast.Word "test *ei*")
Therefore, `
can be used to insert normally reserved symbol
inside a generated document.
mark :: (Stream a, Token a ~ Char) => OgmarkupParser a (Atom b) Source #
See Punctuation
. Be aware that mark
does not parse the quotes
because they are processed quote
.
closeQuote :: (Stream a, Token a ~ Char) => OgmarkupParser a () Source #
See CloseQuote
. This parser consumes the following blank (see blank
)
and skip the result.
asideSeparator :: (Stream a, Token a ~ Char) => OgmarkupParser a () Source #
An aside section (see Aside
) is a particular region
surrounded by two lines of underscores (at least three).
This parser consumes one such line.
endOfParagraph :: (Stream a, Token a ~ Char) => OgmarkupParser a () Source #
The end of a paragraph is the end of the document or two blank lines or an aside separator, that is a line of underscores.
blank :: (Stream a, Token a ~ Char) => OgmarkupParser a () Source #
This parser consumes all the white spaces until it finds either an aside
surrounding marker (see Aside
), the end of the document or
one blank line. The latter marks the end of the current paragraph.
skip :: Stream a => OgmarkupParser a b -> OgmarkupParser a () Source #
skip p
parses p
and skips the result.