Module

Text.Parsing.Indent

This is purescript-port of Text.Parsing.Indent https://hackage.haskell.org/package/indents-0.3.3/docs/Text-Parsec-Indent.html, 05.07.2016. A module to construct indentation aware parsers. Many programming language have indentation based syntax rules e.g. python and Haskell. This module exports combinators to create such parsers.

The input source can be thought of as a list of tokens. Abstractly each token occurs at a line and a column and has a width. The column number of a token measures is indentation. If t1 and t2 are two tokens then we say that indentation of t1 is more than t2 if the column number of occurrence of t1 is greater than that of t2.

Currently this module supports two kind of indentation based syntactic structures which we now describe:

  • Block

    A block of indentation /c/ is a sequence of tokens with indentation at least /c/. Examples for a block is a where clause of Haskell with no explicit braces.

  • Line fold

    A line fold starting at line /l/ and indentation /c/ is a sequence of tokens that start at line /l/ and possibly continue to subsequent lines as long as the indentation is greater than /c/. Such a sequence of lines need to be /folded/ to a single line. An example is MIME headers. Line folding based binding separation is used in Haskell as well.

#IndentParser

type IndentParser s a = ParserT s (State Position) a

Indentation sensitive parser type. Usually @ m @ will be @ Identity @ as with any @ ParserT @

#runIndent

runIndent :: forall a. State Position a -> a

Run the result of an indentation sensitive parse

#withBlock

withBlock :: forall a b c s. (a -> List b -> c) -> IndentParser s a -> IndentParser s b -> IndentParser s c

withBlock f a p parses a followed by an indented block of p combining them with f.

#withBlock'

withBlock' :: forall a b s. IndentParser s a -> IndentParser s b -> IndentParser s (List b)

Like 'withBlock', but throws away initial parse result

#block

block :: forall s a. IndentParser s a -> IndentParser s (List a)

Parses a block of lines at the same indentation level , empty Blocks allowed

#block1

block1 :: forall s a. IndentParser s a -> IndentParser s (List a)

Parses a block of lines at the same indentation level

#indented

indented :: forall s. IndentParser s Unit

Parses only when indented past the level of the reference

#indented'

indented' :: forall s. IndentParser s Unit

Same as indented, but does not change internal state

#sameLine

sameLine :: forall s. IndentParser s Unit

Parses only on the same line as the reference

#sameOrIndented

sameOrIndented :: forall s. IndentParser s Unit

Parses only when indented past the level of the reference or on the same line

#checkIndent

checkIndent :: forall s. IndentParser s Unit

Ensures the current indentation level matches that of the reference

#withPos

withPos :: forall s a. IndentParser s a -> IndentParser s a

Parses using the current location for indentation reference

#indentAp

indentAp :: forall s a b. IndentParser s (a -> b) -> IndentParser s a -> IndentParser s b

<+/> is to indentation sensitive parsers what ap is to monads

#(<+/>)

Operator alias for Text.Parsing.Indent.indentAp (left-associative / precedence 9)

#indentNoAp

indentNoAp :: forall s a b. IndentParser s a -> IndentParser s b -> IndentParser s a

Like <+/> but doesn't apply the function to the parsed value

#(<-/>)

Operator alias for Text.Parsing.Indent.indentNoAp (left-associative / precedence 10)

#indentMany

indentMany :: forall s a b. IndentParser s (List a -> b) -> IndentParser s a -> IndentParser s b

Like <+/> but applies the second parser many times

#(<*/>)

Operator alias for Text.Parsing.Indent.indentMany (left-associative / precedence 11)

#indentOp

indentOp :: forall s a b. IndentParser s (a -> b) -> Optional s a -> IndentParser s b

Like <+/> but applies the second parser optionally using the Optional datatype

#(<?/>)

Operator alias for Text.Parsing.Indent.indentOp (left-associative / precedence 12)

#indentBrackets

indentBrackets :: forall a. IndentParser String a -> IndentParser String a

Parses with surrounding brackets

#indentAngles

indentAngles :: forall a. IndentParser String a -> IndentParser String a

Parses with surrounding angle brackets

#indentBraces

indentBraces :: forall a. IndentParser String a -> IndentParser String a

Parses with surrounding braces

#indentParens

indentParens :: forall a. IndentParser String a -> IndentParser String a

Parses with surrounding parentheses

#Optional

data Optional s a

Data type used to optional parsing

Constructors

Modules