invertible-syntax-0.2: Invertible syntax descriptions for both parsing and pretty printing.

Text.Syntax.Combinators

Contents

Synopsis

Lexemes

text :: Syntax delta => String -> delta ()Source

text parses/prints a fixed text and consumes/produces a unit value.

comma :: Syntax delta => delta ()Source

dot :: Syntax delta => delta ()Source

Repetition

many :: Syntax delta => delta alpha -> delta [alpha]Source

many1 :: Syntax delta => delta alpha -> delta [alpha]Source

sepBy :: Syntax delta => delta alpha -> delta () -> delta [alpha]Source

chainl1 :: Syntax delta => delta alpha -> delta beta -> Iso (alpha, (beta, alpha)) alpha -> delta alphaSource

The chainl1 combinator is used to parse a left-associative chain of infix operators.

Sequencing

(*>) :: Syntax delta => delta () -> delta alpha -> delta alphaSource

This variant of <*> ignores its left result. In contrast to its counterpart derived from the Applicative class, the ignored parts have type `delta ()` rather than `delta beta` because otherwise information relevant for pretty-printing would be lost.

(<*) :: Syntax delta => delta alpha -> delta () -> delta alphaSource

This variant of <*> ignores its right result. In contrast to its counterpart derived from the Applicative class, the ignored parts have type `delta ()` rather than `delta beta` because otherwise information relevant for pretty-printing would be lost.

between :: Syntax delta => delta () -> delta () -> delta alpha -> delta alphaSource

The between function combines *> and <* in the obvious way.

Alternation

(<+>) :: Syntax delta => delta alpha -> delta beta -> delta (Either alpha beta)Source

optional :: Syntax delta => delta alpha -> delta (Maybe alpha)Source

Whitespace

skipSpace :: Syntax delta => delta ()Source

skipSpace marks a position where whitespace is allowed to occur. It accepts arbitrary space while parsing, and produces no space while printing.

sepSpace :: Syntax delta => delta ()Source

sepSpace marks a position where whitespace is required to occur. It requires one or more space characters while parsing, and produces a single space character while printing.

optSpace :: Syntax delta => delta ()Source

optSpace marks a position where whitespace is desired to occur. It accepts arbitrary space while parsing, and produces a single space character while printing.