-- Hoogle documentation, generated by Haddock -- See Hoogle, http://www.haskell.org/hoogle/ -- | A lightweight markup language for story writers -- -- ogmarkup is a lightweight markup language for story writers. -- ogmarkup also refers to a haskell library that provides a -- generic conversion function to transform an ogmarkup document into a -- ready-to-publish document. @package ogmarkup @version 4.0 -- | An abstract representation of an ogmarkup document. module Text.Ogmarkup.Private.Ast -- | A ogmarkup document internal representation waiting to be used in -- order to generate an output. type Document a = [Section a] -- | A Section within an ogmarkup document is a sequence of paragraphs. It -- can be part of the story or an aside section like a letter, a song, -- etc. We make the distinction between the two cases because we want to -- be able to apply different style depending on the situation. data Section a -- | The story as it goes Story :: [Paragraph a] -> Section a -- | Something else. Maybe a letter, a flashback, etc. Aside :: (Maybe a) -> [Paragraph a] -> Section a Failing :: a -> Section a -- | A Paragraph is just a sequence of Component. type Paragraph a = [Component a] -- | A Component is either a narrative text, a character's line of dialogue -- or a character's inner thought. -- -- We also embed an error Component in case we fail to parse a valid -- component. This way, we can resume parsing when we meet a new -- paragraph. data Component a -- | A narrative description Teller :: [Format a] -> Component a -- | A dialogue reply Dialogue :: (Reply a) -> (Maybe a) -> Component a -- | Inner dialogue of the character Thought :: (Reply a) -> (Maybe a) -> Component a -- | If none of the above matched, then output what follows as-is, the -- parsing will be resumed at the next paragraph IllFormed :: a -> Component a -- | A character's line of dialogue. A reply may contain a descriptive -- part, which is not part of what the character actually says or thinks. -- We call the latter a "with say" reply untill someone gives use a -- better name for it. data Reply a -- | A reply of the form: "Good morning." Simple :: [Format a] -> Reply a -- | A reply of the form: "Good morning," she says. "How are you?" WithSay :: [Format a] -> [Format a] -> [Format a] -> Reply a -- | A nested formatted text data Format a -- | No particular emphasis is required on this sequence Raw :: [Atom a] -> Format a -- | Surrounded by *. Emph :: [Format a] -> Format a -- | Surrounded by **. StrongEmph :: [Format a] -> Format a Quote :: [Format a] -> Format a -- | An Atom is the atomic component of a Ogmarkup document. It can be -- either a punctuation mark or a word, that is a string. -- -- Note that, by construction, OpenQuote and CloseQuote are -- not valid Mark values here. Indeed, they are implicit with the -- Quote constructor. This design allows the parser to enforce -- that an opened quote needs to be closed. data Atom a -- | A wrapped string Word :: a -> Atom a -- | A punctuation mark Punctuation :: Mark -> Atom a -- | Mostly in order to deal with typographic spaces, main punctuation -- marks are tokenized during the parsing of an Ogmarkup document. data Mark -- | The character ; Semicolon :: Mark -- | The character , Colon :: Mark -- | The character ? Question :: Mark -- | The character ! Exclamation :: Mark -- | The character " OpenQuote :: Mark -- | The character " CloseQuote :: Mark -- | The character – or the sequence -- Dash :: Mark -- | The character — or the sequence --- LongDash :: Mark -- | The character , Comma :: Mark -- | The character . Point :: Mark -- | The character - Hyphen :: Mark -- | Two or more . or the character … SuspensionPoints :: Mark -- | The characters ' or ’ Apostrophe :: Mark instance GHC.Show.Show a => GHC.Show.Show (Text.Ogmarkup.Private.Ast.Section a) instance GHC.Classes.Eq a => GHC.Classes.Eq (Text.Ogmarkup.Private.Ast.Section a) instance GHC.Show.Show a => GHC.Show.Show (Text.Ogmarkup.Private.Ast.Component a) instance GHC.Classes.Eq a => GHC.Classes.Eq (Text.Ogmarkup.Private.Ast.Component a) instance GHC.Show.Show a => GHC.Show.Show (Text.Ogmarkup.Private.Ast.Reply a) instance GHC.Classes.Eq a => GHC.Classes.Eq (Text.Ogmarkup.Private.Ast.Reply a) instance GHC.Classes.Eq a => GHC.Classes.Eq (Text.Ogmarkup.Private.Ast.Format a) instance GHC.Show.Show a => GHC.Show.Show (Text.Ogmarkup.Private.Ast.Format a) instance GHC.Classes.Eq a => GHC.Classes.Eq (Text.Ogmarkup.Private.Ast.Atom a) instance GHC.Show.Show a => GHC.Show.Show (Text.Ogmarkup.Private.Ast.Atom a) instance GHC.Classes.Eq Text.Ogmarkup.Private.Ast.Mark instance GHC.Show.Show Text.Ogmarkup.Private.Ast.Mark -- | 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. module Text.Ogmarkup.Private.Parser -- | Keep track of the currently opened formats. data ParserState ParserState :: Bool -> Bool -> Bool -> ParserState -- | Already parsing text with emphasis [parseWithEmph] :: ParserState -> Bool -- | Already parsing text with strong emphasis [parseWithStrongEmph] :: ParserState -> Bool -- | Already parsing a quote [parseWithinQuote] :: ParserState -> Bool -- | An ogmarkup parser processes Char tokens and carries a -- ParserState. type OgmarkupParser a = StateT ParserState (Parsec Void a) -- | Update the ParserState to guard against nested emphasis. enterEmph :: Stream a => OgmarkupParser a () -- | Update the ParserState to be able to parse input with emphasis -- again. leaveEmph :: Stream a => OgmarkupParser a () -- | Update the ParserState to guard against nested strong emphasis. enterStrongEmph :: Stream a => OgmarkupParser a () -- | Update the ParserState to be able to parse input with strong -- emphasis again. leaveStrongEmph :: Stream a => OgmarkupParser a () -- | Update the ParserState to guard against nested quoted inputs. enterQuote :: Stream a => OgmarkupParser a () -- | Update the ParserState to be able to parse an input surrounded -- by quotes again. leaveQuote :: Stream a => OgmarkupParser a () -- | A initial ParserState instance to be used at the begining of a -- document parsing. initParserState :: ParserState -- | A wrapper around the runParser function of Megaparsec. It uses -- initParserState as an initial state. parse :: Stream a => OgmarkupParser a b -> String -> a -> Either (ParseError (Token a) Void) b -- | Try its best to parse an ogmarkup document. When it encounters an -- error, it returns an Ast and the remaining input. -- -- See Document. document :: (Stream a, Token a ~ Char, IsString (Tokens a), IsString b) => OgmarkupParser a (Document b) -- | See Section. section :: (Stream a, Token a ~ Char, IsString b) => OgmarkupParser a (Section b) -- | See Aside. aside :: (Stream a, Token a ~ Char, IsString b) => OgmarkupParser a (Section b) -- | See Story. story :: (Stream a, Token a ~ Char, IsString b) => OgmarkupParser a (Section b) -- | See Paragraph. paragraph :: (Stream a, Token a ~ Char, IsString b) => OgmarkupParser a (Paragraph b) -- | See Component. component :: (Stream a, Token a ~ Char, IsString b) => OgmarkupParser a (Component b) -- | See IllFormed. illformed :: (Stream a, Token a ~ Char, IsString b) => OgmarkupParser a (Component b) -- | 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. restOfParagraph :: (Stream a, Token a ~ Char, IsString b) => OgmarkupParser a b -- | See Teller. teller :: (Stream a, Token a ~ Char, IsString b) => OgmarkupParser a (Component b) -- | See Dialogue. dialogue :: (Stream a, Token a ~ Char, IsString b) => OgmarkupParser a (Component b) -- | See Thought. thought :: (Stream a, Token a ~ Char, IsString b) => OgmarkupParser a (Component b) -- | talk c c' constr wraps a reply surrounded by -- c and c' inside constr (either -- Dialogue or Thought). talk :: (Stream a, Token a ~ Char, IsString b) => Char -> Char -> (Reply b -> Maybe b -> Component b) -> OgmarkupParser a (Component b) -- | Parse the name of the character which speaks or thinks. According to -- the ogmarkup syntax, it is surrounded by parentheses. characterName :: (Stream a, Token a ~ Char, IsString b) => OgmarkupParser a b -- | reply parses a Reply. reply :: (Stream a, Token a ~ Char, IsString b) => Char -> Char -> OgmarkupParser a (Reply b) -- | See Format. format :: (Stream a, Token a ~ Char, IsString b) => OgmarkupParser a (Format b) -- | See Raw. raw :: (Stream a, Token a ~ Char, IsString b) => OgmarkupParser a (Format b) -- | See Emph. emph :: (Stream a, Token a ~ Char, IsString b) => OgmarkupParser a (Format b) -- | See StrongEmph. strongEmph :: (Stream a, Token a ~ Char, IsString b) => OgmarkupParser a (Format b) -- | See Quote. quote :: (Stream a, Token a ~ Char, IsString b) => OgmarkupParser a (Format b) -- | See Atom. atom :: (Stream a, Token a ~ Char, IsString b) => OgmarkupParser a (Atom b) -- | See Word. This parser does not consume the following spaces, so -- the caller needs to take care of it. word :: (Stream a, Token a ~ Char, IsString b) => OgmarkupParser a (Atom b) -- | 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. longword :: (Stream a, Token a ~ Char, IsString b) => OgmarkupParser a (Atom b) -- | See Punctuation. Be aware that mark does not parse the -- quotes because they are processed quote. mark :: (Stream a, Token a ~ Char) => OgmarkupParser a (Atom b) -- | See OpenQuote. This parser consumes the following blank (see -- blank) and skip the result. openQuote :: (Stream a, Token a ~ Char) => OgmarkupParser a () -- | See CloseQuote. This parser consumes the following blank (see -- blank) and skip the result. closeQuote :: (Stream a, Token a ~ Char) => OgmarkupParser a () -- | An aside section (see Aside) is a particular region surrounded -- by two lines of underscores (at least three). This parser consumes one -- such line. asideSeparator :: (Stream a, Token a ~ Char) => OgmarkupParser a () -- | 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. endOfParagraph :: (Stream a, Token a ~ Char) => OgmarkupParser a () -- | 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. blank :: (Stream a, Token a ~ Char) => OgmarkupParser a () -- | skip p parses p and skips the result. skip :: (Stream a) => OgmarkupParser a b -> OgmarkupParser a () -- | This module provides the Typography datatype along with two -- default instances for French and English. module Text.Ogmarkup.Private.Typography -- | Deal with typographic spaces, especially when it comes to separating -- two texts. Because Space derives Ord, it is possible to use min and -- max to determine which one to use in case of a conflict. data Space -- | A normal space that can be turned into a newline for displaying. Normal :: Space -- | A non breakable space, it cannot be turned into a newline. Nbsp :: Space -- | No space at all. None :: Space -- | A Typography is a data type that tells the caller what space should be -- privileged before and after a text. data Typography a Typography :: (Mark -> (Space, Space, a)) -> (Bool -> Maybe Mark) -> (Bool -> Maybe Mark) -> Typography a -- | For a given Mark, returns a tuple with the spaces to use before -- and after the punctuation mark and its output value. [decide] :: Typography a -> Mark -> (Space, Space, a) -- | Which mark to use to open a dialogue. If the parameter is True, there -- were another dialogue just before. [openDialogue] :: Typography a -> Bool -> Maybe Mark -- | Which mark to use to close a dialogue. If the parameter is True, there -- is another dialogue just after. [closeDialogue] :: Typography a -> Bool -> Maybe Mark -- | Apply the function to each Mark output value -- | From a Typography, it gives the space to privilege before the input -- Text. beforeAtom :: Typography a -> Atom a -> Space -- | From a Typography, it gives the space to privilege after the input -- Text. afterAtom :: Typography a -> Atom a -> Space -- | Normalize the input in order to add it to a generated Text. normalizeAtom :: Typography a -> Atom a -> a -- | A proposal for the French typography. It can be used with several -- generation approaches, as it remains very generic. Requires the output -- type to be an instance of IsString. frenchTypo :: IsString a => Typography a -- | A proposal for the English typography. It can be used with several -- generation approaches, as it remains very generic. Requires the output -- type to be an instance of IsString. englishTypo :: IsString a => Typography a instance GHC.Classes.Ord Text.Ogmarkup.Private.Typography.Space instance GHC.Classes.Eq Text.Ogmarkup.Private.Typography.Space instance GHC.Base.Functor Text.Ogmarkup.Private.Typography.Typography -- | This module provides the GenConf typeclass which is used to -- configure the Generators monad. module Text.Ogmarkup.Private.Config -- | A Template is just synonym for a template of one argument. type Template a = a -> a -- | An instance of the GenConf typeclass can be given as a -- parameter to a Generator. In order to prevent GHC to -- overabstract this typeclass, there can be only one instance of GenConf -- for one datatype. In other words, one datatype can only handle one -- return type c. -- -- For each template, we give a prefered layout and some hints about the -- default implementation (which is almost always the identity function, -- ignoring all the parameters but the generated output. -- -- Warning: GenConf is a multiparam typeclass (see -- MultiParamTypeClasses GHC extension). In order to make new -- instances, the following extensions need to be enabled: -- --
FlexibleInstances
MultiParamTypeClasses
FlexibleInstances
MultiParamTypeClasses