# Parsing.Indent

- Package
- purescript-parsing
- Repository
- purescript-contrib/purescript-parsing

This module is a port of the Haskell
**Text.Parsec.Indent**
module from 2016-05-07.

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 Source

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

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

### #withBlock Source

`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' Source

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

Like 'withBlock', but throws away initial parse result

### #block Source

`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 Source

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

Parses a block of lines at the same indentation level

### #indented Source

`indented :: forall s. IndentParser s Unit`

Parses only when indented past the level of the reference

### #indented' Source

`indented' :: forall s. IndentParser s Unit`

Same as `indented`

, but does not change internal state

### #sameLine Source

`sameLine :: forall s. IndentParser s Unit`

Parses only on the same line as the reference

### #sameOrIndented Source

`sameOrIndented :: forall s. IndentParser s Unit`

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

### #checkIndent Source

`checkIndent :: forall s. IndentParser s Unit`

Ensures the current indentation level matches that of the reference

### #withPos Source

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

Parses using the current location for indentation reference

### #indentAp Source

`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

### #indentNoAp Source

`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

### #indentMany Source

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

Like `<+/>`

but applies the second parser many times

### #indentOp Source

`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

### #indentBrackets Source

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

Parses with surrounding brackets

### #indentAngles Source

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

Parses with surrounding angle brackets

### #indentBraces Source

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

Parses with surrounding braces

### #indentParens Source

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

Parses with surrounding parentheses