backend-0.1.0.0
Safe HaskellSafe-Inferred
LanguageHaskell2010

Language.Ltml.Parser.MiTree

Description

Parsing Mixed Indentation Trees---trees that may both be represented by indentation, or by bracketing tokens, where the latter nodes may span multiple lines, while empty lines are disallowed.

Synopsis

Documentation

data MiElementConfig Source #

Configuration on how to handle an element (node in a mi-tree).

Constructors

MiElementConfig 

Fields

  • miecRetainPrecedingWhitespace :: Bool

    whether to retain (or else drop) whitespace between the preceding and this element (if any).

  • miecRetainTrailingWhitespace :: Bool

    Whether to retain (or else drop) whitespace between this and the subsequent element (if any). This does not apply if the subsequent element is a child (in which case whitespace is always dropped).

data InlineParser (m :: Type -> Type) a Source #

An in-line element parser (constructor). Involved parsers must not consume whitespace (ASCII spaces, newlines) and must not accept the empty input.

Constructors

LeafParser (m (MiElementConfig, [a])) 
BracketingParser (m ([a] -> (MiElementConfig, [a]))) (m ())

Bracketing parser, composed of two parsers, one for the opening bracket, one for the closing bracket. The closing bracket parser is only used if possible (via optional). The body parser is determined by context. Any whitespace both within and adjacent to the brackets is dropped.

miForest Source #

Arguments

:: (MonadParser m, FromWhitespace [a]) 
=> [Restricted (InlineParser m a)]

In-line element parsers. They are tried in the given order.

-> (Maybe Pos -> m a)

Block element parser.

The block parser is only attempted at the start of a line, and takes precedence over in-line parsers there.

Unlike the in-line parsers, the block parser must take care of indentation itself--except at the very beginning, where it may expect that any indentation has been consumed and the indentation is correct. The supplied indentation is the parent's, and indentation is acceptable iff strictly larger than that.

Further, the block parser must only succeed after a final newline (plus indentation).

Typically, a block parser is constructed via hangingBlock (optionally combined with someIndented and/or <|>), which satisfies these requirements.

-> m [a] 

Parse a list of mixed indentation trees (a forest), terminated by a newline (plus indentation).

At least one element is parsed.

This is expected to be run at the start of a non-empty line, after any indentation.

The initial (minimum) indentation is set to none.

hangingBlock Source #

Arguments

:: (MonadParser m, FromWhitespace [a]) 
=> m ([a] -> b)

Keyword parser. Result is applied to the parsed mi-forest. This is expected not to consume any whitespace.

-> [Restricted (InlineParser m a)] 
-> (Maybe Pos -> m a) 
-> m b 

Parse a mi-forest headed by a keyword, with all lines but the first indented further than the first.

Text may begin on the line of the keyword or on the next (indented) line.

The documentation on miForest generally applies.

hangingBlock' :: (MonadParser m, FromWhitespace [a]) => m b -> [Restricted (InlineParser m a)] -> (Maybe Pos -> m a) -> m (b, [a]) Source #

Version of hangingBlock where the keyword parser may yield any value, which is paired with the parsed mi-forest.

hangingBlock_ :: (MonadParser m, FromWhitespace [a]) => m () -> [Restricted (InlineParser m a)] -> (Maybe Pos -> m a) -> m [a] Source #

Version of hangingBlock where the keyword parser does not return a value.

pipeSeparated Source #

Arguments

:: (MonadParser m, FromWhitespace [a]) 
=> [Restricted (InlineParser m a)] 
-> (Maybe Pos -> m a)

Block parser. Documentation of miForest applies.

-> m [[a]] 

Parse a list of '|' seperated TextForests. At least one element will be parsed. The list can also be defined across multiple lines and contain empty lines. The initial (minimum) indentation is set to none.