Module

Text.Syntax.Combinators

Package
purescript-invertible-syntax
Repository
paulyoung/purescript-invertible-syntax

Derived combinators

#text Source

text :: forall d. Syntax d => String -> d Unit

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

#comma Source

comma :: forall d. Syntax d => d Unit

#dot Source

dot :: forall d. Syntax d => d Unit

#many Source

many :: forall a d. Syntax d => d a -> d (List a)

#many1 Source

many1 :: forall a d. Syntax d => d a -> d (List a)

#sepBy Source

sepBy :: forall a d. Syntax d => d a -> d Unit -> d (List a)

#chainl1 Source

chainl1 :: forall b a d. Syntax d => d a -> d b -> Iso (Tuple a (Tuple b a)) a -> d a

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

#applySecond Source

applySecond :: forall a d. Syntax d => d Unit -> d a -> d a

This variant of <*> ignores its left result. In contrast to its counterpart derived from the Apply class, the ignored parts have type d Unit rather than d b because otherwise information relevant for pretty-printing would be lost.

#(*>) Source

Operator alias for Text.Syntax.Combinators.applySecond (left-associative / precedence 9)

#applyFirst Source

applyFirst :: forall a d. Syntax d => d a -> d Unit -> d a

This variant of <*> ignores its right result. In contrast to its counterpart derived from the Apply class, the ignored parts have type d Unit rather than d b because otherwise information relevant for pretty-printing would be lost.

#(<*) Source

Operator alias for Text.Syntax.Combinators.applyFirst (left-associative / precedence 9)

#between Source

between :: forall a d. Syntax d => d Unit -> d Unit -> d a -> d a

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

#alt Source

alt :: forall b a d. Syntax d => d a -> d b -> d (Either a b)

#(<+>) Source

Operator alias for Text.Syntax.Combinators.alt (left-associative / precedence 4)

#skipSpace Source

skipSpace :: forall d. Syntax d => d Unit

Expressing whitespace

Parsers and pretty printers treat whitespace differently. Parsers specify where whitespace is allowed or required to occur, while pretty printers specify how much whitespace is to be inserted at these locations. To account for these different roles of whitespace, the following three syntax descriptions provide fine-grained control over where whitespace is allowed, desired or required to occur. skipSpace marks a position where whitespace is allowed to occur. It accepts arbitrary space while parsing, and produces no space while printing.

#optSpace Source

optSpace :: forall d. Syntax d => d Unit

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

#sepSpace Source

sepSpace :: forall d. Syntax d => d Unit

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.